请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  数理科学 帖子:3364680 新帖:1

定投指数基金 VS 定投指数增强基金

美联储主席发表于:5 月 9 日 17:15回复(1)

rt

from jqdata import finance
q_index= query(finance.FUND_NET_VALUE).filter(finance.FUND_NET_VALUE.code=="510300").order_by(finance.FUND_NET_VALUE.day.desc()).limit(3000)
df_index = finance.run_query(q_index)
q=query(finance.FUND_NET_VALUE).filter(finance.FUND_NET_VALUE.code=="163407").order_by(finance.FUND_NET_VALUE.day.desc()).limit(len(df_index))
df_enhanced=finance.run_query(q)

df_merge = df_index[['day','sum_value']]
df_merge.columns = ['date','index_fund']
df_merge['enhanced_fund'] = df_enhanced['sum_value']
/opt/conda/lib/python3.6/site-packages/ipykernel_launcher.py:9: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  if __name__ == '__main__':
df_merge = df_merge.sort_values(by='date')
df_merge = df_merge.set_index('date')
#份额
num_index = 0
num_enhanced = 0
#总收益
tp_index = []
tp_enhanced = []
#费率
ex_index = 0.0015
#定投次数h和金额
m=0
mon = 100

for i in range(len(df_merge)):
    if i == 0:
        m+=1
        num_index += (1-ex_index)*100/df_merge['index_fund'].values[i]
        num_enhanced += (1-ex_index)*100/df_merge['enhanced_fund'].values[i]
        tp_index.append(num_index*df_merge['index_fund'].values[i]-m*mon)
        tp_enhanced.append(num_enhanced*df_merge['enhanced_fund'].values[i]-m*mon)
        continue
    elif df_merge.index[i].month != df_merge.index[i-1].month:
        m+=1
        num_index += (1-ex_index)*100/df_merge['index_fund'].values[i]
        num_enhanced += (1-ex_index)*100/df_merge['enhanced_fund'].values[i]
        tp_index.append(num_index*df_merge['index_fund'].values[i]-m*mon)
        tp_enhanced.append(num_enhanced*df_merge['enhanced_fund'].values[i]-m*mon)
        continue
    else :
        tp_index.append(num_index*df_merge['index_fund'].values[i]-m*mon)
        tp_enhanced.append(num_enhanced*df_merge['enhanced_fund'].values[i]-m*mon)
df_merge['tp_index'] = tp_index
df_merge['tp_enhanced'] = tp_enhanced
df_merge.columns =['index_fund','enhanced_fund',u'定投沪深300ETF累计损益',u'定投沪深300指数增强累计损益']
df_merge['损益差'] = df_merge['定投沪深300指数增强累计损益']-df_merge['定投沪深300ETF累计损益']
df_merge[['定投沪深300ETF累计损益','定投沪深300指数增强累计损益','损益差']].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7f759747a828>
 

全部回复

0/140

量化课程

    移动端课程