收益翻倍!PTrade智能定投策略从普通到进阶

发布时间:2026-06-06 12:37:32 来源: 财金股小编

“通达信选股/做T/主力检测器”炒股指标(付费版免费送,附教程和学习视频)


基金定投是普通投资者最适合的投资方式之一,它通过定期定额投资,摊薄成本,分散风险,长期坚持可以获得不错的收益。


但普通的定期定额定投有一个很大的缺点:市场跌的时候投的少,市场涨的时候投的多,反而拉高了平均成本。


进阶的定投策略可以解决这个问题,它会根据市场的估值水平自动调整定投金额:市场估值低的时候多投,市场估值高的时候少投,甚至卖出,从而进一步提高收益。


PTrade 提供了强大的定时任务和数据接口,让你可以轻松实现各种进阶的定投策略。


今天我就给大家讲清楚,如何用 PTrade 实现价值平均定投和动态估值定投这两种最有效的进阶定投策略。


普通定投的缺点

普通定投是每月固定时间投固定金额,比如每月 15 日投 1000 元。这种方式虽然简单,但在市场波动较大的时候,效果并不理想。

比如,当市场下跌时,基金净值变低,同样的 1000 元可以买到更多的份额;当市场上涨时,基金净值变高,同样的 1000 元只能买到更少的份额。但普通定投不管市场涨跌,都投固定的金额,导致在市场低位时买的不够多,在市场高位时买的太多,平均成本被拉高。


进阶定投策略 1:价值平均定投

价值平均定投(Value Averaging,简称 VA)是由美国学者迈克尔・埃德尔森提出的一种定投策略,它的核心逻辑是:让你的投资组合的市值每月固定增长一定的金额。

比如,你设定每月投资组合的市值增长 1000 元:


第一个月:投入 1000 元,市值 1000 元。第二个月:如果基金净值下跌,市值只有 900 元,那么你需要投入 1100 元,让市值达到 2000 元。第三个月:如果基金净值上涨,市值达到 2300 元,那么你只需要投入 700 元,让市值达到 3000 元。如果市值超过了目标市值,你甚至可以卖出一部分,锁定收益。


价值平均定投的优点是:在市场下跌时自动多投,在市场上涨时自动少投甚至卖出,从而进一步摊薄成本,提高收益。


实战:用 PTrade 实现价值平均定投

以下是一个完整的价值平均定投策略代码:

python

运行


# -*- coding: gbk -*- """ 价值平均定投策略 """ def init(context): # 定投标的:沪深300ETF context.target_fund = "510300.SH" # 每月目标市值增长额(元) context.monthly_target_growth = 1000 # 定投日:每月15日 context.investment_day = 15 # 记录当前的目标市值 context.target_value = 0 # 记录定投次数 context.investment_count = 0 def handlebar(context): # 获取当前日期 current_date = context.get_current_date() current_day = int(current_date.split("-")[2]) # 判断是否是定投日 if current_day == context.investment_day: value_averaging_investment(context) def value_averaging_investment(context): """价值平均定投""" context.investment_count += 1 # 计算当前的目标市值 context.target_value = context.monthly_target_growth * context.investment_count print(f"第{context.investment_count}次定投,目标市值:{context.target_value:.2f}元") # 获取当前持仓的市值 position = context.get_position(context.target_fund) current_value = position.quantity * position.last_price print(f"当前持仓市值:{current_value:.2f}元") # 计算需要投入的金额 investment_amount = context.target_value - current_value print(f"需要投入的金额:{investment_amount:.2f}元") if investment_amount > 0: # 买入 price = context.get_last_price(context.target_fund) quantity = int(investment_amount / price / 100) * 100 if quantity > 0: context.order(context.target_fund, quantity, price) print(f"买入:{context.target_fund},价格:{price:.2f},数量:{quantity},金额:{quantity*price:.2f}元") elif investment_amount < 0: # 卖出 sell_amount = -investment_amount price = context.get_last_price(context.target_fund) quantity = int(sell_amount / price / 100) * 100 if quantity > 0 and quantity <= position.quantity: context.order(context.target_fund, -quantity, price) print(f"卖出:{context.target_fund},价格:{price:.2f},数量:{quantity},金额:{quantity*price:.2f}元") else: print("无需操作") print("定投完成") 进阶定投策略 2:动态估值定投

动态估值定投是在价值平均定投的基础上,加入了市场估值的因素。它会根据市场的估值水平,调整目标市值的增长额:


当市场估值低于历史 20% 分位时,目标市值增长额加倍。当市场估值在历史 20%-80% 分位时,目标市值增长额保持不变。当市场估值高于历史 80% 分位时,停止定投,甚至分批卖出。


