def __init__(self): self.logger = LoggerManager().getLogger(__name__) self.hist_econ_data_factory = HistEconDataFactory()
""" import datetime from pythalesians.economics.events.histecondatafactory import HistEconDataFactory from pythalesians.economics.events.popular.commonecondatafactory import CommonEconDataFactory from pythalesians.util.loggermanager import LoggerManager # just change "False" to "True" to run any of the below examples #### Plot US economic data by state using a choropleth Plotly plot #### if False: logger = LoggerManager.getLogger(__name__) hist = HistEconDataFactory() start_date = '01 Jan 1990' finish_date = datetime.datetime.utcnow() country_group = 'usa-states' yoy_ret = False # select as appropriate # data_type = 'Total Nonfarm'; title = 'Change in non-farm payrolls (YoY)'; freq = 12 # data_type = 'Real GDP'; title = 'Real GDP'; freq = 1 # data_type = 'Economic Activity Index'; title = 'Economic Activity Index (YoY change %)'; yoy_ret = True; freq = 12 # data_type = 'Total Construction Employees'; title = Total Construction Employees'; freq = 12 data_type = 'Unemployment Rate'; title = 'Unemployment Rate'; freq = 12 # data_type = 'Total Personal Income'; title = 'Total Personal Income'; freq = 12 # data_type = 'House Price Index'; title = 'House Price Index (YoY change %)'; yoy_ret = True; freq = 12; source = 'fred'
class CommonEconDataFactory: def __init__(self): self.logger = LoggerManager().getLogger(__name__) self.hist_econ_data_factory = HistEconDataFactory() def get_econ_data_group(self, start_date, finish_date, country_group, data_type, source): df = self.hist_econ_data_factory.get_economic_data_history( start_date, finish_date, country_group, data_type, source=source) df = df.fillna(method='pad') return df def get_GDP_QoQ(self, start_date, finish_date, country_group, source='bloomberg'): return self.get_econ_data_group(start_date, finish_date, country_group, 'GDP QoQ (SAAR)', source=source) def get_GDP_QoQ(self, start_date, finish_date, country_group, source='bloomberg'): return self.get_econ_data_group(start_date, finish_date, country_group, 'GDP QoQ (SAAR)', source=source) def get_UNE(self, start_date, finish_date, country_group, source='bloomberg'): return self.get_econ_data_group(start_date, finish_date, country_group, 'Unemployment Rate', source=source) def get_CPI_YoY(self, start_date, finish_date, country_group, source='bloomberg'): return self.get_econ_data_group(start_date, finish_date, country_group, 'CPI YoY', source=source) def usa_plot_une(self, start_date, finish_date): country_group = 'usa-states' source = 'bloomberg' une = self.get_UNE(start_date, finish_date, country_group, source='bloomberg') une = self.hist_econ_data_factory.grasp_coded_entry(une, -1) from chartesians.graphs import PlotFactory from chartesians.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'USA-states' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'usa' gp.plotly_projection = 'albers usa' gp.plotly_world_readable = False gp.plotly_url = country_group + "-unemployment" gp.title = "USA Unemployment" gp.units = 'pc' pf.plot_generic_graph(une, type='choropleth', adapter='plotly', gp=gp) def g10_plot_gdp_cpi_une(self, start_date, finish_date, data_type='cpi'): country_group = 'g10' if data_type == 'cpi': df = self.get_CPI_YoY(start_date, finish_date, country_group) elif data_type == 'gdp': df = self.get_GDP_QoQ(start_date, finish_date, country_group) elif data_type == 'une': df = self.get_UNE(start_date, finish_date, country_group) df = self.hist_econ_data_factory.grasp_coded_entry(df, -1) from chartesians.graphs import PlotFactory from chartesians.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'world' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'world' gp.plotly_projection = 'Mercator' gp.plotly_world_readable = False gp.plotly_url = country_group + "-" + data_type gp.title = "G10 " + data_type gp.units = '%' pf.plot_generic_graph(df, type='choropleth', adapter='plotly', gp=gp) def europe_plot_une(self, start_date, finish_date): country_group = 'all-europe' une = self.get_UNE(start_date, finish_date, country_group) une = self.hist_econ_data_factory.grasp_coded_entry(une, -1) from chartesians.graphs import PlotFactory from chartesians.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'europe' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'europe' gp.plotly_projection = 'Mercator' gp.plotly_world_readable = False gp.plotly_url = country_group + "-unemployment" gp.title = "Europe Unemployment" gp.units = '%' pf.plot_generic_graph(une, type='choropleth', adapter='plotly', gp=gp) def world_plot_cpi(self, start_date, finish_date): country_group = 'world-liquid' cpi = self.get_CPI_YoY(start_date, finish_date, country_group) cpi = self.hist_econ_data_factory.grasp_coded_entry(cpi, -1) from chartesians.graphs import PlotFactory from chartesians.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'world' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'world' gp.plotly_projection = 'Mercator' gp.plotly_world_readable = False gp.plotly_url = str(country_group) + "-cpi" gp.title = "World Liquid CPI YoY" gp.units = '%' pf.plot_generic_graph(cpi, type='choropleth', adapter='plotly', gp=gp) def g10_line_plot_cpi(self, start_date, finish_date): today_root = datetime.date.today().strftime("%Y%m%d") + " " country_group = 'g10-ez' cpi = self.get_CPI_YoY(start_date, finish_date, country_group) from chartesians.graphs import PlotFactory from chartesians.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.title = "G10 CPI YoY" gp.units = '%' gp.scale_factor = Constants.plotfactory_scale_factor gp.file_output = today_root + 'G10 CPI YoY ' + str( gp.scale_factor) + '.png' cpi.columns = [x.split('-')[0] for x in cpi.columns] gp.linewidth_2 = 3 gp.linewidth_2_series = ['United States'] pf.plot_generic_graph(cpi, type='line', adapter='pythalesians', gp=gp) def g10_line_plot_une(self, start_date, finish_date): today_root = datetime.date.today().strftime("%Y%m%d") + " " country_group = 'g10-ez' une = self.get_UNE(start_date, finish_date, country_group) from chartesians.graphs import PlotFactory from chartesians.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.title = "G10 Unemployment Rate (%)" gp.units = '%' gp.scale_factor = Constants.plotfactory_scale_factor gp.file_output = today_root + 'G10 UNE ' + str( gp.scale_factor) + '.png' une.columns = [x.split('-')[0] for x in une.columns] gp.linewidth_2 = 3 gp.linewidth_2_series = ['United States'] pf.plot_generic_graph(une, type='line', adapter='pythalesians', gp=gp) def g10_line_plot_gdp(self, start_date, finish_date): today_root = datetime.date.today().strftime("%Y%m%d") + " " country_group = 'g10-ez' gdp = self.get_GDP_QoQ(start_date, finish_date, country_group) from chartesians.graphs import PlotFactory from chartesians.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.title = "G10 GDP" gp.units = 'Rebased' gp.scale_factor = Constants.plotfactory_scale_factor gp.file_output = today_root + 'G10 UNE ' + str( gp.scale_factor) + '.png' gdp.columns = [x.split('-')[0] for x in gdp.columns] gp.linewidth_2 = 3 gp.linewidth_2_series = ['United Kingdom'] from pythalesians.timeseries.calcs.timeseriescalcs import TimeSeriesCalcs tsc = TimeSeriesCalcs() gdp = gdp / 100 gdp = tsc.create_mult_index_from_prices(gdp) pf.plot_generic_graph(gdp, type='line', adapter='pythalesians', gp=gp)
__author__ = 'saeedamen' from pythalesians.util.loggermanager import LoggerManager from pythalesians.economics.events.histecondatafactory import HistEconDataFactory from pythalesians.economics.events.popular.commonecondatafactory import CommonEconDataFactory import datetime class EconComparison: pass if __name__ == '__main__': logger = LoggerManager.getLogger(__name__) hist = HistEconDataFactory() start_date = '01 Jan 1990' finish_date = datetime.datetime.utcnow()
class CommonEconDataFactory: def __init__(self): self.logger = LoggerManager().getLogger(__name__) self.hist_econ_data_factory = HistEconDataFactory() def get_econ_data_group(self, start_date, finish_date, country_group, data_type, source): df = self.hist_econ_data_factory.get_economic_data_history(start_date, finish_date, country_group, data_type, source = source) df = df.fillna(method='pad') return df def get_GDP_QoQ(self, start_date, finish_date, country_group, source = 'bloomberg'): return self.get_econ_data_group(start_date, finish_date, country_group, 'GDP QoQ (SAAR)', source = source) def get_UNE(self, start_date, finish_date, country_group, source = 'bloomberg'): return self.get_econ_data_group(start_date, finish_date, country_group, 'Unemployment Rate', source = source) def get_CPI_YoY(self, start_date, finish_date, country_group, source = 'bloomberg'): return self.get_econ_data_group(start_date, finish_date, country_group, 'CPI YoY', source = source) def usa_plot_une(self, start_date, finish_date): country_group = 'usa-states'; source = 'bloomberg' une = self.get_UNE(start_date, finish_date, country_group, source = 'bloomberg') une = self.hist_econ_data_factory.grasp_coded_entry(une, -1) from pythalesians.graphics.graphs.plotfactory import PlotFactory from pythalesians.graphics.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'USA-states' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'usa' gp.plotly_projection = 'albers usa' gp.plotly_world_readable = False gp.plotly_url = country_group + "-unemployment" gp.title = "USA Unemployment" gp.units = 'pc' pf.plot_generic_graph(une, type = 'choropleth', adapter = 'plotly', gp = gp) def g10_plot_gdp_cpi_une(self, start_date, finish_date, data_type = 'cpi'): country_group = 'g10' if data_type == 'cpi': df = self.get_CPI_YoY(start_date, finish_date, country_group) elif data_type == 'gdp': df = self.get_GDP_YoY(start_date, finish_date, country_group) elif data_type == 'une': df = self.get_UNE(start_date, finish_date, country_group) df = self.hist_econ_data_factory.grasp_coded_entry(df, -1) from pythalesians.graphics.graphs.plotfactory import PlotFactory from pythalesians.graphics.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'world' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'world' gp.plotly_projection = 'Mercator' gp.plotly_world_readable = False gp.plotly_url = country_group + "-" + data_type gp.title = "G10 " + data_type gp.units = '%' pf.plot_generic_graph(df, type = 'choropleth', adapter = 'plotly', gp = gp) def europe_plot_une(self, start_date, finish_date): country_group = 'all-europe' une = self.get_UNE(start_date, finish_date, country_group) une = self.hist_econ_data_factory.grasp_coded_entry(une, -1) from pythalesians.graphics.graphs.plotfactory import PlotFactory from pythalesians.graphics.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'europe' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'europe' gp.plotly_projection = 'Mercator' gp.plotly_world_readable = False gp.plotly_url = country_group + "-unemployment"; gp.title = "Europe Unemployment" gp.units = '%' pf.plot_generic_graph(une, type = 'choropleth', adapter = 'plotly', gp = gp) def world_plot_cpi(self, start_date, finish_date): country_group = 'world-liquid' cpi = self.get_CPI_YoY(start_date, finish_date, country_group) cpi = self.hist_econ_data_factory.grasp_coded_entry(cpi, -1) from pythalesians.graphics.graphs.plotfactory import PlotFactory from pythalesians.graphics.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.plotly_location_mode = 'world' gp.plotly_choropleth_field = 'Val' gp.plotly_scope = 'world' gp.plotly_projection = 'Mercator' gp.plotly_world_readable = False gp.plotly_url = str(country_group) + "-cpi" gp.title = "World Liquid CPI YoY" gp.units = '%' pf.plot_generic_graph(cpi, type = 'choropleth', adapter = 'plotly', gp = gp) def g10_line_plot_cpi(self, start_date, finish_date): today_root = datetime.date.today().strftime("%Y%m%d") + " " country_group = 'g10-ez' cpi = self.get_CPI_YoY(start_date, finish_date, country_group) from pythalesians.graphics.graphs.plotfactory import PlotFactory from pythalesians.graphics.graphs.graphproperties import GraphProperties gp = GraphProperties() pf = PlotFactory() gp.title = "G10 CPI YoY" gp.units = '%' gp.scale_factor = 3 gp.file_output = today_root + 'G10 CPI YoY ' + str(gp.scale_factor) + '.png' cpi.columns = [x.split('-')[0] for x in cpi.columns] gp.linewidth_2 = 3 gp.linewidth_2_series = ['United States'] pf.plot_generic_graph(cpi, type = 'line', adapter = 'pythalesians', gp = gp)
""" import datetime from pythalesians.economics.events.histecondatafactory import HistEconDataFactory from pythalesians.economics.events.popular.commonecondatafactory import CommonEconDataFactory from pythalesians.util.loggermanager import LoggerManager # just change "False" to "True" to run any of the below examples #### Plot US economic data by state using a choropleth Plotly plot #### if False: logger = LoggerManager.getLogger(__name__) hist = HistEconDataFactory() start_date = '01 Jan 1990' finish_date = datetime.datetime.utcnow() country_group = 'usa-states' yoy_ret = False # select as appropriate # data_type = 'Total Nonfarm'; title = 'Change in non-farm payrolls (YoY)'; freq = 12 # data_type = 'Real GDP'; title = 'Real GDP'; freq = 1 # data_type = 'Economic Activity Index'; title = 'Economic Activity Index (YoY change %)'; yoy_ret = True; freq = 12 # data_type = 'Total Construction Employees'; title = Total Construction Employees'; freq = 12 data_type = 'Unemployment Rate' title = 'Unemployment Rate' freq = 12 # data_type = 'Total Personal Income'; title = 'Total Personal Income'; freq = 12 # data_type = 'House Price Index'; title = 'House Price Index (YoY change %)'; yoy_ret = True; freq = 12;