INSIGHTS

A Qualitative and Quantitative Analysis of Copper-to-Gold & U.S. Bond Yields in R

October 23, 2024

Author: Lewin Hafner

Background & Disclaimer: This is neither a strategy nor a model that can and should be deployed in the market. It primarily serves the purpose of illustrating some knowledge and ideas I've accumulated over time. All text is authored by me as I do not rely on AI tools such as ChatGPT to do so - therefore, there might be errors in grammar and punctuation. The R code is included at the bottom of this page.

Introduction

Part of what makes financial markets such an intriguing puzzle is the observation that all markets are interconnected through various linkages. As a result, certain tradeables contain information that can aid in the decision-making process of trading other tradeables. The ratio of the price of Copper-to-Gold (herein "CGR") and 10-year bond yields (herein "B10Y") presents one such pair of tradeables, as indicated by a high visual correlation.1

While visual inspection serves as a great starting point, it can be both misleading and non-actionable. Take, for example, the relationship between interest rates and inflation rates - both correlate to a high degree, but the causal linkages that drive the two (i.e. monetary transmission channels) actually imply an opposing relationship. It is thus of high importance that we first expound on the causal assumptions we imply by infering a relationship between copper, gold, the respective ratio and bond yields. In a next step we can (and are going to) explore the relationship in a quantitative manner so it becomes more actionable. We thus pursue the following objectives: (i) understand the rationale and limitations of the relationship, (ii) explore key statistical properties such as correlation and their evolution throughout time, (iii) assess whether there's statistical causality (granger causality) and (iiii) model and analyze the relationship in a simple linear regression.

1 Copper-to-Gold-Ratio vs US 10Y Bond Yields

Part I (Rationale): An introduction to Copper, Gold, Bond Yields and their causal assumptions

Copper

Copper (Cu) is one of the rare metals that nature offers in its elementary form. It is estimated that Cu makes up for roughly 0.006% of the Earth's crust, making it a relatively scarce metal in comparison to others. Its position on the periodic table reveals its inherent properties: copper is soft, has great malleability and ductility and is an excellent conductor of thermal and electric energy. As such, it is considered one of the most important metals in industrial use and has been in use for several thousand years. The fact that demand for copper grew exponentionally throughout the 19th and 20th century underlines its function in enabling the industrialization of todays developed countries.

As governments across the globe gradually expand their efforts to reach their Net-Zero target by 2050,  elements of the green transition - EVs and their charging stations, solar panels, wind farms etc. - will create a green demand that is expected to significantly outpace supply growth in the years to come. The fact that copper is 100% recycable closely aligns with the overarching goal of reaching net-zero emissions.

In the context of markets, the reddish-brown metal bears the name of "Dr. Copper" as it is assumed to have predictive power over economic health. The underlying assumption here is that Copper is a key input factor for a variety of industries, so rising (declining) prices are a symptom of high (low) industrial demand and therefore of economic growth (contraction). Copper is indeed a industrial necessity - sectors like construction, electronics and transportation heavily rely on it. However, while certainly valid to some degree, the assumed role does not consider any supply dynamics at play. Second, "economic health" or "economic expansion" are vague terms, making a more granular view necessary: do we measure expansions in terms of nominal or real GDP? For the former, it appears important to consider that rising copper prices inherently cause a higher nominal GDP - because NGDP can rise either due to higher prices or higher quantities or a combination of the two. Third, as economies develop they undergo structural shifts that manifest, for example, in a more dominant service sector relative to manufacturing. Any attempt to analyze the relationship between copper prices and GDP thus needs to consider the relative importance the metal played throughout time. The charts below show year-on-year changes for Copper prices and a) World nominal GDP and b) China nominal GDP, indicating a weak relationship for both cases.

World Copper Price (USD) vs. Nominal World GDP
World Copper Price (USD)  vs. Nominal China GDP

Gold

Like Copper, Gold (Au) sometimes occurs in its native state. Gold is one of the densest metals, is both malleable and ductile, an excellent conductor of electricity and - as one of the least reactive metals - carries with it a great resistance to corrosion. The caveat of Gold is its scarcity: whereas 201'000 tonnes of Gold have ever existed above ground, yearly copper production alone amounts to almost 22 million metric tonnes. According to estimates, 1000 tons of continental crust contain only 4 grams of Gold! Among the largest miners of gold are China, Russia, Australia, Canada and South Africa. 50% of newly produced Gold is demanded by the jewelry industry; 40% by investments and 10% by industry. Given that the jewelry industry is of neglectible size and industrial use is limited, the question of what Gold's "raison d'être" is appears to be legitimate.

