OPEN-SOURCE SCRIPT
Portfolio Strategy Tester

The Portfolio Strategy Tester is an institutional-grade backtesting framework that evaluates the performance of trend-following strategies on multi-asset portfolios. It enables users to construct custom portfolios of up to 30 assets and apply moving average crossover strategies across individual holdings. The model features a clear, color-coded table that provides a side-by-side comparison between the buy-and-hold portfolio and the portfolio using the risk management strategy, offering a comprehensive assessment of both approaches relative to the benchmark.
Portfolios are constructed by entering each ticker symbol in the menu, assigning its respective weight, and reviewing the total sum of individual weights displayed at the top left of the table. For strategy selection, users can choose between Exponential Moving Average (EMA), Simple Moving Average (SMA), Wilder’s Moving Average (RMA), Weighted Moving Average (WMA), Moving Average Convergence Divergence (MACD), and Volume-Weighted Moving Average (VWMA). Moving average lengths are defined in the menu and apply only to strategy-enabled assets.
To accurately replicate real-world portfolio conditions, users can choose between daily, weekly, monthly, or quarterly rebalancing frequencies and decide whether cash is held or redistributed. Daily rebalancing maintains constant portfolio weights, while longer intervals allow natural drift. When cash positions are not allowed, capital from bearish assets is automatically redistributed proportionally among bullish assets, ensuring the portfolio remains fully invested at all times. The table displays a comprehensive set of widely used institutional-grade performance metrics:
Cumulative returns are displayed on each label as the total percentage gain from the selected start date, with green indicating positive returns and red indicating negative returns. In the table, baseline metrics serve as the benchmark reference and are always gray. For portfolio metrics, green indicates outperformance relative to the baseline, while red indicates underperformance relative to the baseline. For strategy metrics, green indicates outperformance relative to both the baseline and the portfolio, red indicates underperformance relative to both, and gray indicates underperformance relative to either the baseline or portfolio. Metrics such as Volatility, Tracking Error, and Turnover ratio are always displayed in gray as they serve as descriptive measures.
In summary, the Portfolio Strategy Tester is a comprehensive backtesting tool designed to help investors evaluate different trend-following strategies on custom portfolios. It enables real-world simulation of both active and passive investment approaches and provides a full set of standard institutional-grade performance metrics to support data-driven comparisons. While results are based on historical performance, the model serves as a powerful portfolio management and research framework for developing, validating, and refining systematic investment strategies.
Portfolios are constructed by entering each ticker symbol in the menu, assigning its respective weight, and reviewing the total sum of individual weights displayed at the top left of the table. For strategy selection, users can choose between Exponential Moving Average (EMA), Simple Moving Average (SMA), Wilder’s Moving Average (RMA), Weighted Moving Average (WMA), Moving Average Convergence Divergence (MACD), and Volume-Weighted Moving Average (VWMA). Moving average lengths are defined in the menu and apply only to strategy-enabled assets.
To accurately replicate real-world portfolio conditions, users can choose between daily, weekly, monthly, or quarterly rebalancing frequencies and decide whether cash is held or redistributed. Daily rebalancing maintains constant portfolio weights, while longer intervals allow natural drift. When cash positions are not allowed, capital from bearish assets is automatically redistributed proportionally among bullish assets, ensuring the portfolio remains fully invested at all times. The table displays a comprehensive set of widely used institutional-grade performance metrics:
- CAGR = Compounded annual growth rate of returns.
- Volatility = Annualized standard deviation of returns.
- Sharpe = CAGR per unit of annualized standard deviation.
- Sortino = CAGR per unit of annualized downside deviation.
- Calmar = CAGR relative to maximum drawdown.
- Max DD = Largest peak-to-trough decline in value.
- Beta (β) = Sensitivity of returns relative to benchmark returns.
- Alpha (α) = Excess annualized risk-adjusted returns relative to benchmark.
- Upside = Ratio of average return to benchmark return on up days.
- Downside = Ratio of average return to benchmark return on down days.
- Tracking = Annualized standard deviation of returns versus benchmark.
- Turnover = Average sum of absolute changes in weights per year.
Cumulative returns are displayed on each label as the total percentage gain from the selected start date, with green indicating positive returns and red indicating negative returns. In the table, baseline metrics serve as the benchmark reference and are always gray. For portfolio metrics, green indicates outperformance relative to the baseline, while red indicates underperformance relative to the baseline. For strategy metrics, green indicates outperformance relative to both the baseline and the portfolio, red indicates underperformance relative to both, and gray indicates underperformance relative to either the baseline or portfolio. Metrics such as Volatility, Tracking Error, and Turnover ratio are always displayed in gray as they serve as descriptive measures.
In summary, the Portfolio Strategy Tester is a comprehensive backtesting tool designed to help investors evaluate different trend-following strategies on custom portfolios. It enables real-world simulation of both active and passive investment approaches and provides a full set of standard institutional-grade performance metrics to support data-driven comparisons. While results are based on historical performance, the model serves as a powerful portfolio management and research framework for developing, validating, and refining systematic investment strategies.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
👉 Unlock exclusive indicators for free: join.quantitativealpha.com/
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
👉 Unlock exclusive indicators for free: join.quantitativealpha.com/
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。