import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
import yfinance as yf
import requests
import cufflinks as cf; cf.go_offline()
plt.style.use('fivethirtyeight')
# Define the start and end dates for the data
start_date = '2010-01-01'
# # Retrieve the data
# # Gold Price
data_gold = yf.download('GC=F', start=start_date)
# # TIPS
data_tips = yf.download('TIP', start=start_date)
# # USDollar Index
data_usdindex = yf.download('DX=F', start=start_date)
price_gold = data_gold['Adj Close'].rename('gold')
price_tips = data_tips['Adj Close'].rename('tips')
price_usdindex = data_usdindex['Adj Close'].rename('usdx')
df = pd.concat([price_gold, price_tips, price_usdindex],axis=1)
df_diff = df.diff()
df.to_csv(r'./Data/data_from_yfinance.csv')
[*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed
start_date = '2010-01-01'
df_from_yf = pd.read_csv(r'./Data/data_from_yfinance.csv', index_col='Date', parse_dates=True)
df_from_yf
gold | tips | usdx | |
---|---|---|---|
Date | |||
2010-01-04 | 1117.699951 | 73.639183 | 77.830002 |
2010-01-05 | 1118.099976 | 73.879532 | 77.849998 |
2010-01-06 | 1135.900024 | 73.688652 | 77.654999 |
2010-01-07 | 1133.099976 | 73.801781 | 78.105003 |
2010-01-08 | 1138.199951 | 73.957268 | 77.654999 |
... | ... | ... | ... |
2024-04-16 | 2390.800049 | 105.349998 | 106.065002 |
2024-04-17 | 2371.699951 | 105.760002 | 105.764000 |
2024-04-18 | 2382.300049 | 105.620003 | 105.982002 |
2024-04-19 | 2398.399902 | 105.779999 | 105.984001 |
2024-04-22 | 2382.699951 | NaN | 105.885002 |
3600 rows × 3 columns
df_from_yf.iplot(y='gold', secondary_y = [ 'tips', 'usdx'])
df_from_yf.corr()
gold | tips | usdx | |
---|---|---|---|
gold | 1.000000 | 0.734716 | 0.240488 |
tips | 0.734716 | 1.000000 | 0.616567 |
usdx | 0.240488 | 0.616567 | 1.000000 |
df_from_yf[df_from_yf.index>'2020'].corr()
gold | tips | usdx | |
---|---|---|---|
gold | 1.000000 | 0.072961 | 0.102308 |
tips | 0.072961 | 1.000000 | -0.609331 |
usdx | 0.102308 | -0.609331 | 1.000000 |
df_from_yf[df_from_yf.index > '2020'].iplot(y='gold', secondary_y = [ 'tips', 'usdx'])
df_from_yf[df_from_yf.index>'2023'].corr()
gold | tips | usdx | |
---|---|---|---|
gold | 1.000000 | 0.516854 | 0.000794 |
tips | 0.516854 | 1.000000 | -0.676702 |
usdx | 0.000794 | -0.676702 | 1.000000 |
df_from_yf[df_from_yf.index > '2023'].iplot(y='gold', secondary_y = [ 'tips', 'usdx'])