OPEN-SOURCE SCRIPT
Portfolio Simulator & Backtester

Multi-asset portfolio simulator with different metrics and ratios, DCA modeling, and rebalancing strategies.
Core Features
Portfolio Construction
Dollar Cost Averaging
Rebalancing
Key Metrics Table
Visualization
🚀 Quick Start Guide
💡 Pro Tips
⚠️ Important Notes
Let me know if you have any suggestions to improve this simulator.
Core Features
Portfolio Construction
- Up to 5 assets with customizable weights (must total 100%)
- Support for any tradable symbol: stocks, ETFs, crypto, indices, commodities
- Real-time validation of allocations
Dollar Cost Averaging
- Monthly or Quarterly contributions
- Applies to both portfolio and benchmark for fair comparison
- Model real-world investing behavior
Rebalancing
- Four strategies: None, Monthly, Quarterly, Yearly
- Automatic rebalancing to target weights
- Transaction cost modeling (customizable fee %)
Key Metrics Table
- CAGR: Annualized compound return (S&P 500 avg: ~10%)
- Alpha: Excess return vs. benchmark (positive = outperformance)
- Sharpe Ratio: Return per unit of risk (>1.0 is good, >2.0 excellent)
- Sortino Ratio: Like Sharpe but only penalizes downside (better metric)
- Calmar Ratio: CAGR / Max Drawdown (>1.0 good, >2.0 excellent)
- Max Drawdown: Largest peak-to-trough decline
- Win Rate: % of positive days (doesn't indicate profitability)
Visualization
- Dual-chart comparison - Portfolio vs. Benchmark
- Dollar or percentage view toggle
- Customizable colors and line width
- Two tables: Statistics + Asset Allocation
- Adjustable table position and text size
🚀 Quick Start Guide
- Enter 1-5 ticker symbols (e.g., SPY, QQQ, TLT, GLD, BTCUSD)
- Make sure percentage weights total 100%
- Choose date range (ensure chart shows full period - zoom out!)
- Configure DCA and rebalancing (optional)
- Select benchmark (default: SPX)
- Analyze results in statistics table
💡 Pro Tips
- Chart data matters: Load SPY or your longest-history asset as main chart
- If you select an asset that was not available for the selected period, the chart will not show up! E.g. BTCUSD data: Only available from ~2017 onwards.
- Transaction fees: 0.1% default (adjust to match your broker)
⚠️ Important Notes
- Requires visible chart data (zoom out to show full date range)
- Limited by each asset's historical data availability
- Transaction fees and costs are modeled, but taxes/slippage are not
- Past performance ≠ future results
- Use for research and education only, not financial advice
Let me know if you have any suggestions to improve this simulator.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้มันเป็นโอเพ่นซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันการทำงานของสคริปต์ได้ ขอแสดงความชื่นชมผู้เขียน! แม้ว่าคุณจะสามารถใช้งานได้ฟรี แต่อย่าลืมว่าการเผยแพร่โค้ดซ้ำนั้นจะต้องเป็นไปตามกฎระเบียบการใช้งานของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้มันเป็นโอเพ่นซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันการทำงานของสคริปต์ได้ ขอแสดงความชื่นชมผู้เขียน! แม้ว่าคุณจะสามารถใช้งานได้ฟรี แต่อย่าลืมว่าการเผยแพร่โค้ดซ้ำนั้นจะต้องเป็นไปตามกฎระเบียบการใช้งานของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน