其他分享
首页 > 其他分享> > 获取近期几日收益情况

获取近期几日收益情况

作者:互联网

点击查看代码
# import pandas as pd
# df = pd.read_csv('320007.csv')
# print(df)


import csv

# with open('320007.csv', encoding='utf-8-sig') as f:
#     for row in csv.reader(f, skipinitialspace=True):
#         print(row)
#

# 取出指定行数
new_list=[]
# 取出最近多少日的数据
num_days = 100
# 初始金额
money = 1000
# 获取近段时间数据存放到new_list
def getBase():
    with open('320007.csv', encoding='utf-8-sig') as f:
        reader = csv.reader(f)
        print("近{}日数据".format(num_days))
        for i,rows in enumerate(reader):
            if i<num_days  and  i>0:
                row = rows
                # print("日期:%s,单位净值:%s,累计净值:%s,日涨幅:%s" %(row[1],row[2],row[3],row[7]))
                new_dict ={"日期": row[1],"单位净值": row[2], "累计净值": row[3], "日涨幅":row[7]}
                # money_diff = money * (float(new_dict["日涨幅"]) / 100)
                # money = money + money_diff
                # print(money)
                new_list.append(new_dict)
    return new_list
# print(getBase())
getBase()
for new_dict in new_list:
    a_new_dict = new_dict["日涨幅"]
    # print(a_new_dict)
    money_diff = money * (float(a_new_dict) / 100)
    money = money + money_diff
print(money)
# 以上可以计算出近几日数据的收益是多少



点击查看代码
,FSRQ,DWJZ,LJJZ,SDATE,ACTUALSYI,NAVTYPE,JZZZL,SGZT,SHZT,FHFCZ,FHFCBZ,DTYPE,FHSP
0,2022-07-26,1.4870,1.9320,,,1,0.00,开放申购,开放赎回,,,,
1,2022-07-25,1.4870,1.9320,,,1,-1.20,开放申购,开放赎回,,,,
2,2022-07-22,1.5050,1.9500,,,1,-0.73,开放申购,开放赎回,,,,
3,2022-07-21,1.5160,1.9610,,,1,2.57,开放申购,开放赎回,,,,
4,2022-07-20,1.4780,1.9230,,,1,0.61,开放申购,开放赎回,,,,
5,2022-07-19,1.4690,1.9140,,,1,-0.68,开放申购,开放赎回,,,,
6,2022-07-18,1.4790,1.9240,,,1,-0.60,开放申购,开放赎回,,,,
7,2022-07-15,1.4880,1.9330,,,1,0.07,开放申购,开放赎回,,,,
8,2022-07-14,1.4870,1.9320,,,1,0.34,开放申购,开放赎回,,,,
9,2022-07-13,1.4820,1.9270,,,1,-1.59,开放申购,开放赎回,,,,
10,2022-07-12,1.5060,1.9510,,,1,-3.46,开放申购,开放赎回,,,,
11,2022-07-11,1.5600,2.0050,,,1,-2.62,开放申购,开放赎回,,,,
12,2022-07-08,1.6020,2.0470,,,1,0.63,开放申购,开放赎回,,,,
13,2022-07-07,1.5920,2.0370,,,1,-0.62,开放申购,开放赎回,,,,
14,2022-07-06,1.6020,2.0470,,,1,2.43,开放申购,开放赎回,,,,

标签:07,几日,money,收益,获取,2022,new,开放,row
来源: https://www.cnblogs.com/LuoYao666/p/16523124.html