Get USDEUR data and chart
With this template, you can get data from USD EUR ticker available in Yahoo finance.
Tags: #yahoofinance #trading #plotly #naas_drivers
Author: Carlo Occhiena

Input

Import libraries

1
from naas_drivers import yahoofinance, plotly
Copied!

Input parameters

👉 Here you can change the ticker, timeframe and add moving averages analysiss
1
ticker = "EURUSD=X"
2
date_from = -365
3
date_to = "today"
4
interval = '1d'
5
moving_averages = [20, 50]
Copied!

Model

Get dataset from Yahoo Finance

1
df_yahoo = yahoofinance.get(ticker,
2
date_from=date_from,
3
date_to=date_to,
4
interval=interval,
5
moving_averages=moving_averages)
6
df_yahoo
Copied!

Output

Display chart

1
# Get last value
2
last_date = df_yahoo.loc[df_yahoo.index[-1], "Date"].strftime("%Y-%m-%d")
3
last_value = df_yahoo.loc[df_yahoo.index[-1], "Close"]
4
5
# Create chart
6
chart = plotly.linechart(df_yahoo,
7
x="Date",
8
y=["Close", "MA20", "MA50"],
9
showlegend=True,
10
title=f"<b>{ticker} rate as of {last_date}</b><br><span style='font-size: 13px;'>Last value: {last_value}</span>")
11
12
chart.update_layout(
13
title_font=dict(family="Arial", size=18, color="black"),
14
legend_font=dict(family="Arial", size=11, color="black"),
15
margin_pad=10,
16
)
Copied!
Copy link
Edit on GitHub