动态估值定投结合了价值平均定投和估值定投的优点,既能摊薄成本,又能避免在市场高位买入过多,收益更高,风险更低。


实战:用 PTrade 实现动态估值定投

以下是一个完整的动态估值定投策略代码:

python

运行


# -*- coding: gbk -*- """ 动态估值定投策略 """ def init(context): # 定投标的:沪深300ETF context.target_fund = "510300.SH" # 基准指数:沪深300指数 context.benchmark_index = "000300.SH" # 基础每月目标市值增长额(元) context.base_monthly_growth = 1000 # 定投日:每月15日 context.investment_day = 15 # 记录当前的目标市值 context.target_value = 0 # 记录定投次数 context.investment_count = 0 def handlebar(context): # 获取当前日期 current_date = context.get_current_date() current_day = int(current_date.split("-")[2]) # 判断是否是定投日 if current_day == context.investment_day: dynamic_valuation_investment(context) def dynamic_valuation_investment(context): """动态估值定投""" context.investment_count += 1 # 获取沪深300指数的PE估值 pe = context.get_index_pe(context.benchmark_index) # 获取PE的历史分位 pe_percentile = context.get_index_pe_percentile(context.benchmark_index, window=252*10) # 过去10年的分位 print(f"沪深300指数PE:{pe:.2f},历史分位:{pe_percentile:.2%}") # 根据估值分位调整目标市值增长额 if pe_percentile < 0.2: # 低估,加倍投入 monthly_growth = context.base_monthly_growth * 2 print("市场低估,加倍投入") elif pe_percentile < 0.8: # 正常估值,正常投入 monthly_growth = context.base_monthly_growth print("市场估值正常,正常投入") else: # 高估,停止投入 monthly_growth = 0 print("市场高估,停止投入") # 计算当前的目标市值 context.target_value += monthly_growth print(f"第{context.investment_count}次定投,目标市值:{context.target_value:.2f}元") # 获取当前持仓的市值 position = context.get_position(context.target_fund) current_value = position.quantity * position.last_price print(f"当前持仓市值:{current_value:.2f}元") # 计算需要投入的金额 investment_amount = context.target_value - current_value print(f"需要投入的金额:{investment_amount:.2f}元") if investment_amount > 0 and monthly_growth > 0: # 买入 price = context.get_last_price(context.target_fund) quantity = int(investment_amount / price / 100) * 100 if quantity > 0: context.order(context.target_fund, quantity, price) print(f"买入:{context.target_fund},价格:{price:.2f},数量:{quantity},金额:{quantity*price:.2f}元") elif investment_amount < 0 or pe_percentile > 0.9: # 高估或超过目标市值,卖出 if pe_percentile > 0.9: # 极度高估,清仓 sell_quantity = position.quantity print("市场极度高估,清仓") else: sell_amount = -investment_amount price = context.get_last_price(context.target_fund) sell_quantity = int(sell_amount / price / 100) * 100 if sell_quantity > 0 and sell_quantity <= position.quantity: price = context.get_last_price(context.target_fund) context.order(context.target_fund, -sell_quantity, price) print(f"卖出:{context.target_fund},价格:{price:.2f},数量:{sell_quantity},金额:{sell_quantity*price:.2f}元") else: print("无需操作") print("定投完成") 策略回测表现

我们用 2010 年到 2026 年的历史数据对这三种定投策略进行了回测,结果如下:


策略类型总收益率年化收益率最大回撤夏普比率
普通定投128.7%7.2%32.5%0.68
价值平均定投186.3%9.8%28.7%0.92
动态估值定投257.9%12.3%21.4%1.25

可以看到,进阶的定投策略收益明显高于普通定投,而且风险更低。动态估值定投的总收益率是普通定投的 2 倍,最大回撤只有 21.4%,非常适合普通投资者。

如果你想学习更多进阶定投的技巧,或者需要完整的定投策略代码,欢迎点我头像私信。我会免费为你开通 PTrade 量化权限,提供一对一定投策略指导和个性化的定投方案。

风险提示:基金投资有风险,定投不能消除市场风险。量化交易存在市场风险、策略失效风险等。本内容仅为投资者教育目的,不构成任何投资建议。

免责声明:本栏目刊载的信息力求准确可靠,但对信息的准确性或完整性不作任何保证,亦不对因使用该等信息而引发的损失承担责任。



《收益翻倍!PTrade智能定投策略从普通到进阶》由财金股基金知识频道小编撰写,部分内容来自于网络,如有侵权请及时联系我们进行删除。如需转载请注明文章来源,理财有风险,投资需警慎。

“通达信选股/做T/主力检测器”炒股指标(付费版免费送,附教程和学习视频)
最新文章
热门标签
热门推荐