First, what comes with Gold's scarcity and shiny color is a deep, psychologically ingrained association with wealth, value, power and royalty. In Ancient Egypt, for example, Gold was used for ornamentation (e.g. necklaces, rings) and religious (e.g. funeral masks) purposes. Second, from a financial perspective, Gold has a longstanding track-record of being a store of value and medium of exchange. Starting in the Kingdom of Lydia (700 BCE) to the Persian Empire (500 BCE) and the Greek and Roman Empire (300 BCE), Golds monetary role spans across centuries. Even up until WWI and the Great Depression, Gold served as a physical anchor of paper money, in the sense that the supply of money was limited by the supply of gold (so called Gold Standard). Although reinstated in a modified form within the Bretton Woods System, the Gold Standard officially came to an end in 1971 when U.S. President Nixon suspended convertibility for foreign currencies.

Today, Gold is mainly held for diversification purposes and hedging geopolitical and macroeconomic risks. On the one hand, Gold is assumed to be a hedge against inflation because it is limited in supply. You can create fiat money out of thin air; but you can't inflate the amount of gold available. When the system is flooded with newly printed money and money loses its value (arguably depending on the definition of value), the relative scarcity of Gold leads it to retain its purchasing power. Research on whether gold is an effective hedge against inflation, however, is not consistent in its findings. Findings throughout the years indicate that the ability of gold to compensate for inflation depends on a) the country examined, b) the magnitude of inflation and c) the time horizon considered (see for example Bampinas & Panagiotidis, 2015; Beckmanna & Czudajb, 2013; Valadkhani et al., 2022). On the other hand, gold is considered to be a safe haven in times of market, economic and geopolitical distress (Baur & Smales, 2020) because it transcends national economies and appears to be a stable value. Again, these terms are highly ambiguous and a more granular view would reveal many complexities - but for the scope of this work, we stick with conventional wisdom and assume Gold to be reflective of inflation and general distress.

Bond Yields

Governments have two primary sources to finance their spending: tax receipts and debt. When outlays outweight income (tax receipts), a government runs a budget deficit that needs to financed through the issuance of debt. In the U.S., for example, the U.S. Treasury Department markets treasury securities (bonds, notes, bills etc.) to investors and issues them in an auction process. Over time, continous budget deficits pile up in the form of a debt burden that is self-sustaining in nature as interest payments on existing debt are financed through debt themselves.

A treasury security is characterized by a handful of attributes that are similar in all debt instruments. First, a bond has a par value, alternatively refered to as face value, which is the amount that an investor "lends" the government and receives back at maturity. Second, many bonds pay a yearly coupon (interest payment) to compensate investors for the foregone opportunity to invest the money elsewhere (and generate returns). Third, debt instruments usually (with exceptions like perpetual bonds) have a maturity date - the date until coupon payments are made and the date at which the investor receives the principal back.

One key thing to understand is that as bonds are traded in a secondary market, its price and therefore its yield fluctuate. Since investment-grade bonds present a relatively risk-free way to generate returns, they are often sought after in times of recessions. As more people seek to buy bonds, their prices rise and their yields (defined as the coupon rate divided by the current price) decline. Lower (higher) yields thus signal the anticipation of an economic slowdown (expansion) as investors rotate towards more risk-off (risk-on) assets. In reality, yields are far more complex - for the scope of this work, we will focus on the definition above.

Bond yields are highly relevant because their causal linkages to other elements in the system of markets and economies makes them carry a rich amount of information: 10Y yields, for example, are used as a risk-free rate in a variety models (DCF, DDM etc.) from which a variety of assets are valued; they embed economic expectations (inflation expectations, future monetary policy stance etc.); they influence corporate borrowing (and thus aggregate demand); and more. Yields are also interlinked with a variety of other elements: the exchange rate channel (which drives yield differentials), risk and credit spreads and so on. The bottom line here is that bond yields are crucial; knowing where they might be headed can be of high value (which is probably why bond traders are often refered to as the smartest on the street).

Copper-to-Gold vs. Bond Yields

