发布时间:2026/7/31 4:56:50
定投纳斯达克20年会有多少收益 背景最近网上看到有人问豆包定投的问题验证1豆包的计算正确吗我拿同样的问题问了DeepSeek感觉Deepseek不太准截至到2026年4月来计算投入金额应该在60w左右。验证2再问问ChatgptChatgpt投入金额与豆包计算结果相同但持有的总市值本金收益与豆包计算的结果要差一半到底哪个是对的验证3我让Chatgpt写了一段代码以 $纳指100ETF-Invesco(QQQ)$ 为标的看看20年究竟能收益多钱标的: QQQ投资起始: 2006-01-01当前日期: 2026-05-28累计投入本金: 602,000.00累计持仓份额: 5,652.1816当前价格: 729.45当前市值: 4,122,983.94累计收益: 3,520,983.94总收益率: 584.88%年化收益率(XIRR): 19.28%当前市值为412w收益额为352w足够直观20年接近6倍的收益年化收益率约20%非常强业绩超过了80%的基金经理。代码import yfinance as yf import pandas as pd from dateutil.relativedelta import relativedelta from scipy.optimize import newton # # 参数配置 # TICKER SPY FX_TICKER CNYX # USD/CNY START_DATE 2006-01-01 INITIAL_MONTHLY_RMB 1000 YEARLY_INCREMENT_RMB 150 # # 下载数据 # def download_price_data( ticker, start_date ): df yf.download( ticker, startstart_date, auto_adjustTrue, progressFalse ) if df.empty: raise ValueError(f{ticker} 没有下载到数据) else: print(f获取到{len(df)}条数据) # 修复 MultiIndex if isinstance(df.columns, pd.MultiIndex): df.columns df.columns.get_level_values(0) df df[[Close]].copy() df.index pd.to_datetime(df.index) return df # # 生成定投日期 # def generate_invest_dates(df): start_dt df.index.min() end_dt df.index.max() current pd.Timestamp( yearstart_dt.year, monthstart_dt.month, day1 ) invest_dates [] while current end_dt: invest_dates.append(current) current relativedelta(months1) return invest_dates # # 获取实际交易日 # def get_actual_trade_date(df, invest_date): future_dates df.index[df.index invest_date] if len(future_dates) 0: return None return future_dates[0] # # XIRR # def xnpv(rate, cashflows): t0 cashflows[0][0] return sum( cf / ((1 rate) ** ((t - t0).days / 365.0)) for t, cf in cashflows ) def xirr(cashflows, guess0.1): return newton( lambda r: xnpv(r, cashflows), guess ) # # 定投模拟加入汇率 # def simulate_dca_with_fx( etf_df, fx_df, invest_dates, initial_monthly_rmb, yearly_increment_rmb ): total_shares 0.0 total_invested_rmb 0.0 records [] cashflows [] for invest_date in invest_dates: actual_date get_actual_trade_date( etf_df, invest_date ) if actual_date is None: break # # 获取 ETF 价格 # etf_price_usd float( etf_df.loc[actual_date, Close] ) # # 获取汇率 # CNYX 表示: # 1 USD ? RMB # fx_rate float( fx_df.loc[actual_date, Close] ) # # 计算定投金额 # years_passed actual_date.year - 2006 monthly_rmb ( initial_monthly_rmb years_passed * yearly_increment_rmb ) # RMB - USD monthly_usd monthly_rmb / fx_rate # 买入份额 shares_bought monthly_usd / etf_price_usd total_shares shares_bought total_invested_rmb monthly_rmb # 现金流人民币 cashflows.append( (actual_date, -monthly_rmb) ) records.append({ date: actual_date, monthly_rmb: monthly_rmb, fx_rate: fx_rate, monthly_usd: monthly_usd, etf_price_usd: etf_price_usd, shares_bought: shares_bought, total_shares: total_shares }) # # 当前资产 # latest_etf_price float( etf_df[Close].iloc[-1] ) latest_fx_rate float( fx_df[Close].iloc[-1] ) # ETF 市值美元 current_value_usd ( total_shares * latest_etf_price ) # 转回人民币 current_value_rmb ( current_value_usd * latest_fx_rate ) profit_rmb ( current_value_rmb - total_invested_rmb ) cashflows.append( ( etf_df.index[-1], current_value_rmb ) ) annual_return xirr(cashflows) result { total_invested_rmb: total_invested_rmb, total_shares: total_shares, current_value_usd: current_value_usd, current_value_rmb: current_value_rmb, profit_rmb: profit_rmb, xirr: annual_return, records: pd.DataFrame(records) } return result # # 主程序 # def main(): print(下载 ETF 数据...) etf_df download_price_data( TICKER, START_DATE ) print(下载汇率数据...) fx_df download_price_data( FX_TICKER, START_DATE ) # 对齐日期 common_index etf_df.index.intersection( fx_df.index ) etf_df etf_df.loc[common_index] fx_df fx_df.loc[common_index] invest_dates generate_invest_dates( etf_df ) result simulate_dca_with_fx( etf_dfetf_df, fx_dffx_df, invest_datesinvest_dates, initial_monthly_rmbINITIAL_MONTHLY_RMB, yearly_increment_rmbYEARLY_INCREMENT_RMB ) # # 输出 # print( * 60) print(fETF: {TICKER}) print( * 60) print( f累计投入(RMB): f{result[total_invested_rmb]:,.2f} ) print( f累计持仓份额: f{result[total_shares]:,.4f} ) print( f当前市值(USD): f{result[current_value_usd]:,.2f} ) print( f当前市值(RMB): f{result[current_value_rmb]:,.2f} ) print( f累计收益(RMB): f{result[profit_rmb]:,.2f} ) print( f总收益率: f{result[profit_rmb] / result[total_invested_rmb] * 100:.2f}% ) print( f年化收益率(XIRR): f{result[xirr] * 100:.2f}% ) print( * 60) # # 启动 # if __name__ __main__: main()

