Skip to content

Commit 54faf4f

Browse files
authored
Merge pull request #808 from e2thenegpii/master
Support new TSP funds in 2020
2 parents 3ef1b30 + 7bdd08c commit 54faf4f

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

docs/source/whatsnew/v0.9.0.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Backwards incompatible API changes
3030
- Removed Robinhood which no longer exists
3131
- Immediately deprecated AlphaVantage quote reader which used an end point that has been retired
3232
- Immediately deprecated Enigma which has substantially changed their business model and API
33+
- Immediately deprecated old symbol names for TSP to reflect the new website API
3334

3435
.. _whatsnew_090.bug_fixes:
3536

@@ -42,6 +43,7 @@ Bug Fixes
4243
- Correct NASDAQ symbols fields link (:issue:`715`)
4344
- Fix Yahoo! actions bug due to change in split format (:issue:`755`)
4445
- Fix FutureWarning from pandas import (:issue:`762`)
46+
- Update TSP web scraper to new site (:issue:`740`)
4547

4648
Contributors
4749
~~~~~~~~~~~~
@@ -56,4 +58,4 @@ Contributors
5658
- Gábor Lipták
5759
- Kevin Sheppard
5860
- David Stephens
59-
61+
- Eldon Allred

pandas_datareader/tests/test_tsp.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ class TestTSPFunds(object):
1111
def test_get_allfunds(self):
1212
tspdata = tsp.TSPReader(start="2015-11-2", end="2015-11-2").read()
1313

14-
assert len(tspdata == 1)
14+
assert len(tspdata) == 1
1515

1616
assert round(tspdata["I Fund"][dt.datetime(2015, 11, 2)], 5) == 25.0058
1717

18+
def test_get_one_fund(self):
19+
tspdata = tsp.TSPReader(
20+
start="2015-11-2", end="2015-11-2", symbols=("I Fund",)
21+
).read()
22+
23+
assert len(tspdata) == 1
24+
25+
assert tspdata.columns.values.tolist() == ["I Fund"]
26+
1827
def test_sanitize_response(self):
1928
class response(object):
2029
pass

pandas_datareader/tsp.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,29 @@ class TSPReader(_BaseReader):
2727
requests.sessions.Session instance to be used
2828
"""
2929

30+
all_symbols = frozenset(
31+
(
32+
"L Income",
33+
"L 2025",
34+
"L 2030",
35+
"L 2035",
36+
"L 2040",
37+
"L 2045",
38+
"L 2050",
39+
"L 2055",
40+
"L 2060",
41+
"L 2065",
42+
"G Fund",
43+
"F Fund",
44+
"C Fund",
45+
"S Fund",
46+
"I Fund",
47+
)
48+
)
49+
3050
def __init__(
3151
self,
32-
symbols=("Linc", "L2020", "L2030", "L2040", "L2050", "G", "F", "C", "S", "I"),
52+
symbols=all_symbols,
3353
start=None,
3454
end=None,
3555
retry_count=3,
@@ -49,22 +69,24 @@ def __init__(
4969
@property
5070
def url(self):
5171
"""API URL"""
52-
return "https://www.tsp.gov/InvestmentFunds/FundPerformance/index.html"
72+
return "https://secure.tsp.gov/components/CORS/getSharePricesRaw.html"
5373

5474
def read(self):
5575
""" read one data from specified URL """
5676
df = super(TSPReader, self).read()
5777
df.columns = map(lambda x: x.strip(), df.columns)
78+
df.drop(columns=self.all_symbols - set(self.symbols), inplace=True)
5879
return df
5980

6081
@property
6182
def params(self):
6283
"""Parameters to use in API calls"""
6384
return {
64-
"startdate": self.start.strftime("%m/%d/%Y"),
65-
"enddate": self.end.strftime("%m/%d/%Y"),
66-
"fundgroup": self.symbols,
67-
"whichButton": "CSV",
85+
"startdate": self.start.strftime("%Y%m%d"),
86+
"enddate": self.end.strftime("%Y%m%d"),
87+
"download": "0",
88+
"Lfunds": "1",
89+
"InvFunds": "1",
6890
}
6991

7092
@staticmethod

0 commit comments

Comments
 (0)