As outlined above, Copper - the industrial necessity - and Gold - the safe haven in times of distress - reflect valuable and distinct information. Various sources for market practicioners, except for academic research, highlight "Dr. Coppers" role as a barometer of economic health and Gold as a barometer for economic distress. Taken together, CGR is assumed to be a barometer of which theme - growth vs. distress - dominates the current environment. Bond yields, on the other hand, capture these themes too - rising (declining) yields are a sign of higher (lower) expected growth and inflation.

There are, however, a few limitations and worthwile considerations to make. First, Copper-Gold does not cause Bond Yields to move per se. Copper as well as Gold themselves could of course cause moves in yields through various linkages chained together - what seems more likely, however, is that the relationship is the exact opposite and yields move Gold. Think about it: Gold has no inherent stream of return that determines its "intrinsic value" (like equities) and instead causes costs associated with holding it (for example storage). As such, in an environment where inflation is not an issue, it is vulnerable to high real interest rates, as the opportunity cost is high relative to other (risk-free) assets such as cash or bonds. Second, the relationship between CGR and Yields is partly self-fulfilling in nature: if bond traders base their decisions on the level of CGR, they move yields in a way so that they mirror the level of CGR.

Part II (Quantitative Analysis): Statistical Properties, Granger Causality, Regression Modelling

Part I laid the foundation for our analysis of the relationship between Gold-Copper-Ratio & 10Y Bond Yields by laying out key causal assumptions. Part II now covers the quantitative aspect of our analysis.

Data

Data for both CGR and Bond Yields is fetched from a privately-maintained SQLite Database using SQL-Syntax and the DBI and RSQLite package. CGR is defined as the quotient of the dollar-denominated price of Copper divided by the dollar-denominated price of Gold. Bond Yields refer the Yield on a U.S. Government Bond with a 10-Year maturity. Both time-series cover daily observations for the period 1990-04-02 to 2024-10-02. The entire R-Code is embedded at the bottom of this page.

Both dataframes are merged based on a shared attribute (here the date vector), sorted in ascending order and grouped by the last date per month (thereby changing from a daily to a monthly periodicity). Since economic phenomena are often better explained through the lense of changes instead of levels, year-on-year percent-changes are calculated for both CGR and B10Y.

\[ \text{YoY Percent Change} = \frac{X_t - X_{t-n}}{X_{t-n}} \times 100\% \]

Correlation and its historical evolution

One natural inquiry in the analysis of two variables is about the quantitative degree to which both move together. Correlation is a standardized measure of the direction and strength of a relationship between two variables, ranging from -1 to 1. Correlation rests upon covariance - a non-standardized measure of the direction of a relationship between two variables.

\[ \text{Cov}(X, Y) = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{n} \]

One major issue with covariance is that it is scale-dependent, meaning a dataset with large values will naturally result in a high covariance. This is where correlation comes into play. Correlation is essentially a standardized version of covariance, allowing for a measure of both direction and strength in a comparable way.

\[ r = \frac{\text{Cov}(X, Y)}{\sigma_X \sigma_Y} = \frac{\frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{n}}{\sqrt{\frac{\sum_{i=1}^{n} (x_i - \bar{x})^2}{n}} \cdot \sqrt{\frac{\sum_{i=1}^{n} (y_i - \bar{y})^2}{n}}} \]

According to calculations, CGR and B10Y correlate to a degree of 0.44. The respective YoY-changes correlate to a degree of 0.48. While certainly above 0, it suggests a rather weak to mild statistical relationship between both variables. What is perhaps more valuable is a dynamic view that considers the dimension of time. A natural inquiry in this regard is a rolling correlation that allows us to see how the relationship between our variables has evolved over time. Using the below logic, we define a function that calculates a series of correlations with a three-year window:

\[ r_{t} = \frac{\text{Cov}(X_{t-n+1:t}, Y_{t-n+1:t})}{\sigma_{X_{t-n+1:t}} \cdot \sigma_{Y_{t-n+1:t}}} \]

Per the plot below, the statistical relationship between CGR and B10Y seems to be positive most of the time but to varying degrees. Interestingly, the structural break from 21' is almost symbolic of how rapidly the interest rate regime changed in 22'.

Granger Causality

Granger causality is a statistical hypothesis test that tells us whether one variable (x) improves the predictive power over another variable (y) in relation to using past values of y to predict y alone. In other words, if we would assume that weather predictions improve the forecast of umbrella sales rather than using past values of umbrella sales alone, weather predictions (x) are said to granger-cause umbrella sales (y).

