OPEN-SOURCE SCRIPT
[PDR] Daily Rebalance

█ OVERVIEW
This indicator is a powerful portfolio backtesting tool designed to simulate the performance of a static-weight, daily rebalancing strategy. It allows you to define a portfolio of up to 10 assets, set their target weights, and track its cumulative return against a user-defined benchmark and a risk-free rate.
The core of the script is its daily rebalancing logic, which calculates and logs every trade needed to bring the portfolio back to its target allocations at the close of each day. This provides a transparent and detailed view of how a static portfolio would have performed historically, including the impact of trading costs.
█ KEY FEATURES
█ HOW TO USE
█ DISCLAIMER
This is a backtesting and simulation tool, not a trading signal generator. Its purpose is for research and performance analysis. Past performance is not indicative of future results. Always conduct your own research before making any investment decisions.
This indicator is a powerful portfolio backtesting tool designed to simulate the performance of a static-weight, daily rebalancing strategy. It allows you to define a portfolio of up to 10 assets, set their target weights, and track its cumulative return against a user-defined benchmark and a risk-free rate.
The core of the script is its daily rebalancing logic, which calculates and logs every trade needed to bring the portfolio back to its target allocations at the close of each day. This provides a transparent and detailed view of how a static portfolio would have performed historically, including the impact of trading costs.
█ KEY FEATURES
- Daily Rebalancing: Simulates a portfolio that is rebalanced at the close of every day to maintain target asset allocations.
- Customizable Portfolio: Configure up to 10 different assets with specific weights. If all weights are left at 0, the script automatically creates an equal-weight portfolio from the selected assets.
- Performance Comparison: Plots the portfolio's equity curve against a user-defined benchmark (e.g.,
SET50) and a risk-free return, allowing for easy relative performance analysis.
- Realistic Simulation: Accounts for trading costs like broker commission and minimum lot sizes for more accurate and grounded backtesting results.
- Detailed Performance Metrics: An on-chart table displays real-time statistics, including Current Drawdown, Max Drawdown, and Total Return for both your portfolio and the benchmark.
- Trade-by-Trade Logs: For full transparency, every rebalancing trade (BUY/SELL), including shares, price, notional value, and fees, is logged in the Pine Logs panel.
█ HOW TO USE
- **Apply to a Daily Chart:** This script is designed to work exclusively on the daily (1D) timeframe. Applying it to any other timeframe will result in a runtime error.
- **Configure Settings:** Open the indicator's settings. Set your `Initial Capital`, `Start Time`, and the `Benchmark` symbol you wish to compare against.
- **Define Your Assets:** In the 'Assets' group, check the box to enable each asset you want to include, select the symbol, and define its target `Weight (%)`.
- **Set Trading Costs:** Adjust the `Broker Commission (%)` and `Minimal Buyable Lot` to match your expected trading conditions.
- **Analyze the Results:** The performance curves are plotted in the indicator pane below your main chart. The key metrics table is displayed on the bottom-right of your chart.
- **View Rebalancing Trades:** This is a crucial step for understanding the simulation. To see the detailed daily trades, you **must** open the **Pine Logs**. You can find this panel at the bottom of your TradingView window, next to the "Pine Editor" and "Strategy Tester" tabs. The logs provide a complete breakdown of every rebalancing action.
█ DISCLAIMER
This is a backtesting and simulation tool, not a trading signal generator. Its purpose is for research and performance analysis. Past performance is not indicative of future results. Always conduct your own research before making any investment decisions.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
mastertop
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
mastertop
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。