Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forex usd/CHF exchange rate #129

Open
tino1948 opened this issue Mar 3, 2023 · 0 comments
Open

Forex usd/CHF exchange rate #129

tino1948 opened this issue Mar 3, 2023 · 0 comments

Comments

@tino1948
Copy link

tino1948 commented Mar 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant