python 计算当月天数_如何用Python算出股票是上涨天数多还是下跌天数多?

话不多说先上代码:

#请使用前复权的日K线数据import os#上涨天数upCount = 0#下跌天数downCount = 0#打开日志文件fs = open(r'C:\Py\result.txt','a+')#循环遍历所有的日K线文件for root, dirs, files in os.walk(r'C:\Py\day'):  for file in files:    #写日志    print('正在计算' + file)    #打开日K线文件    fs2 = open(os.path.join(root,file), 'r', True)    #昨日收盘价    lastClose = 0    #索引    pos = 0    #循环遍历每一行    while True:      #读取该行      line = fs2.readline()      #没有行的时候退出      if not line: break      #去除前2行和尾行      if pos > 1 and len(line) > 20:        #分割字符串        strs = line.split(',')        #收盘价        closePrice = float(strs[4])        #开盘价        openPrice = float(strs[1])        if pos == 2:          lastClose = openPrice        if closePrice > lastClose:          upCount = upCount 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值