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] pf = PlotFactory() gp = self.create_graph_properties("positions (% portfolio notional)", "Positions") pf.plot_generic_graph(last_day, adapter = self.DEFAULT_PLOT_ENGINE, type = 'bar', gp = gp)
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
if True: import pandas df = pandas.read_csv( "volsurface.csv") # load a snapshot for a vol surface from disk gp = GraphProperties() gp.plotly_plot_mode = "offline_html" # render Plotly plot locally (rather than via website) gp.file_output = "volsurface.png" # save as static PNG file gp.html_file_output = "volsurface.html" # save as interactive HTML file gp.title = "GBP/USD vol surface" gp.color = 'Blues' # plot surface with Plotly pf = PlotFactory() pf.plot_generic_graph(df, type='surface', adapter='cufflinks', gp=gp) if True: time_series_request = TimeSeriesRequest( start_date="01 Jan 2013", # start date finish_date=datetime.date.today(), # finish date freq='daily', # daily data data_source='google', # use Bloomberg as data source tickers=['Apple', 'S&P500 ETF'], # ticker (Thalesians) fields=['close'], # which fields to download vendor_tickers=['aapl', 'spy'], # ticker (Google) vendor_fields=['Close'], # which Bloomberg fields to download cache_algo='internet_load_return') # how to return data ltsf = LightTimeSeriesFactory()
if True: import pandas df = pandas.read_csv("volsurface.csv") # load a snapshot for a vol surface from disk gp = GraphProperties() gp.plotly_plot_mode = "offline_html" # render Plotly plot locally (rather than via website) gp.file_output = "volsurface.png" # save as static PNG file gp.html_file_output = "volsurface.html" # save as interactive HTML file gp.title = "GBP/USD vol surface" gp.color = 'Blues' # plot surface with Plotly pf = PlotFactory() pf.plot_generic_graph(df, type = 'surface', adapter = 'cufflinks', gp = gp) if True: time_series_request = TimeSeriesRequest( start_date = "01 Jan 2013", # start date finish_date = datetime.date.today(), # finish date freq = 'daily', # daily data data_source = 'google', # use Bloomberg as data source tickers = ['Apple', 'S&P500 ETF'], # ticker (Thalesians) fields = ['close'], # which fields to download vendor_tickers = ['aapl', 'spy'], # ticker (Google) vendor_fields = ['Close'], # which Bloomberg fields to download cache_algo = 'internet_load_return') # how to return data ltsf = LightTimeSeriesFactory()
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