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 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 pythalesians.graphics.graphs.plotfactory import PlotFactory
        from pythalesians.graphics.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)
Esempio n. 3
0
    def plot_strategy_signals(self, date=None, strip=None):

        ######## plot signals
        strategy_signal = self._strategy_signal
        strategy_signal = 100 * (strategy_signal)

        if date is None:
            last_day = strategy_signal.ix[-1].transpose().to_frame()
        else:
            last_day = strategy_signal.ix[date].transpose().to_frame()

        if strip is not None:
            last_day.index = [x.replace(strip, '') for x in last_day.index]

        print(last_day)

        pf = PlotFactory()
        gp = GraphProperties()

        gp.title = self.FINAL_STRATEGY + " positions (% portfolio notional)"
        gp.scale_factor = self.SCALE_FACTOR
        gp.file_output = self.DUMP_PATH + self.FINAL_STRATEGY + ' (Positions) ' + str(
            gp.scale_factor) + '.png'

        pf.plot_generic_graph(last_day,
                              adapter='pythalesians',
                              type='bar',
                              gp=gp)
    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_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 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 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)
    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 pythalesians.graphics.graphs.plotfactory import PlotFactory
        from pythalesians.graphics.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_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 pythalesians.graphics.graphs.plotfactory import PlotFactory
        from pythalesians.graphics.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)
Esempio n. 9
0
    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)
    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 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 plot_strategy_signals(self, date = None, strip = None):

        ######## plot signals
        strategy_signal = self._strategy_signal
        strategy_signal = 100 * (strategy_signal)

        if date is None:
            last_day = strategy_signal.ix[-1].transpose().to_frame()
        else:
            last_day = strategy_signal.ix[date].transpose().to_frame()

        if strip is not None:
            last_day.index = [x.replace(strip, '') for x in last_day.index]

        print(last_day)

        pf = PlotFactory()
        gp = GraphProperties()

        gp.title = self.FINAL_STRATEGY + " positions (% portfolio notional)"
        gp.scale_factor = self.SCALE_FACTOR
        gp.file_output = self.DUMP_PATH + self.FINAL_STRATEGY + ' (Positions) ' + str(gp.scale_factor) + '.png'

        pf.plot_generic_graph(last_day, adapter = 'pythalesians', type = 'bar', gp = gp)
Esempio n. 13
0
    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)
Esempio n. 14
0
    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 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 pythalesians.graphics.graphs.plotfactory import PlotFactory
        from pythalesians.graphics.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)
    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)
Esempio n. 17
0
    df = tsc.create_mult_index_from_prices(
        ltsf.harvest_time_series(time_series_request))

    gp = GraphProperties()
    gp.title = "S&P500 vs Apple"

    # plot first with PyThalesians and then Plotly (via Cufflinks)
    # just needs 1 word to change
    # (although, note that AdapterCufflinks does have some extra parameters that can be set in
    # GraphProperties)
    gp.plotly_username = '******'
    gp.plotly_world_readable = True

    pf = PlotFactory()
    pf.plot_generic_graph(df, type='line', adapter='pythalesians', gp=gp)
    pf.plot_generic_graph(df, type='line', adapter='cufflinks', gp=gp)

# test simple Plotly bar charts - average differences in EURUSDV1M-1Y vol and USDJPYV1M-1Y slope over past sixth months
if True:
    from datetime import timedelta
    ltsf = LightTimeSeriesFactory()

    end = datetime.datetime.utcnow()
    start = end - timedelta(days=180)

    tickers = ['EURUSDV1M', 'EURUSDV1Y', 'USDJPYV1M', 'USDJPYV1Y']
    vendor_tickers = [
        'EURUSDV1M BGN Curncy', 'EURUSDV1Y BGN Curncy', 'USDJPYV1M BGN Curncy',
        'USDJPYV1Y BGN Curncy'
    ]
Esempio n. 18
0
    ltsf = LightTimeSeriesFactory()
    tsc = TimeSeriesCalcs()

    df = tsc.create_mult_index_from_prices(ltsf.harvest_time_series(time_series_request))

    gp = GraphProperties()
    gp.html_file_output = "output_data/apple.htm"
    gp.title = "S&P500 vs Apple"

    # plot first with PyThalesians and then Bokeh
    # just needs 1 word to change
    gp.display_legend = False

    pf = PlotFactory()
    pf.plot_generic_graph(df, type = 'line', adapter = 'pythalesians', gp = gp)
    pf.plot_generic_graph(df, type = 'line', adapter = 'bokeh', gp = gp)

