R Markdown

LOADING PACKAGE

library(tidyquant)
library(fPortfolio)
library(PerformanceAnalytics)
library(xts)
library(readr)
library(dplyr)
library(lubridate)
library(timetk)
library(purrr)
library(kableExtra)
library(tibble)

LOADING DATA FROM YAHOO

We download the stock price, gold price, oil price and U.S. dollar index from yahoo:
Historical data of US dollar, oil, gold, and stock prices
USOIL GOLD DOLLAR DJI
2011-01-01 92.19 1333.8 77.74 11891.93
2011-02-01 96.97 1409.3 76.89 12226.34
2011-03-01 106.72 1438.9 75.86 12319.73
2011-04-01 113.93 1556.0 72.93 12810.54
2011-05-01 102.70 1535.9 74.64 12569.79
2011-06-01 95.42 1502.3 74.30 12414.34
2011-07-01 95.70 1628.3 73.90 12143.24
2011-08-01 88.81 1828.5 74.13 11613.53
2011-09-01 79.20 1620.4 78.55 10913.38
2011-10-01 93.19 1724.2 76.17 11955.01
2011-11-01 100.36 1745.5 78.39 12045.68
2011-12-01 98.83 1565.8 80.17 12217.56
2012-01-01 98.48 1737.8 79.28 12632.91
2012-02-01 107.07 1709.9 78.73 12952.07
2012-03-01 103.02 1669.3 78.93 13212.04
2012-04-01 104.87 1663.4 78.79 13213.63
2012-05-01 86.53 1562.6 83.04 12393.45
2012-06-01 84.96 1603.5 81.65 12880.09
2012-07-01 88.06 1610.5 82.64 13008.68
2012-08-01 96.47 1684.6 81.25 13090.84
2012-09-01 92.19 1771.1 79.94 13437.13
2012-10-01 86.24 1717.5 79.92 13096.46
2012-11-01 88.91 1710.9 80.15 13025.58
2012-12-01 91.82 1674.8 79.77 13104.14
2013-01-01 97.49 1660.6 79.21 13860.58
2013-02-01 92.05 1577.7 81.98 14054.49
2013-03-01 97.23 1594.8 82.99 14578.54
2013-04-01 93.46 1472.2 81.73 14839.80
2013-05-01 91.97 1392.6 83.38 15115.57
2013-06-01 96.56 1223.8 83.17 14909.60
2013-07-01 105.03 1312.4 81.45 15499.54
2013-08-01 107.65 1396.1 82.09 14810.31
2013-09-01 102.33 1326.5 80.22 15129.67
2013-10-01 96.38 1323.6 80.20 15545.75
2013-11-01 92.72 1250.6 80.68 16086.41
2013-12-01 98.42 1201.9 80.04 16576.66
2014-01-01 97.49 1240.1 81.27 15698.85
2014-02-01 102.59 1321.4 79.78 16321.71
2014-03-01 101.58 1283.4 80.10 16457.66
2014-04-01 99.74 1295.6 79.49 16580.84
2014-05-01 102.71 1245.6 80.37 16717.17
2014-06-01 105.37 1321.8 79.78 16826.60
2014-07-01 98.17 1281.3 81.46 16563.30
2014-08-01 95.96 1285.8 82.75 17098.45
2014-09-01 91.16 1210.5 85.94 17042.90
2014-10-01 80.54 1171.1 86.88 17390.52
2014-11-01 66.15 1175.2 88.36 17828.24
2014-12-01 53.27 1183.9 90.27 17823.07
2015-01-01 48.24 1278.5 94.80 17164.95
2015-02-01 49.76 1212.6 95.25 18132.70
2015-03-01 47.60 1183.1 98.36 17776.12
2015-04-01 59.63 1182.4 94.60 17840.52
2015-05-01 60.30 1189.4 96.91 18010.68
2015-06-01 59.47 1171.5 95.49 17619.51
2015-07-01 47.12 1094.9 97.37 17689.86
2015-08-01 49.20 1131.6 95.95 16528.03
2015-09-01 45.09 1115.5 96.35 16284.70
2015-10-01 46.59 1141.5 96.95 17663.54
2015-11-01 41.65 1065.8 100.17 17719.92
2015-12-01 37.04 1060.3 98.63 17425.03
2016-01-01 33.62 1116.4 99.61 16466.30
2016-02-01 33.75 1233.9 98.21 16516.50
2016-03-01 38.34 1234.2 94.59 17685.09
2016-04-01 45.92 1289.2 93.08 17773.64
2016-05-01 49.10 1214.8 95.89 17787.20
2016-06-01 48.33 1318.4 96.14 17929.99
2016-07-01 41.60 1349.0 95.53 18432.24
2016-08-01 44.70 1306.9 96.02 18400.88
2016-09-01 48.24 1313.3 95.46 18308.15
2016-10-01 46.86 1271.5 98.45 18142.42
2016-11-01 49.44 1170.8 101.50 19123.58
2016-12-01 53.72 1150.0 102.39 19762.60
2017-01-01 52.81 1208.6 99.51 19864.09
2017-02-01 54.01 1252.6 101.12 20812.24
2017-03-01 50.60 1247.3 100.35 20663.22
2017-04-01 49.33 1266.1 99.05 20940.51
2017-05-01 48.32 1272.0 96.92 21008.65
2017-06-01 46.04 1240.7 95.66 21349.63
2017-07-01 50.17 1266.6 92.86 21891.12
2017-08-01 47.23 1316.2 92.67 21948.10
2017-09-01 51.67 1281.5 93.08 22405.09
2017-10-01 54.38 1267.0 94.55 23377.24
2017-11-01 57.40 1273.2 93.01 24272.35
2017-12-01 60.42 1306.3 92.12 24719.22
2018-01-01 64.73 1339.0 89.13 26149.39
2018-02-01 61.64 1315.5 90.61 25029.20
2018-03-01 64.94 1322.8 90.15 24103.11
2018-04-01 68.57 1316.2 91.84 24163.15
2018-05-01 67.04 1300.1 93.99 24415.84
2018-06-01 74.15 1251.3 94.63 24271.41
2018-07-01 68.76 1223.7 94.49 25415.19
2018-08-01 69.80 1200.3 95.14 25964.82
2018-09-01 73.25 1191.5 95.19 26458.31
2018-10-01 65.31 1212.3 97.13 25115.76
2018-11-01 50.93 1220.2 97.27 25538.46
2018-12-01 45.41 1278.3 96.17 23327.46
2019-01-01 53.79 1319.7 95.58 24999.67
2019-02-01 57.22 1312.8 96.16 25916.00
2019-03-01 60.14 1293.0 97.28 25928.68
2019-04-01 63.91 1282.8 97.48 26592.91
2019-05-01 53.50 1305.8 97.75 24815.04
2019-06-01 58.47 1409.7 96.13 26599.96
2019-07-01 58.58 1426.1 98.52 26864.27
2019-08-01 55.10 1519.1 98.92 26403.28
2019-09-01 54.07 1465.7 99.38 26916.83
2019-10-01 54.18 1511.4 97.35 27046.23
2019-11-01 55.17 1465.6 98.27 28051.41
2019-12-01 61.06 1519.5 96.39 28538.44
2020-01-01 51.56 1582.9 97.39 28256.03
2020-02-01 44.76 1564.1 98.13 25409.36
2020-03-01 20.48 1583.4 99.05 21917.16
2020-04-01 18.84 1684.2 99.02 24345.72
2020-05-01 35.49 1736.9 98.34 25383.11
2020-06-01 39.27 1793.0 97.39 25812.88
2020-07-01 40.27 1962.8 93.49 26428.32
2020-08-01 42.61 1967.6 92.14 28430.05
2020-09-01 40.22 1887.5 93.89 27781.70
2020-10-01 35.79 1877.4 94.04 26501.60
2020-11-01 45.34 1775.7 91.87 29638.64
2020-12-01 48.52 1893.1 89.94 30606.48
2021-01-01 52.20 1847.3 90.58 29982.62
2021-02-01 61.50 1728.1 90.93 30932.37
2021-03-01 59.16 1713.8 93.23 32981.55
2021-04-01 63.58 1767.3 91.28 33874.85
2021-05-01 66.32 1902.5 90.03 34529.45
2021-06-01 73.47 1770.8 92.44 34502.51
2021-07-01 73.95 1812.6 92.17 34935.47
2021-08-01 68.50 1815.0 92.63 35360.73
2021-09-01 75.03 1755.3 94.25 33843.92
2021-10-01 83.57 1783.0 94.12 35819.56
2021-11-01 66.18 1773.6 95.99 34483.72
2021-12-01 75.21 1827.5 95.67 36338.30
2022-01-01 88.15 1795.0 96.54 35131.86
2022-02-01 95.72 1899.4 96.71 33892.60
2022-03-01 100.28 1949.2 98.31 34678.35
2022-04-01 104.69 1909.3 102.96 32977.21
2022-05-01 114.67 1842.7 101.75 32990.12
2022-06-01 105.76 1804.1 104.69 30775.43
2022-07-01 98.62 1762.9 105.90 32845.13
2022-08-01 89.55 1712.8 108.70 31510.43
2022-09-01 79.49 1662.4 112.12 28725.51
2022-10-01 86.53 1635.9 111.53 32732.95
2022-11-01 80.55 1746.0 105.95 34589.77
2022-12-01 80.26 1819.7 103.52 33147.25
2023-01-01 78.87 1929.5 102.10 34086.04
2023-02-01 77.05 1828.9 104.87 32656.70
2023-03-01 75.67 1969.0 102.51 33274.15
2023-04-01 76.78 1990.1 101.67 34098.16
2023-05-01 68.09 1963.9 104.32 32908.27