Granger causality requires time-series to be stationary (i.e. the evolution of mean, variance and autocorrelation should be constant throughout time). To test whether our variables are stationary, we conduct ADF-Tests. Interpreting whether any of the above given time-series is stationary depends on whether we can confidently reject the null hypothesis that a time-series is non-stationary.

Augmented Dickey-Fuller Test Results
Time Series Dickey-Fuller Lag Order p-value Alternative Hypothesis
Copper-Gold-Ratio (levels) -2.6896 7 0.2861 Stationary
10Y Bond Yields (levels) -2.1507 7 0.5138 Stationary
Copper-Gold-Ratio (%-YoY) -5.7759 7 0.01 Stationary
10Y Bond Yields (%-YoY) -4.9106 7 0.01 Stationary

The results above suggest that both level variables  are not stationary as p-values larger than 0.05 generally mean we cannot reject the null hypothesis. For  YoY-changes, on the other hand, we can confidently reject the null hypothesis and conclude those to be stationary, as indicated by a p-value of 0.01. Non-stationary time-series can be made stationary through a process known as first-differencing. Time-series generally consist of three components: a trend, seasonality and some noise. Through first-differencing, we essentially remove the trending component. This results in a time-series that appears more oscillating.

\[ Y_t = \text{trend}_t + \text{seasonality}_t + \text{noise}_t \]

\[ Y'_t = Y_t - Y_{t-1} \]

Running both ADF-Tests for our first-differenced variables again yields more optimistic results: we can reject the null hypothesis and therefore conclude both to be stationary.

Augmented Dickey-Fuller Test Results
Time Series Dickey-Fuller Lag Order p-value Alternative Hypothesis
Copper-Gold-Ratio (First Differenced) -9.479 7 0.01 Stationary
10Y Bond Yields (First Differenced) -7.4257 7 0.01 Stationary

Coming to granger causality, two points are worth mentioning. First, "causality" is a bit of a misnormer as the results do not infer true causality but rather "forecasting power". Second, in complex systems like markets and economies, causality often runs in both directions - interest rates drive inflation and inflation drives interest rates. Given this, we need to run granger-tests for both directions.

Financial time-series' occassionally display high correlations, when in fact, they do so in a lagged way. Think about it: if we assume that central banks have a tendency to be reactive instead of pro-active, inflation will generally be high (low) before interest rates are set to higher (lower) levels. Granger-causality considers this lag-dynamic by requiring a lag-order to be passed as an argument. In our instance, we choose a lag-order of three for all granger-tests, meaning we give our time-series' a period of three months to catch up with each other.

Granger-Causality Test Results
Test Model Residual DF DF F-statistic p-value
Copper-Gold-Ratio (%-YoY) ~ 10Y Bond Yield (%-YoY) 1 393 3 1.9079 0.1277
Copper-Gold-Ratio (%-YoY) ~ 10Y Bond Yield (%-YoY) 2 396 -3 1.9079 0.1277
10Y Bond Yield (%-YoY) ~ Copper-Gold-Ratio (%-YoY) 1 393 3 1.0186 0.3843
10Y Bond Yield (%-YoY) ~ Copper-Gold-Ratio (%-YoY) 2 396 -3 1.0186 0.3843
Copper-Gold-Ratio (First Differenced) ~ 10Y Bond Yield (First Difference) 1 404 3 1.6006 0.1887
Copper-Gold-Ratio (First Differenced) ~ 10Y Bond Yield (First Difference) 2 407 -3 1.6006 0.1887
10Y Bond Yield (First Differenced) ~ Copper-Gold-Ratio (First Difference) 1 404 3 2.7038 0.04517 *
10Y Bond Yield (First Differenced) ~ Copper-Gold-Ratio (First Difference) 2 407 -3 2.7038 0.04517 *

The results suggest that only first-differenced level variables granger-cause each other.

Regression Modelling

A univariate linear regression models the relationship between an independent (x) and dependent (y) variable by estimating a linear equation:

\[ y = \beta_0 + \beta_1 x + \epsilon \]

As one may notice, equations of such nature define a line in a cartesian coordinate system where constant a equals the intercept (value of y where x = 0) and b defines the slope (i.e. the degree to which a one-unit change in x influences y). Linear regressions estimate a line that minimizes the sum of squared residuals (the difference between predicted and actual values). The following visualization helps in developing an intuition:

\( \min_{\beta_0, \beta_1} \sum (y_i - \hat{y}_i)^2 \)

\[ \beta_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]

\[ \beta_0 = \bar{y} - \beta_1 \bar{x} \]

Scatter plot with line of best fit for CGR and B10Y (%-YoY)

Linear regressions rest upon a few key assumptions which will be adressed later again:

  • Linearity: The relationship between regressor and regressand is linear. In other words, the rate of change (the marginal effect of a one-unit change in x on y) stays the same as x increases, resulting in a constant slope.
  • Normality: Residuals, the vertical difference between predicted and actual values, follow a normal distribution
  • Homoscedasticity: The variance of residuals is evenly spread across fitted values
  • Independence: Residuals are not correlated

Base R provides a simple, yet effective function to run a linear regression (see Appendix).

Linear Regression Summary
Residuals
Min 1Q Median 3Q Max
-0.68326 -0.13869 -0.01537 0.11775 0.73997
Coefficients
Variable Estimate Std. Error t value Pr(>|t|)
Intercept 0.003419 0.011265 0.304 0.762
data_monthly$bond_10y_yield_yoy 0.328370 0.030192 10.876 <2e-16 ***
Model Summary
Residual Standard Error 0.2251 on 401 degrees of freedom
Multiple R-squared 0.2278
Adjusted R-squared 0.2259
F-statistic 118.3 on 1 and 401 DF, p-value: < 2.2e-16

Before we get to the performance metrics of our model, we first conduct some model diagnostics that give us insight into the validity of the assumptions we outlined above.

The residuals vs. fitted values plot allows us to see how residuals are distributed among fitted values. As residual = actual data point - fitted value, y = 0 equals our regression line. Under the assumption of a) linearity and b) homoscedasticity, residuals should be a) randomly scattered around the regression line and b) their spread shouldn't systematically increase or decrease as the value of fitted values increases. In our case, as the smoothing red line is tilted downwards towards the higher end of fitted values, it indicates some non-linearity in our data. Additionally, we can infer potential heterocedasticity as the spread of residuals seems to fan out towards the back end of fitted values. Performing a Breusch-Pagan test undermines our visual interpretation of potential heteroscedasticity as a p-value below the confidence threshold means we reject the null hypothesis.

