Skip to content

Feature/av forex daily #764

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

Merged
merged 5 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/source/remote_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Historical Time Series Data

Through the
`Alpha Vantage <https://www.alphavantage.co/documentation>`__ Time Series
endpoints, it is possible to obtain historical equities data for individual
endpoints, it is possible to obtain historical equities and currency rate data for individual
symbols. For daily, weekly, and monthly frequencies, 20+ years of historical data is available. The past 3-5 days of intraday data is also available.

The following endpoints are available:
Expand All @@ -151,6 +151,7 @@ The following endpoints are available:
* ``av-weekly-adjusted`` - Weekly Time Series (Adjusted)
* ``av-monthly`` - Monthly Time Series
* ``av-monthly-adjusted`` - Monthly Time Series (Adjusted)
* ``av-forex-daily`` - Daily Time Series

.. code-block:: ipython

Expand All @@ -173,6 +174,8 @@ The following endpoints are available:
volume 2.834990e+07
Name: 2017-02-09, dtype: float64

To request the historical exchange rate of physical or digital currencies, use
``av-forex-daily`` and format the symbol as "FROM/TO", for example "USD/JPY".

The top-level function ``get_data_alphavantage`` is also provided. This
function will
Expand Down
2 changes: 2 additions & 0 deletions docs/source/whatsnew/v0.9.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Highlights include:
Enhancements
~~~~~~~~~~~~

- Added AlphaVantage endpoint to get historical currency exchange rates.

.. _whatsnew_090.api_breaking:

Expand All @@ -33,3 +34,4 @@ Bug Fixes
Contributors
~~~~~~~~~~~~
- David Stephens
- Matthew Hall
11 changes: 10 additions & 1 deletion pandas_datareader/av/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AVTimeSeriesReader(AlphaVantage):
"TIME_SERIES_MONTHLY": "Monthly Time Series",
"TIME_SERIES_MONTHLY_ADJUSTED": "Monthly Adjusted Time Series",
"TIME_SERIES_INTRADAY": "Time Series (1min)",
"FX_DAILY": "Time Series FX (Daily)",
}

def __init__(
Expand Down Expand Up @@ -77,6 +78,10 @@ def function(self):
def intraday(self):
return True if self.function == "TIME_SERIES_INTRADAY" else False

@property
def forex(self):
return True if self.function == "FX_DAILY" else False

@property
def output_size(self):
""" Used to limit the size of the Alpha Vantage query when
Expand All @@ -92,13 +97,17 @@ def data_key(self):
@property
def params(self):
p = {
"symbol": self.symbols,
"function": self.function,
"apikey": self.api_key,
"outputsize": self.output_size,
}
if self.intraday:
p.update({"interval": "1min"})
if self.forex:
p.update({"from_symbol": self.symbols.split("/")[0]})
p.update({"to_symbol": self.symbols.split("/")[1]})
else:
p.update({"symbol": self.symbols})
return p

def _read_lines(self, out):
Expand Down
13 changes: 13 additions & 0 deletions pandas_datareader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def DataReader(
"yahoo-actions",
"yahoo-dividends",
"av-forex",
"av-forex-daily",
"av-daily",
"av-daily-adjusted",
"av-weekly",
Expand Down Expand Up @@ -567,6 +568,18 @@ def DataReader(
api_key=api_key,
).read()

elif data_source == "av-forex-daily":
return AVTimeSeriesReader(
symbols=name,
function="FX_DAILY",
start=start,
end=end,
retry_count=retry_count,
pause=pause,
session=session,
api_key=api_key,
).read()

elif data_source == "av-daily":
return AVTimeSeriesReader(
symbols=name,
Expand Down
14 changes: 14 additions & 0 deletions pandas_datareader/tests/av/test_av_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,17 @@ def test_av_intraday(self):
assert len(df) > 1000
assert "open" in df.columns
assert "close" in df.columns

def test_av_forex_daily(self):
df = web.DataReader(
"USD/JPY",
"av-forex-daily",
start=self.start,
end=self.end,
retry_count=6,
pause=20.5,
)
assert df.columns.equals(self.col_index[:4]) # No volume col for forex
assert len(df) == 718
assert df.loc["2015-02-09"]["close"] == 118.6390
assert df.loc["2017-05-24"]["high"] == 112.1290
2 changes: 1 addition & 1 deletion pandas_datareader/yahoo/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _read_one_data(self, url, params):
def split_ratio(row):
if float(row["Numerator"]) > 0:
if ":" in row["Splitratio"]:
n, m = row["Splitratio"].split(':')
n, m = row["Splitratio"].split(":")
return float(m) / float(n)
else:
return eval(row["Splitratio"])
Expand Down