MODEL 1:

Log(stock) = β1 + β2log(oil) + β3log(gold) + β4log(US dollar) + ϵ1

lm_stock <- lm(log(DJI) ~ log(USOIL) + log(GOLD) + log(DOLLAR), data = prices_monthly)
summary(lm_stock)
## 
## Call:
## lm(formula = log(DJI) ~ log(USOIL) + log(GOLD) + log(DOLLAR), 
##     data = prices_monthly)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.3709 -0.1538 -0.0175  0.1401  0.3596 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -8.28334    1.06743  -7.760 1.39e-12 ***
## log(USOIL)   0.09809    0.05331   1.840   0.0678 .  
## log(GOLD)    0.69012    0.08971   7.693 2.02e-12 ***
## log(DOLLAR)  2.83343    0.18475  15.337  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1819 on 145 degrees of freedom
## Multiple R-squared:  0.7226, Adjusted R-squared:  0.7168 
## F-statistic: 125.9 on 3 and 145 DF,  p-value: < 2.2e-16

The regression results for equation (5) is illustrated in Table 1, the regression analysis reveals valuable insights into the relationship between the stock market and the independent variables: oil prices, gold prices, and the US dollar index. The intercept term indicates that the expected stock market value is projected to be negative when all independent variables are set to zero, suggesting a potential downturn. At a 95% confidence level, the model shows that a 1% increase in oil prices leads to a modest increase in the stock market. A 1% increase in gold prices is associated with a significant increase in the stock market. The US dollar index demonstrates a substantial impact, with a 1% increase leading to a notable increase in the stock market. These effects are statistically significant. Overall, the regression model highlights the positive influences of oil prices, gold prices, and the US dollar index on the stock market, providing valuable insights for understanding stock market dynamics.