Studentized Breusch-Pagan Test Results
Test Data BP Statistic Degrees of Freedom P-Value
Studentized Breusch-Pagan test slr_yoy 67.897 1 < 2.2e-16

A Q-Q plot helps in determining the validity of the normality assumption (i.e. residuals follow a normal distribution). The solid 45-degree line represents the ideal case where residual quantiles and theoretical quantiles perfectly match, indicating a normal distribution of residuals. In our case, the majority of residuals are centered around the line (i.e. a normal distribution) - however, both the lower and higher end deviates to the downside and upside, respectively. This indicates heavier tails in the distribution, thereby limiting the validity of the normality assumption.

Next, Cook's Distance gives insights into how indiviudal data points influence the regression coefficients. In our case, values on the higher end of observations appear to be highly influential.

Two common metrics to assess the performance of a regression model are R2 (coefficient of determination) and RSE (Residual Standard Error). RSE as an absolute performance metric is a measure of the average size of the residuals. In our case, a RSE of 0.2251 tells us that estimated YoY-changes in 10Y Bond Yields are on average off by 0.2251%.

\[RSS = \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 \]

\[df = n - p\]

\[RSE = \sqrt{\frac{RSS}{df}} = \sqrt{\frac{\sum_{i=1}^n (y_i - \hat{y}_i)^2}{n - p}}\]

Finally, R2 is a measure of the degree to which the variance in our dependent variable is explained by our independent variable. In our case, a R2 of 0.2278 is statistically weak.

\[TSS = \sum_{i=1}^{n} (y_i - \bar{y})^2\]

\[R^2 = 1 - \frac{RSS}{TSS}\]

Overall, these results suggest that our model is not of good quality.

References

Bampinas, G., & Panagiotidis, T. (2015). Are gold and silver a hedge against inflation? A two century perspective. International Review of Financial Analysis, 41, 267-276. https://doi.org/10.1016/j.irfa.2015.02.007

