python 펀드 데이터 획득 펀드 30 일 이동 평균 선

1174 단어 python
import tushare as ts
import xlrd#    
import pandas as pd

ts.set_token('xxxxxxxxxxxxxx')
pro = ts.pro_api()
path="C://Users//fuxingyu//Desktop//  .xlsx"
path2="C://Users//fuxingyu//Desktop//    .xlsx"
df = pro.fund_nav(ts_code='001632.OF')
df.to_excel(path)
book=xlrd.open_workbook("C://Users//fuxingyu//Desktop//  .xlsx")
sheet=book.sheet_by_index(0)

row1_value=sheet.row_values(rowx=0)#     

bianhao=sheet.col_values(colx=0,start_rowx=1)#     
end_date=sheet.col_values(colx=3,start_rowx=1)#     
unit_nav=sheet.col_values(colx=4,start_rowx=1)#    
end_date.reverse()#  
unit_nav.reverse()
data = pd.DataFrame(unit_nav,index=end_date,columns=['test'])
#data['mean30'] = data.test.rolling(30).mean()
data['0.97mean30'] = (data.test.rolling(30).mean())*0.97#30        0.97

data.to_excel(path2)
data.plot()#30        
#plt.show()

book2=xlrd.open_workbook("C://Users//fuxingyu//Desktop//    .xlsx")
sheet2=book2.sheet_by_index(0)
a=len(sheet2.col_values(colx=0,start_rowx=0))#a  excel   
f=sheet2.col_values(colx=2,start_rowx=a-1)[0]# 2 ,    ,    
print('%.4f' % f)

좋은 웹페이지 즐겨찾기