MODEL 2:

Log(oil) = α1 + α2log(stock) + α3log(gold) + α4log(US dollar) + ϵ2

lm_oil <- lm(log(USOIL) ~ log(DJI) + log(GOLD) + log(DOLLAR), data = prices_monthly)
summary(lm_oil)
## 
## Call:
## lm(formula = log(USOIL) ~ log(DJI) + log(GOLD) + log(DOLLAR), 
##     data = prices_monthly)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.13008 -0.10884  0.02032  0.15843  0.66489 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  11.4252     1.7100   6.682 4.72e-10 ***
## log(DJI)      0.2326     0.1264   1.840   0.0678 .  
## log(GOLD)     0.3135     0.1619   1.937   0.0547 .  
## log(DOLLAR)  -2.6195     0.4061  -6.451 1.56e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2801 on 145 degrees of freedom
## Multiple R-squared:  0.3905, Adjusted R-squared:  0.3779 
## F-statistic: 30.97 on 3 and 145 DF,  p-value: 1.56e-15

On the other hands, the lm_oil model examines the relationship between oil prices and the independent variables (DOLLAR, GOLD, and DXY) in a similar manner to the lm_stock model. However, the coefficients and significance levels differ between the two models. In lm_oil, the coefficient for DJI is not statistically significant (p-value = 0.0678), while the coefficients for GOLD and DOLLAR show a potential significance (p-values = 0.0547 and 1.56e-09, respectively). The adjusted R-squared for lm_oil indicates that approximately 37.79% of the variation in oil prices can be explained by the independent variables. Comparing the two models, lm_stock and lm_oil, we find that the relationship between the independent variables and the dependent variable differs. In lm_stock, the US dollar index (DOLLAR) has a significant positive effect on stock prices, while in lm_oil, DOLLAR has a significant negative effect on oil prices. Additionally, the coefficient for GOLD is significant and positive in both models, suggesting that an increase in gold prices leads to an increase in both stock prices and oil prices.

