OPEN-SOURCE SCRIPT
Geometric Monthly Returns Heatmap

Overview
The Geometric Monthly Returns Heatmap is a powerful visual dashboard that breaks down asset performance by month and year. Unlike standard performance tables that only show simple arithmetic sums, this indicator calculates both Geometric and Arithmetic Year-to-Date (YTD) returns side-by-side. This allows traders to see the true compounding impact of monthly gains and losses on their equity.
How It Works & Calculations
The script initializes a dynamic table in the bottom-right corner of your chart and populates historical data using a localized historical indexing loop:
Key Features
How to Use
Disclaimer
This script is strictly for educational and informational purposes. Past performance, whether geometric or arithmetic, is not a guarantee of future market results. Always apply proper risk management.
The Geometric Monthly Returns Heatmap is a powerful visual dashboard that breaks down asset performance by month and year. Unlike standard performance tables that only show simple arithmetic sums, this indicator calculates both Geometric and Arithmetic Year-to-Date (YTD) returns side-by-side. This allows traders to see the true compounding impact of monthly gains and losses on their equity.
How It Works & Calculations
The script initializes a dynamic table in the bottom-right corner of your chart and populates historical data using a localized historical indexing loop:
- Monthly Returns ((m_ret)): Calculated using the closing price of the current month versus the closing price of the previous month: ((close / close[1]) - 1) * 100.
- Arithmetic YTD (Ari YTD): The simple linear sum of all monthly returns for that specific year ((sum R_i)).
- Geometric YTD (Geo YTD): Reflects the actual compounded return of the asset by converting percentages to multipliers, compounding them, and converting them back: ((prod (1 + R_i) - 1) times 100). This exposes the true dragging effect of large negative months on overall performance.
Key Features
- Dual YTD View: Instantly compare the linear performance against the actual compounded performance.
- Smart Data Fetching: Built using request.security arrays to pull precise monthly metrics.
- Error Handling: Features a safety check (timeframe.ismonthly) that alerts you to switch to a Monthly chart, ensuring the data arrays map perfectly to the grid.
- ]Fully Customizable Layout: Change lookback depth and color thresholds instantly via the user input menu.
How to Use
- Add the script to your chart.
- Crucial: Switch your chart timeframe to Monthly (1M). The script will throw a clear runtime error if used on lower timeframes to prevent data distortion.
- Open the script settings to adjust the lookback window (up to 30 years) or modify the positive/negative color heat thresholds to match your chart theme.
Disclaimer
This script is strictly for educational and informational purposes. Past performance, whether geometric or arithmetic, is not a guarantee of future market results. Always apply proper risk management.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.