tickers_input = input("Enter a list of tickers separated by commas: ")
tickers_list = tickers_input.split(",")
tickers_list = [ticker.strip() for ticker in tickers_list]
Enter the start date (YYYY-MM-DD): 2023-01-01
Traceback (most recent call last):
File "/home/schaich/Dokumente/Python/USDCHF.py", line 31, in
rates = exchange_rate(start_date, end_date)
File "/home/schaich/Dokumente/Python/USDCHF.py", line 10, in exchange_rate
rates[date.strftime("%Y-%m-%d")] = cr.get_rate("USD", "CHF", date)
File "/home/schaich/.local/lib/python3.10/site-packages/forex_python/converter.py", line 79, in get_rate
raise RatesNotAvailableError("Currency Rates Source Not Ready")
forex_python.converter.RatesNotAvailableError: Currency Rates Source Not Ready
i have this code:
Import packages
import requests import pandas as pd import matplotlib.pyplot as plt from datetime import datetime
Set the start and end date
start_date = '2023-01-01' end_date = datetime.now().strftime("%Y-%m-%d")
Define the ticker list
tickers_input = input("Enter a list of tickers separated by commas: ") tickers_list = tickers_input.split(",") tickers_list = [ticker.strip() for ticker in tickers_list]
Create placeholder for data
data = pd.DataFrame()
Fetch the data
for ticker in tickers_list: url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={ticker}&apikey=YVPP8PYIMZMED6ZJ" response = requests.get(url) data_json = response.json() if 'Error Message' in data_json: print(f"Failed download: {ticker}") else: data[ticker] = pd.DataFrame.from_dict(data_json['Time Series (Daily)']).T['4. close']
Print first 5 rows of the data
print(data.head(5))
Convert data to numerical
data = data.apply(pd.to_numeric)
Plot all the close prices
data.plot(figsize=(80, 20))
Show the legend
plt.legend()
Define the label for the title of the figure
plt.title(ticker, fontsize=16)
Define the labels for x-axis and y-axis
plt.ylabel('Kurs', fontsize=14) plt.xlabel('Date', fontsize=14)
Plot the grid lines
plt.grid(which="major", color='k', linestyle='-.', linewidth=0.5) plt.show()
and i get this error:
Enter the start date (YYYY-MM-DD): 2023-01-01 Traceback (most recent call last): File "/home/schaich/Dokumente/Python/USDCHF.py", line 31, in
rates = exchange_rate(start_date, end_date)
File "/home/schaich/Dokumente/Python/USDCHF.py", line 10, in exchange_rate
rates[date.strftime("%Y-%m-%d")] = cr.get_rate("USD", "CHF", date)
File "/home/schaich/.local/lib/python3.10/site-packages/forex_python/converter.py", line 79, in get_rate
raise RatesNotAvailableError("Currency Rates Source Not Ready")
forex_python.converter.RatesNotAvailableError: Currency Rates Source Not Ready