MODEL 3:

Log(gold) = δ1 + δ2log(oil) + δ3log(stock) + δ4log(US dollar) + ϵ3

lm_gold <- lm(log(GOLD) ~ log(USOIL) + log(DJI) + log(DOLLAR), data = prices_monthly)
summary(lm_gold)
## 
## Call:
## lm(formula = log(GOLD) ~ log(USOIL) + log(DJI) + log(DOLLAR), 
##     data = prices_monthly)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.269306 -0.120284 -0.007545  0.115243  0.261009 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.14278    0.79343   9.002 1.14e-15 ***
## log(USOIL)   0.08046    0.04154   1.937   0.0547 .  
## log(DJI)     0.41999    0.05459   7.693 2.02e-12 ***
## log(DOLLAR) -0.96860    0.21908  -4.421 1.91e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1419 on 145 degrees of freedom
## Multiple R-squared:  0.3491, Adjusted R-squared:  0.3356 
## F-statistic: 25.92 on 3 and 145 DF,  p-value: 1.741e-13

In equation (7), the positive constant term suggests that the economy was moving along a stable path, and the estimated value of gold price in the absence of the independent variables is 15.720. Analyzing the coefficients of lm_gold, we find that a 1% increase in oil price leads to a 0.28% decrease in gold price, indicating an inverse relationship between the two variables. On the other hand, a 1% increase in stock prices is associated with a 0.041% increase in gold price, suggesting a positive relationship. Additionally, a 1% increase in the US dollar leads to a 2.53% decrease in oil price. These effects are statistically significant as indicated by the p-values of the t-tests, which are less than 5%. The lm_gold model examines the relationship between gold prices and the independent variables (USOIL, DJI, and DOLLAR). The adjusted R-squared of 0.3356 indicates that around 33.56% of the variation in gold prices can be explained by the independent variables. Overall, this regression model provides insights into the effects of oil prices, stock prices, and the US dollar on gold prices. It suggests that changes in these variables have significant impacts on the price of gold, with oil prices and the US dollar exerting opposite effects, while stock prices have a positive influence.

MODEL 4:

Log(US dollar) = γ1 + γ2log(oil) + γ3log(stock) + γ4log(gold) + ϵ4

lm_usdollar <- lm(log(DOLLAR) ~ log(USOIL) + log(GOLD) + log(DJI), data = prices_monthly)
summary(lm_usdollar)
## 
## Call:
## lm(formula = log(DOLLAR) ~ log(USOIL) + log(GOLD) + log(DJI), 
##     data = prices_monthly)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.092979 -0.035713 -0.005687  0.035029  0.167378 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.59284    0.18772  19.139  < 2e-16 ***
## log(USOIL)  -0.08512    0.01320  -6.451 1.56e-09 ***
## log(GOLD)   -0.12264    0.02774  -4.421 1.91e-05 ***
## log(DJI)     0.21834    0.01424  15.337  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.05048 on 145 degrees of freedom
## Multiple R-squared:  0.7465, Adjusted R-squared:  0.7413 
## F-statistic: 142.4 on 3 and 145 DF,  p-value: < 2.2e-16

The lm_usdollar model explores the relationship between the US dollar (DOLLAR) and the independent variables (USOIL, GOLD, and DJI). The regression analysis reveals the following: The constant term in equation (8) is 3.59284, indicating that the expected value of the US dollar is 3.59284 when all the independent variables are set to zero. Analyzing the coefficients, we find that a 1% increase in oil prices (USOIL) is associated with an estimated 0.08512% decrease in the US dollar. Similarly, a 1% increase in gold prices (GOLD) leads to a 0.12264% decrease in the US dollar. Conversely, a 1% increase in stock prices (DJI) is associated with a 0.21834% increase in the US dollar. These effects are statistically significant, as denoted by the p-values of the t-tests, which are less than 5%. The adjusted R-squared of 0.7413 indicates that approximately 74.13% of the variation in the US dollar can be explained by the independent variables. In summary, the lm_usdollar model provides insights into the relationships between the US dollar and the variables of interest. It suggests that changes in oil prices, gold prices, and stock prices have significant impacts on the value of the US dollar, with oil and gold prices exerting a negative influence and stock prices having a positive effect.