相关新闻

2026/7/31 4:56:50

龍魂·数字根计算引擎 v1.0

这是专门为龙魂系统定制的数字根计算引擎,CNSH五行计算器和流场压缩核的底层组件。 #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 龍魂数字根计算引擎 v1.0 DNA: #龍芯⚡️丙午乙未甲辰离为火-数字根引擎-v1.0 CONFIRM: #CONFIRM&#x1f30…

2026/7/31 4:56:49

带你从不同视角了解三大MQ

前言 首先我提一点我自己的学习心得,我通过最近学习项目,我觉得我们在学习新技术的时候,要始终记得有一个前提:技术的诞生是为了解决问题。 我们不要为了学而去学,这样其实没自己思考学的和理解的也比较慢&#xff0…

2026/7/31 4:51:49

AI写作工具在学术专著创作中的高效应用

1. AI写作工具在学术专著创作中的革命性应用当我在2022年第一次尝试用AI工具辅助完成我的第三本专业著作时,那种效率提升的震撼感至今难忘。传统专著写作往往需要耗费学者数月甚至数年的心血,而现在,合理运用AI工具可以将初稿产出时间缩短60%…

2026/7/31 8:57:00

Comsol模拟岩石热-水-力耦合损伤的工程实践

1. 项目概述:岩石损伤与热水力耦合的工程挑战 在深部资源开采、地热开发及核废料地质处置等工程领域,岩石在热-水-力(THM)多场耦合作用下的损伤演化一直是困扰工程师的核心难题。传统单一场分析无法解释高温高压渗流环境下岩石的渐…

2026/7/31 8:57:00

会议录音怎么知道是谁说的?AI发言人识别到底准不准?

开完一场多人讨论会,翻录音找某个人的观点要拖半小时时间轴?整理会议纪要时分不清哪句话是产品说的哪句是研发说的?相信很多经常参会的人都遇到过这个问题。AI 发言人识别技术号称能自动区分不同说话人,但实际用起来经常出现串人、…

2026/7/31 8:57:00

低成本开启 AI 布局,主流大模型商用接口稳定供应

人工智能商业化持续提速,大模型 API 正在成为各行各业数字化转型的核心基础设施。想要搭建 AI 应用,从头自研大模型需要投入巨额算力、组建专业算法团队,漫长的研发周期让很多中小企业望而却步。依托成熟大模型 API 服务,开发者与…

2026/7/31 8:52:00

Wireshark Lua插件开发:深度解析Portal认证协议

1. 项目概述:为什么我们需要一个Portal协议的Wireshark Lua插件?如果你经常和网络认证打交道,尤其是那种在酒店、机场、校园里常见的“网页弹窗认证”(也就是Portal认证),那你肯定对抓包分析不陌生。Wiresh…

2026/7/29 22:32:30

PDF合并与动态水印的工程化方案:2026国内免费工具实测对比

一、背景与测试方案 在实际项目交付中,PDF文件合并与版权保护水印的叠加是一个高频但容易被低估的技术需求。典型的处理链路涉及:多源PDF的文件流合并、页面级水印渲染(含透明度混合与图层叠加)、输出文件体积控制。看似简单的操作…

2026/7/31 0:01:11

物理复制比逻辑复制好在哪?数据库复制原理详解

数据库复制是把主库数据同步到备库的机制,分为逻辑复制和物理复制两种。逻辑复制传输的是 SQL 语句或行变更事件,物理复制传输的是存储引擎底层的物理日志。阿里云 PolarDB(云原生数据库)采用物理复制,在同步延迟、数据…

2026/7/31 0:01:11

BilibiliDown:3分钟学会B站视频下载的终极指南

BilibiliDown:3分钟学会B站视频下载的终极指南 【免费下载链接】BilibiliDown (GUI-多平台支持) B站 哔哩哔哩 视频下载器。支持稍后再看、收藏夹、UP主视频批量下载|Bilibili Video Downloader 😳 项目地址: https://gitcode.com/gh_mirrors/bi/Bilib…

2026/7/31 0:01:11

有哪些游戏数据AI平台?游戏行业Data+AI融合方案盘点

当前,游戏行业的“DataAI融合”已从概念验证进入价值落地阶段。根据IDC 2025年数据,中国AI游戏云市场规模已达18.6亿元;同时,游戏研发环节AI渗透率高达86%,生成式AI内容普及率超过50%。面对庞大的市场,游戏…

2026/7/31 0:38:56

3个高效策略:快速掌握Axure中文界面配置

3个高效策略:快速掌握Axure中文界面配置 【免费下载链接】axure-cn Chinese language file for Axure RP. Axure RP 简体中文语言包。支持 Axure 11、10、9。不定期更新。 项目地址: https://gitcode.com/gh_mirrors/ax/axure-cn 还在为Axure RP的英文界面感…