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 de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.