
Bitcoin Alerts PRO
Log in now to create exclusive alerts!Your email is the only information we'll need.
Login
- Low-to-Low Comparison
- Global M2 Growth
- CounterFlow Model
- Google Trends
- After Halving Comparison
- Funding Rate
- Open Interest
- Bitcoin Dominance
- Fear & Greed Index
- Bitcoin x Gold x S&P500
- Bull Market Drawdowns
- Price Visit Frequency Heatmap
- Daily Change %
- Drawdown from ATH
- Mayer Multiple
- BTC 30d Volatility
- Futures vs Spot Volume
- NUPL
- Coinglass SuperChart
- MSTR Charts
Chart Explained
Loading Data...
The Table calculates the correlation between the M2 money supply and the prices of Bitcoin, Gold, and the S&P 500 over different time periods. Correlation is a statistical measure that indicates the strength and direction of the relationship between two variables.
Explanation of Correlation Calculation
The correlation is calculated based on historical data for Bitcoin prices, Gold prices, the S&P 500, and the M2 money supply using the Pearson correlation formula.
Let's understand how it works in the code:
- Data Collected: The code fetches data from two sources:
- M2 Supply: The amount of money in circulation, fetched from an API.
- Bitcoin, Gold, and S&P 500: Prices of these financial assets, also fetched from another API.
- Data Alignment: The M2, Bitcoin, Gold, and S&P 500 data are aligned by date, meaning the price of each asset is paired with the corresponding M2 value for the same day. The code ensures that only the dates that are present in both the M2 and the financial asset data are considered for correlation calculation.
- Pearson Correlation Calculation: The Pearson correlation is calculated using the following formula:
r = (Σ (xi - x̄)(yi - ȳ)) / √(Σ (xi - x̄)2 Σ (yi - ȳ)2)Where:
- xi and yi: The individual values of the variables (M2 and the financial asset).
- x̄ and ȳ: The means of the M2 and asset values.
- The numerator represents the sum of the products of the deviations of values from their means.
- The denominator is the product of the sum of squared deviations for each variable.
- Periods Considered: The code calculates correlation for four periods:
- All Periods: All available data.
- Last 4 Years: Data from the last 4 years only.
- Last 2 Years: Data from the last 2 years only.
- Last Year: Data from the last year only.
- Displaying Results: After calculating the correlation for each period, the results are displayed in an HTML table. The correlation is expressed as a percentage, and correlations are categorized for Bitcoin, Gold, and the S&P 500. The table contains the following columns:
- Asset/Period: The financial asset (Bitcoin, Gold, S&P 500).
- All Periods, Last 4 Years, Last 2 Years, Last Year: The calculated correlations for each period.
- Correlation Calculation: The
calculateCorrelation()
function is called to calculate the correlation between the M2 supply and the asset values. If the data lengths are different, the code returns a warning and does not calculate the correlation for those datasets.
Summary
This code calculates the Pearson correlation between the M2 money supply and the prices of Bitcoin, Gold, and the S&P 500 over different time periods. Pearson correlation is used to measure the linear relationship between two variables, indicating whether they move together or not. The result is displayed in a table, showing the correlations for the different periods analyzed.