交易用户如何去理解python股票接口策略?
1- 读仓位信息:
(1)先简单存到dic中,时间是倒序,在构造time_list中reverse即可
(2) str,int转换 int(''.join(str1.split('-'))
2- 读取收盘价:
取出来后的数据转格式:
df_close_f = df_close.pivot(index='时间',columns='股票代码',values='CLOSE')
取tb_object_1425 赋权收盘价,代码略
3- 计算股票端收益率:
(1) df.pct_change(1)计算股票个券收益率
(2) 用np.dot(df_r,df_pos) 矩阵计算,得到股票端收益率
(3) 用矩阵计算要实现对齐数据s_index = df_pos['股票代码'] \ df_r = df_r.loc[:,s_index]
或用自定义函数ircp.ORDER_LIST(): df = df.set_index(target_columns) \ df = df.loc[s_index,:] \ df = df.reset_index()
4- 运行策略:
(1)逐渐建仓 仓位 np.linspace(0,0.8,len(xxx)
(2)非满仓下认为投货币基金
(3)series 是对应位置加减,dataframe与series运算.add, .sub , .div 再复杂的运算可转为array,进行换算, 注意换算后是否要转置
5- 策略评判:
(1)最大回撤
(2)真实收益
(3)基准
(4)胜率
(5)平均年化收益率