def test_get_one_fund(self): tspdata = tsp.TSPReader(start="2015-11-2", end="2015-11-2", symbols=("I Fund", )).read() assert len(tspdata) == 1 assert tspdata.columns.values.tolist() == ["I Fund"]
def fetch(self): import pandas_datareader as pdr import pandas_datareader.data as web from pandas_datareader import wb #self.prog_bar.pb_start() self.applyOptions() source = self.kwds['source'] dataset = self.kwds['dataset'] url = self.kwds['url'] st = self.kwds['start'] e = self.kwds['end'] dateformat = self.kwds['dateformat'] start = pd.to_datetime(st, format=dateformat, errors='ignore') end = pd.to_datetime(e, format=dateformat, errors='ignore') if url != '': df = self.fetch_url(url) if df is None: return label = os.path.basename(url) self.parent.load_dataframe(df, label, True) return if source == 'Yahoo Finance': df = web.DataReader("F", 'yahoo', start, end) elif source == 'Google Finance': df = web.DataReader("F", 'google', start, end) elif source == 'FRED': df = web.DataReader("GDP", "fred", start, end) elif source == 'OECD': df = web.DataReader('UN_DEN', 'oecd', end=end) elif source == 'World Bank': df = wb.download(indicator='NY.GDP.PCAP.KD', country=['US', 'CA', 'MX'], start=2005, end=2008) elif source == 'Eurostat': df = web.DataReader("tran_sf_railac", 'eurostat') elif source == 'TSP': import pandas_datareader.tsp as tsp tspreader = tsp.TSPReader(start=start, end=end) df = tspreader.read() elif source == 'FAMA/French': ds = web.DataReader(dataset, "famafrench") df = ds[0] label = source + '_' + dataset df = df.reset_index() self.parent.load_dataframe(df, label, True) #self.prog_bar.pb_stop() return
def test_get_allfunds(self): tspdata = tsp.TSPReader(start='2015-11-2', end='2015-11-2').read() assert len(tspdata == 1) assert round(tspdata['I Fund'][dt.date(2015, 11, 2)], 5) == 25.0058
def test_get_allfunds(self): tspdata = tsp.TSPReader(start="2015-11-2", end="2015-11-2").read() assert len(tspdata) == 1 assert round(tspdata["I Fund"][dt.datetime(2015, 11, 2)], 5) == 25.0058
end = datetime(2018, 1, 1) gdp = web.DataReader('GDP', 'fred', start, end) #crea la columna growth con los calculos gdp['growth'] = gdp['GDP'] - gdp['GDP'].shift(1) print(gdp) #---------------------------------------------------------------------------------------------------------------- import pandas_datareader.tsp as tsp from datetime import datetime start = datetime(2009, 1, 1) end = datetime(2019, 1, 1) tsp_data = tsp.TSPReader(start,end).read() print(tsp_data) #prints the variance of the values print(tsp_data.var()) #prints the covariance of the values #describes the relationship between the returns on two different investments over a period of time, #and can be used to help balance a portfolio. print(tsp_data.cov()) # Python is able to import financial data from csv files as well as public financial APIs. # The pandas read_csv function can be used to import data from a csv file into a pandas dataframe. # Pandas-datareader makes it easy to import data from public financial APIs. # Python’s datetime function can be used to create datetime objects which are often used to specify time ranges for financial data. # API keys are unique identifiers required for some APIs in order to access data. # Sometimes APIs can be flaky. To mitigate the damage this might cause it’s best to test your code often and keep up to date with the pandas-datareader documentation and GitHub page.