def get_factors(startDate: str = start_date): dataset_names = famafrench.get_available_datasets() print("Getting Fama French 3 factors") factors = famafrench.FamaFrenchReader("F-F_Research_Data_Factors", start=startDate) ff3factors: DataFrame = factors.read()[0] print("Getting Fama French momentum factor") momentum = famafrench.FamaFrenchReader("F-F_Momentum_Factor", start=startDate) momfactors: DataFrame = momentum.read()[0] together = concat([ff3factors, momfactors], axis=1) return together
def printThreeFactorDataList(self): """ Obtains the list of datasets from Kenneth French data library related to the 3 factor model. http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html (Kenneth French data library) """ ffData = get_available_datasets() self.ff3DataList = [ dataset for dataset in ffData if '3_Factors' in dataset ] for i in range(0, len(self.ff3DataList)): print(i, '.', self.ff3DataList[i])
def Data_FF_search(term,all_info=False): ''' Search specific Summary of sets available to download using DataReader_FF function ''' from pandas_datareader.famafrench import get_available_datasets import pandas_datareader.data as web import numpy as np import pandas as pd sets = np.array(get_available_datasets()) if all_info!=False: data = sets else: b_idx = np.array([x.find(term)!=-1 for x in sets]) data = sets[b_idx] return data
def update(self, evt=None): """Update data widget(s)""" datasets = [] self.applyOptions() source = self.kwds['source'] x = ['F'] if source == 'Yahoo Finance': x = ['F'] elif source == 'FAMA/French': from pandas_datareader.famafrench import get_available_datasets x = get_available_datasets() w = self.widgets['dataset'] w['values'] = x w.set(x[0]) return
#create a performance chart and save for later portfolio_index = (1 + Combined_Portfolio_returns).cumprod() ax = portfolio_index.plot(title='In Sample ' + str(test_sector) + ' performance') fig = ax.get_figure() Sector_Performance_Chart = 'In Sample Performance Chart ' + test_sector path_to_file = ( r'/Users/downey/coding/Python/Scripts/EPAT Project RF Models, Code,' ' and Results/Sector Performance/') output_name = path_to_file + Sector_Performance_Chart + '.pdf' fig.savefig(output_name) ####################get risk free rate from kenneth french##################### len(get_available_datasets()) ds = web.DataReader( 'F-F_Research_Data_Factors_daily', 'famafrench', start='1990-08-30', ) print(ds['DESCR']) ds[0].head() data = ds[0] data = data.dropna() data = data / 100 #convert to percent returns RF_data = (1 + data['RF']).cumprod()
def test_get_available_datasets(self): # _skip_if_no_lxml() l = get_available_datasets() assert len(l) > 100
#pip install pandas-datareader (in case you haven't install this package) from pandas_datareader.famafrench import get_available_datasets import pickleshare import pandas as pd from pandas.core.frame import DataFrame import numpy as np import datetime as dt import psycopg2 import matplotlib.pyplot as plt from dateutil.relativedelta import * from pandas.tseries.offsets import * from scipy import stats from matplotlib.backends.backend_pdf import PdfPages #You can extract all the available datasets from Ken French's website and find that there are 295 of them. We can opt to see all the datasets available. datasets = get_available_datasets() print('No. of datasets:{}'.format(len(datasets))) #datasets # comment out if you want to see all the datasets ############## #Customize your data selection ############## #Note:If this is what you are intended to find: '6_Portfolios_ME_OP_2x3', but don't know exactly what it is named, do the following line #df_me_op_factor = [dataset for dataset in datasets if 'ME' in dataset and 'OP' in dataset and '2x3' in dataset] #print(df_me_op_factor) #It is important to check the description of the dataset we access by using the following codes Datatoread='F-F_Research_Data_5_Factors_2x3_daily' sdate='1992-07-01' edate='2018-06-30'
def test_get_available_datasets(self): pytest.importorskip("lxml") l = get_available_datasets() assert len(l) > 100
def test_get_available_datasets(self): _skip_if_no_lxml() l = get_available_datasets() assert len(l) > 100
def fama_french(): from pandas_datareader.famafrench import get_available_datasets get_available_datasets() ds = web.DataReader('5_Industry_Portfolios', 'famafrench') print(ds['DESCR'])
# pprint(os.environ) # FRED start = datetime(2010, 1, 1) end = datetime(2013, 1, 27) gdp = web.DataReader('GDP', 'fred', start, end) print(gdp.info()) inflation = web.DataReader(['CPIAUCSL', 'CPILFESL'], 'fred', start, end) print(inflation.info()) # Fama/French from pandas_datareader.famafrench import get_available_datasets print(get_available_datasets()) ds = web.DataReader('5_Industry_Portfolios', 'famafrench') print(ds['DESCR']) # World Bank from pandas_datareader import wb gdp_variables = wb.search('gdp.*capita.*const') gdp_variables.head() wb_data = wb.download(indicator='NY.GDP.PCAP.KD', country=['US', 'CA', 'MX'], start=1990, end=2019)