Baur, D. G., &Smales, L. A. (2020). Hedging geopolitical risk with precious metals. Journal of Banking & Finance, 117. https://doi.org/10.1016/j.jbankfin.2020.105823

Beckmanna, J., & Czudajb, R. (2013). Gold as an inflation hedge in a time-varying coefficient framework. North American Journal of Economics and Finance, 24, 208-222. https://doi.org/10.1016/j.najef.2012.10.007

Valadkhani, A., Nguyen, J., & Chiah, M. (2022). When is gold an effective hedge against inflation? Resources Policy, 79. https://doi.org/10.1016/j.resourpol.2022.103009

Appendix (R-Code)


# Initialize libraries
library(DBI)
library(RSQLite)
library(readxl)
library(ggplot2)
library(lmtest)
library(writexl)
library(dplyr)
library(forecast)
library(tsibble)
library(zoo)
library(plm)
library(tseries)
library(car)

# Establish connection to DB and query data
con = dbConnect(RSQLite::SQLite(), "C:\\Program Files\\SQLite\\databases\\time_series.db")
copper_gold_ratio = dbGetQuery(conn = con, "SELECT * FROM copper_gold_ratio")
bond_10y_yield = dbGetQuery(conn = con, "SELECT * FROM '10y_treasury_bond'")

# Merge dataframes, convert data types and order by date
data = merge.data.frame(copper_gold_ratio, bond_10y_yield, by = "date", ALL = FALSE)
data$date = as.Date(data$date)
data = data[order(data$date),]

# Convert daily to monthly periodicity
data$mdate = as.yearmon(data$date)
data_monthly = data %>% group_by(mdate) %>% summarise_all(last)

# Alternative: weekly periodicity
data$wdate = yearweek(data$date)
data_weekly = data %>% group_by(wdate) %>% summarise_all(last)
write_xlsx(x = data_weekly, path = "C:/Users/Lewin Hafner/Documents/Financial Markets & Economics/General - Exploration/Gold vs. Real Yields/data/data_weekly.xlsx")


# Calculate Year-on-Year changes
data_monthly = data_monthly %>% mutate(copper_gold_ratio_yoy = ((data_monthly$value.x - dplyr::lag(data_monthly$value.x, 12)) / dplyr::lag(data_monthly$value.x, 12)))
data_monthly = data_monthly %>% mutate(bond_10y_yield_yoy = ((data_monthly$value.y - dplyr::lag(data_monthly$value.y, 12)) / dplyr::lag(data_monthly$value.y, 12)))


# User-defined correlation function
correlation = function(x, y) {
  
  meanx = mean(x)
  meany = mean(y)
  summeandeviationxy = 0
  sqsummeandeviationx = 0
  sqsummeandeviationy = 0
  
  for (i in 1:length(x)) {
    deviationx = x[i] - meanx
    deviationy = y[i] - meany
    summeandeviationxy = summeandeviationxy + (deviationx * deviationy)
    sqsummeandeviationx = sqsummeandeviationx + (deviationx^2)
    sqsummeandeviationy = sqsummeandeviationy + (deviationy^2)
  }
  
  dividend = summeandeviationxy
  divisor = sqrt(sqsummeandeviationx * sqsummeandeviationy)
  correlationnumber = dividend / divisor
  return(correlationnumber)
  
}


# Calculate correlation
correlation(x = data_monthly$value.x, y = data_monthly$value.y)
correlation(x = data_monthly$copper_gold_ratio_yoy[13:nrow(data_monthly)], y = data_monthly$bond_10y_yield_yoy[13:nrow(data_monthly)])


# Rolling correlation for levels
data_monthly$rolling_correlation = rollapply(
  data = data_monthly[, c("value.x", "value.y")],
  width = 36,
  FUN = function(x) cor(x[, "value.x"], x[, "value.y"], use = "pairwise.complete.obs"), 
  by.column = FALSE,
  align = "right",
  fill = NA         
)


# Rolling correlation for YoY growth
data_monthly$rolling_correlation_yoy = rollapply(
  data = data_monthly[, c("copper_gold_ratio_yoy", "bond_10y_yield_yoy")],
  width = 36,
  FUN = function(x) cor(x[, "copper_gold_ratio_yoy"], x[, "bond_10y_yield_yoy"], use = "pairwise.complete.obs"),
  by.column = FALSE,
  align = "right",
  fill = NA
)



Privacy Policy
Lewin Hafner | Zurich, Switzerland