Skip to content

Commit 6eec371

Browse files
authored
Merge pull request #764 from matthewhall79/feature/av-forex-daily
Feature/av forex daily
2 parents 2925ebd + c61f394 commit 6eec371

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

docs/source/remote_data.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Historical Time Series Data
139139

140140
Through the
141141
`Alpha Vantage <https://www.alphavantage.co/documentation>`__ Time Series
142-
endpoints, it is possible to obtain historical equities data for individual
142+
endpoints, it is possible to obtain historical equities and currency rate data for individual
143143
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.
144144

145145
The following endpoints are available:
@@ -151,6 +151,7 @@ The following endpoints are available:
151151
* ``av-weekly-adjusted`` - Weekly Time Series (Adjusted)
152152
* ``av-monthly`` - Monthly Time Series
153153
* ``av-monthly-adjusted`` - Monthly Time Series (Adjusted)
154+
* ``av-forex-daily`` - Daily Time Series
154155

155156
.. code-block:: ipython
156157
@@ -173,6 +174,8 @@ The following endpoints are available:
173174
volume 2.834990e+07
174175
Name: 2017-02-09, dtype: float64
175176
177+
To request the historical exchange rate of physical or digital currencies, use
178+
``av-forex-daily`` and format the symbol as "FROM/TO", for example "USD/JPY".
176179

177180
The top-level function ``get_data_alphavantage`` is also provided. This
178181
function will

docs/source/whatsnew/v0.9.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Highlights include:
1616
Enhancements
1717
~~~~~~~~~~~~
1818

19+
- Added AlphaVantage endpoint to get historical currency exchange rates.
1920

2021
.. _whatsnew_090.api_breaking:
2122

@@ -34,3 +35,4 @@ Bug Fixes
3435
Contributors
3536
~~~~~~~~~~~~
3637
- David Stephens
38+
- Matthew Hall

pandas_datareader/av/time_series.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class AVTimeSeriesReader(AlphaVantage):
3939
"TIME_SERIES_MONTHLY": "Monthly Time Series",
4040
"TIME_SERIES_MONTHLY_ADJUSTED": "Monthly Adjusted Time Series",
4141
"TIME_SERIES_INTRADAY": "Time Series (1min)",
42+
"FX_DAILY": "Time Series FX (Daily)",
4243
}
4344

4445
def __init__(
@@ -77,6 +78,10 @@ def function(self):
7778
def intraday(self):
7879
return True if self.function == "TIME_SERIES_INTRADAY" else False
7980

81+
@property
82+
def forex(self):
83+
return True if self.function == "FX_DAILY" else False
84+
8085
@property
8186
def output_size(self):
8287
""" Used to limit the size of the Alpha Vantage query when
@@ -92,13 +97,17 @@ def data_key(self):
9297
@property
9398
def params(self):
9499
p = {
95-
"symbol": self.symbols,
96100
"function": self.function,
97101
"apikey": self.api_key,
98102
"outputsize": self.output_size,
99103
}
100104
if self.intraday:
101105
p.update({"interval": "1min"})
106+
if self.forex:
107+
p.update({"from_symbol": self.symbols.split("/")[0]})
108+
p.update({"to_symbol": self.symbols.split("/")[1]})
109+
else:
110+
p.update({"symbol": self.symbols})
102111
return p
103112

104113
def _read_lines(self, out):

pandas_datareader/data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ def DataReader(
361361
"yahoo-actions",
362362
"yahoo-dividends",
363363
"av-forex",
364+
"av-forex-daily",
364365
"av-daily",
365366
"av-daily-adjusted",
366367
"av-weekly",
@@ -570,6 +571,18 @@ def DataReader(
570571
api_key=api_key,
571572
).read()
572573

574+
elif data_source == "av-forex-daily":
575+
return AVTimeSeriesReader(
576+
symbols=name,
577+
function="FX_DAILY",
578+
start=start,
579+
end=end,
580+
retry_count=retry_count,
581+
pause=pause,
582+
session=session,
583+
api_key=api_key,
584+
).read()
585+
573586
elif data_source == "av-daily":
574587
return AVTimeSeriesReader(
575588
symbols=name,

pandas_datareader/tests/av/test_av_time_series.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,17 @@ def test_av_intraday(self):
194194
assert len(df) > 1000
195195
assert "open" in df.columns
196196
assert "close" in df.columns
197+
198+
def test_av_forex_daily(self):
199+
df = web.DataReader(
200+
"USD/JPY",
201+
"av-forex-daily",
202+
start=self.start,
203+
end=self.end,
204+
retry_count=6,
205+
pause=20.5,
206+
)
207+
assert df.columns.equals(self.col_index[:4]) # No volume col for forex
208+
assert len(df) == 718
209+
assert df.loc["2015-02-09"]["close"] == 118.6390
210+
assert df.loc["2017-05-24"]["high"] == 112.1290

0 commit comments

Comments
 (0)