OPEN-SOURCE SCRIPT

Historical Correlation [LuxAlgo]

The Historical Correlation tool aims to provide the historical correlation coefficients of up to 10 pairs of user-defined tickers starting from a user-defined point in time.

Users can choose to display the historical values as lines or the most recent correlation values as a heat map.

🔶 USAGE

لقطة

This tool provides historical correlation coefficients, the correlation coefficient between two assets highlight their linear relationship and is always within the range (-1, 1).

It is a simple and easy to use statistical tool, with the following interpretation:

  • Positive correlation (values close to +1.0): the two assets move in sync, they rise and fall at the same time.
  • Negative correlation (values close to -1.0): the two assets move in opposite directions: when one goes up, the other goes down and vice versa.
  • No correlation (values close to 0): the two assets move independently.


The user must confirm the selection of the anchor point in order for the tool to be executed; this can be done directly on the chart by clicking on any bar, or via the date field in the settings panel.

For the parameter Anchor period, the user can choose between the following values NONE, HOURLY, DAILY, WEEKLY, MONTHLY, QUARTERLY and YEARLY. If NONE is selected, there will be no resetting of the calculations, otherwise the calculations will start from the first bar of the new period.

There is a wide range of trading strategies that make use of correlation coefficients between assets, some examples are:

  • Pair Trading: Traders may wish to take advantage of divergences in the price movements of highly positively correlated assets; even highly positively correlated assets do not always move in the same direction; when assets with a correlation close to +1.0 diverge in their behavior, traders may see this as an opportunity to buy one and sell the other in the expectation that the assets will return to the likely same price behavior.

  • Sector rotation: Traders may want to favor some sectors that are expected to perform in the next cycle, tracking the correlation between different sectors and between the sector and the overall market.

  • Diversification: Traders can aim to have a diversified portfolio of uncorrelated assets. From a risk management perspective, it is useful to know the correlation between the assets in your portfolio, if you hold equal positions in positively correlated assets, your risk is tilted in the same direction, so if the assets move against you, your risk is doubled. You can avoid this increased risk by choosing uncorrelated assets so that they move independently.

  • Hedging: Traders may want to hedge positions with correlated assets, from a hedging perspective, if you are long an asset, you can hedge going long a negative correlated asset or going short a positive correlated asset.


Traders generally need to develop awareness, a key point is to be aware of the relationships between the assets we hold or trade, the historical correlation is an invaluable tool in our arsenal which allows us to make better informed decisions.

لقطة

On this chart we have an example of historical correlations for several futures markets.

We can clearly see how positively correlated the Nasdaq100 and Dow30 are with the SP500 over the whole period, or how the correlation between the Euro and the SP500 falls from almost +85% to almost -4% since 2021.

As we can see, correlations, like everything else in the market, are not static and vary over time depending on many factors, from macro to technical and everything in between.

🔹 Heatmap

لقطة

The chart above shows the tool with the default settings and the Drawing Mode set to 'HEATMAP'.

We can see the current correlation between the assets, in this case the FX pairs.

  • The highest positive correlation is +90% (+0.90) between EURUSD and GBPUSD.
  • The highest negative correlation is -78% (-0.78) between EURUSD and USDJPY.
  • The pair with no correlation is AUDUSD and EURCAD with 1% (0.01)


لقطة

On the above chart we can see the current correlations for the futures markets.

Currently, the assets that are less correlated to the SP500 are NaturalGas and the Euro, the more positive correlations are Nasdaq100 and Dow20, and the more negative correlations are the Yen, Treasury Bonds and 10-Year Notes.

🔶 DETAILS

🔹 Anchor Period

لقطة

This chart shows the standard FX correlations with the Anchor Period set to `MONTHLY`.

We can clearly see how the calculations restart with the new month, in this case we can clearly see the differences between the correlations from month to month.

Let us look at the correlation coefficient between GBPUSD and USDJPY

  • In January, their correlation started at close to -100%, rose to close to +50%, only to fall to close to 0% and remain there for the second half of the month.
  • In February it was -90% in the first few days of the month and is now around -57%.


And between AUDUSD and EURCAD

  • Last month their correlation was negative for most of the month, reaching -70% and ending around -14%.
  • This month their correlation has never gone below +21% and at the time of writing is close to +53%.


🔶 SETTINGS

  • Anchor point: Starting point from which the tool is executed
  • Anchor period: At the beginning of each new period, the tool will reset the calculations
  • Pairs from 1 to 10: For each pair of tickers, you can: enable/disable the pair, select the color and specify the two tickers from which you wish to obtain the correlation


🔹 Style

  • Drawing Mode: Output style, `LINES` will show the historical correlations as lines, `HEATMAP` will show the current correlations with a color gradient from green for correlations near 1 to red for correlations near -1.
Centered OscillatorscorrelationCorrelation Coefficient (CC)ForexheatmaphistoricalanalysisluxalgoPortfolio managementstatistics

نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعد‎‎قوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟


Get access to our exclusive tools: luxalgo.com

Join our 150k+ community: discord.gg/lux

All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
يعمل أيضًا:

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