OPEN-SOURCE SCRIPT

Geometric Monthly Returns Heatmap

429
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:
  • 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
  1. Add the script to your chart.
  2. 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.
  3. 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.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.