# test simple Bokeh bar charts - monthly returns over past 6 months
if True:
    from datetime import timedelta
    ltsf = LightTimeSeriesFactory()

    end = datetime.datetime.utcnow()
    start = end - timedelta(days=180)

    tickers = ['S&P500', 'FTSE', 'Nikkei']
    vendor_tickers = ['SPX Index', 'UKX Index', 'NKY Index']

    time_series_request = TimeSeriesRequest(
        start_date = start,                             # start date
Esempio n. 19
0
            cache_algo='internet_load_return')  # how to return data

        daily_vals = ltsf.harvest_time_series(time_series_request)

        # plot data
        gp = GraphProperties()
        pf = PlotFactory()

        gp.title = 'Spot values'
        gp.file_output = 'output_data/demo.png'
        gp.scale_factor = 2
        gp.style_sheet = 'pythalesians'

        # first use PyThalesians matplotlib wrapper
        pf.plot_line_graph(daily_vals, adapter='pythalesians', gp=gp)
        pf.plot_generic_graph(daily_vals, gp=gp, type='line')

        # use modified 538 Matplotlib stylesheet
        gp.style_sheet = '538-pythalesians'
        pf.plot_line_graph(daily_vals, adapter='pythalesians', gp=gp)

        # use miletus matplotlib stylesheet
        gp.style_sheet = 'miletus-pythalesians'
        pf.plot_line_graph(daily_vals, adapter='pythalesians', gp=gp)

        # use ggplot matplotlib styleheet
        gp.scale_factor = 1
        gp.display_brand_label = False
        gp.display_source = False
        gp.style_sheet = 'ggplot-pythalesians'
        gp.display_mpld3 = True
Esempio n. 20
0
    ltsf = LightTimeSeriesFactory()
    tsc = TimeSeriesCalcs()

    df = tsc.create_mult_index_from_prices(ltsf.harvest_time_series(time_series_request))

    gp = GraphProperties()
    gp.html_file_output = "output_data/apple.htm"
    gp.title = "S&P500 vs Apple"

    # plot first with PyThalesians and then Bokeh
    # just needs 1 word to change
    gp.display_legend = False

    pf = PlotFactory()
    pf.plot_generic_graph(df, type="line", adapter="pythalesians", gp=gp)
    pf.plot_generic_graph(df, type="line", adapter="bokeh", gp=gp)

# test simple Bokeh bar charts - monthly returns over past 6 months
if True:
    from datetime import timedelta

    ltsf = LightTimeSeriesFactory()

    end = datetime.datetime.utcnow()
    start = end - timedelta(days=180)

    tickers = ["S&P500", "FTSE", "Nikkei"]
    vendor_tickers = ["SPX Index", "UKX Index", "NKY Index"]

    time_series_request = TimeSeriesRequest(
                cache_algo = 'internet_load_return')                # how to return data

        daily_vals = ltsf.harvest_time_series(time_series_request)

        # plot data
        gp = GraphProperties()
        pf = PlotFactory()

        gp.title = 'Spot values'
        gp.file_output = 'demo.png'
        gp.scale_factor = 2
        gp.style_sheet = 'pythalesians'

        # first use PyThalesians matplotlib wrapper
        pf.plot_line_graph(daily_vals, adapter = 'pythalesians', gp = gp)
        pf.plot_generic_graph(daily_vals, gp = gp, type = 'line')

        # use modified 538 Matplotlib stylesheet
        gp.style_sheet = '538-pythalesians'
        pf.plot_line_graph(daily_vals, adapter = 'pythalesians', gp = gp)

        # use miletus matplotlib stylesheet
        gp.style_sheet = 'miletus-pythalesians'
        pf.plot_line_graph(daily_vals, adapter = 'pythalesians', gp = gp)

        # use ggplot matplotlib styleheet
        gp.scale_factor = 1
        gp.display_brand_label = False
        gp.display_source = False
        gp.style_sheet = 'ggplot-pythalesians'
        gp.display_mpld3 = True
Esempio n. 22
0
    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_url = country_group + data_type.replace(' ', '-')
    gp.plotly_world_readable = False
    gp.title = title
    gp.units = 'Value'

    # do a map plot by US state
    pf.plot_generic_graph(df, type = 'choropleth', adapter = 'cufflinks', gp = gp)

#### uses CommonEconDataFactory to get more common forms of economic data and plot
####
if True:
    logger = LoggerManager.getLogger(__name__)

    cedf = CommonEconDataFactory()
    start_date = '01 Jan 2014'
    finish_date = datetime.datetime.utcnow()

    # select as appropriate!
    # cedf.g10_plot_gdp_cpi_une(start_date, finish_date)
    # cedf.usa_plot_une(start_date, finish_date)
    # cedf.world_plot_une(start_date, finish_date)
    # cedf.world_plot_cpi(start_date, finish_date)
        )  # how to return data

        daily_vals = ltsf.harvest_time_series(time_series_request)

        # plot data
        gp = GraphProperties()
        pf = PlotFactory()

        gp.title = "Spot values"
        gp.file_output = "output_data/demo.png"
        gp.scale_factor = 2
        gp.style_sheet = "pythalesians"

        # first use PyThalesians matplotlib wrapper
        pf.plot_line_graph(daily_vals, adapter="pythalesians", gp=gp)
        pf.plot_generic_graph(daily_vals, gp=gp, type="line")

        # use modified 538 Matplotlib stylesheet
        gp.style_sheet = "538-pythalesians"
        pf.plot_line_graph(daily_vals, adapter="pythalesians", gp=gp)

        # use miletus matplotlib stylesheet
        gp.style_sheet = "miletus-pythalesians"
        pf.plot_line_graph(daily_vals, adapter="pythalesians", gp=gp)

        # use ggplot matplotlib styleheet
        gp.scale_factor = 1
        gp.display_brand_label = False
        gp.display_source = False
        gp.style_sheet = "ggplot-pythalesians"
        gp.display_mpld3 = True