pip install yfinance
gold=yf.download('GC=F', period = "max", interval = "1mo")
gold=gold['Close']
[*********************100%***********************] 1 of 1 completed
copper=yf.download('HG=F', period = "max", interval = "1mo")
copper=copper['Close']
[*********************100%***********************] 1 of 1 completed
asset = pd.merge(gold, copper, on='Date')
asset=asset.rename(columns={'Close_x': 'gold','Close_y':'copper'})
asset=asset.dropna()
asset=round(asset,3)
asset['copper/gold']=asset['copper']/asset['gold']
asset['copper/gold'].plot(kind='line',color='red')
list_symbol=[
'FCX',
'CCJ',
'UEC',
'UROY',
'FNV',
'WPM',
'GOLD',
'RGLD',
'NEM',
'GROY',
'AQMS',
'RIOT',
'MARA',
'COIN',
'VYGVF',
]
list_assets=[]
for i in list_symbol:
company_data=yf.Ticker(i)
list_assets.append(company_data)
print(list_assets)
[yfinance.Ticker object <FCX>, yfinance.Ticker object <CCJ>, yfinance.Ticker object <UEC>, yfinance.Ticker object <UROY>, yfinance.Ticker object <FNV>, yfinance.Ticker object <WPM>, yfinance.Ticker object <GOLD>, yfinance.Ticker object <RGLD>, yfinance.Ticker object <NEM>, yfinance.Ticker object <GROY>, yfinance.Ticker object <AQMS>, yfinance.Ticker object <RIOT>, yfinance.Ticker object <MARA>, yfinance.Ticker object <COIN>, yfinance.Ticker object <VYGVF>]
print(list_assets)
[yfinance.Ticker object <FCX>, yfinance.Ticker object <CCJ>, yfinance.Ticker object <UEC>, yfinance.Ticker object <UROY>, yfinance.Ticker object <FNV>, yfinance.Ticker object <WPM>, yfinance.Ticker object <GOLD>, yfinance.Ticker object <RGLD>, yfinance.Ticker object <NEM>, yfinance.Ticker object <GROY>, yfinance.Ticker object <AQMS>, yfinance.Ticker object <RIOT>, yfinance.Ticker object <MARA>, yfinance.Ticker object <COIN>, yfinance.Ticker object <VYGVF>]
list_feature=['shortName',
'symbol',
'country',
'sector',
]
feature_shortName=[]
feature_symbol=[]
feature_country=[]
feature_sector=[]
for i in list_assets:
feature_shortName.append(i.info[list_feature[0]])
df_feature_shortName = pd.DataFrame (feature_shortName, columns = ['shortName'])
df_feature_shortName["id"] = df_feature_shortName.index + 1
for i in list_assets:
feature_symbol.append(i.info[list_feature[1]])
df_feature_symbol = pd.DataFrame (feature_symbol, columns = ['symbol'])
df_feature_symbol["id"] = df_feature_symbol.index + 1
for i in list_assets:
feature_country.append(i.info[list_feature[2]])
df_feature_country = pd.DataFrame (feature_country, columns = ['country'])
df_feature_country["id"] = df_feature_country.index + 1
for i in list_assets:
feature_sector.append(i.info[list_feature[3]])
df_feature_sector = pd.DataFrame (feature_sector, columns = ['sector'])
df_feature_sector["id"] = df_feature_sector.index + 1
df_merge=pd.merge(df_feature_shortName, df_feature_symbol)
df_merge=pd.merge(df_merge, df_feature_country)
df_merge=pd.merge(df_merge, df_feature_sector)
display(df_merge)
price_close.plot()
NameError: name 'price_close' is not defined
for i in range(0, len(list_symbol)+1):
price_close=list_assets[i].history(period='max')['Close']
plt.suptitle(list_symbol[i])
price_close.plot()
plt.show()
KeyError: 'Close'
for i in range(0, len(list_symbol)+1):
dividend=list_assets[i].history(period='max')['Dividends']
plt.suptitle(list_symbol[i])
dividend.plot()
plt.show()
KernelInterrupted: Execution interrupted by the Jupyter kernel.
print(list_symbol)
['FCX', 'CCJ', 'UEC', 'UROY', 'FNV', 'GOLD', 'RGLD', 'NEM', 'GROY', 'AQMS', 'RIOT', 'MARA', 'COIN', 'VYGVF', 'WPM']