数据来源
- 易方达基金官网,选择基金即可下载历史净值
官网地址:https://www.efunds.com.cn/index.shtml
数据分析代码
- 本次仅以一只基金分析,结果不一定具有代表性
import pandas as pd
import time
import datetime
def invest_regularly(start_time,money=100,invest_frequency='week',fund_code=110022):
assert invest_frequency in ['week','month'],'invest_frequency error'
data = pd.read_excel(r'110022.xlsx')
data['净值日期']=pd.to_datetime(data['净值日期'])
# data.index=data['净值日期']
start_time = pd.to_datetime(start_time)
# 获取初始交易时间
start_index=0
for index,item in enumerate(data['净值日期']):
if start_time<=item.date():
start_index=index
break
inve_freq={'week':7,'month':30}
# 定投时刻的净值序列
value_list = data['单位净值(元)'][start_index::inve_freq[invest_frequency]]
# 总投入金额
total_invest_money = money*len(value_list)
# 总拥有的份额 假设申购费率为 1%
current_shares = sum((money*(1-0.01))/value_list)
# 当前份额所拥有的价值
current_value = list(data['单位净值(元)'])[-1]*current_shares
# 收益率
gain_rate = (current_value-total_invest_money)/total_invest_money
return gain_rate,total_invest_money
week_rate = []
for item in range(2010,2023):
gain_rate,_ = invest_regularly('%d-1-1'%item,10)
week_rate.append(gain_rate)
month_rate = []
for item in range(2010,2023):
gain_rate,_ = invest_regularly('%d-1-1'%item,10,'month')
month_rate.append(gain_rate)
rate = pd.DataFrame()
rate['week']=week_rate
rate['month']=month_rate
rate['month-week']=rate['month']-rate['week']
rate.index=range(2010,2023)
rate['month-week'].plot(title='month-week')
rate['week'].plot(title='week gain rate')
rate['month'].plot(title='month gain rate')
结果分析
上图为该基金单位净值的变化曲线
- 以下各图形为
- x轴为定投起始年分,定投起始日期均为1月1日
下图为周定投收益率变化
下图为月定投收益率变化
下图为月定投收益率与周定投收益率差值
结论
如果单从最后图中分析,大部分情况来说
- 月定投的收益率要比周定投的收益率高,分析主要原因是由于频繁交易导致的手续费增加。
- 从基金开始发售就持有,且长时间持有,可以获得不错的收益率。
- 当大盘不好时,定投也不一定能保持正的收益。