asset_df = ltsf.harvest_time_series(time_series_request) spot_df = asset_df logger.info("Running backtest...") # use technical indicator to create signals # (we could obviously create whatever function we wanted for generating the signal dataframe) tech_ind = TechIndicator() tech_ind.create_tech_ind(spot_df, indicator, tech_params); signal_df = tech_ind.get_signal() # use the same data for generating signals cash_backtest.calculate_trading_PnL(br, asset_df, signal_df) port = cash_backtest.get_cumportfolio() port.columns = [indicator + ' = ' + str(tech_params.sma_period) + ' ' + str(cash_backtest.get_portfolio_pnl_desc()[0])] signals = cash_backtest.get_porfolio_signal() # print the last positions (we could also save as CSV etc.) print(signals.tail(1)) pf = PlotFactory() gp = GraphProperties() gp.title = "Thalesians FX trend strategy" gp.source = 'Thalesians/BBG (calc with PyThalesians Python library)' gp.scale_factor = 1 gp.file_output = 'output_data/fx-trend-example.png' pf.plot_line_graph(port, adapter = 'pythalesians', gp = gp) ###### backtest simple trend following strategy for FX spot basket if True:
cache_algo = 'internet_load_return') # how to return data ltsf = LightTimeSeriesFactory() asset_df = ltsf.harvest_time_series(time_series_request) spot_df = asset_df logger.info("Running backtest...") # use technical indicator to create signals # (we could obviously create whatever function we wanted for generating the signal dataframe) tech_ind = TechIndicator() tech_ind.create_tech_ind(spot_df, indicator, tech_params); signal_df = tech_ind.get_signal() # use the same data for generating signals cash_backtest.calculate_trading_PnL(br, asset_df, signal_df) port = cash_backtest.get_cumportfolio() port.columns = [indicator + ' = ' + str(tech_params.sma_period) + ' ' + str(cash_backtest.get_portfolio_pnl_desc()[0])] signals = cash_backtest.get_porfolio_signal() # print the last positions (we could also save as CSV etc.) print(signals.tail(1)) pf = PlotFactory() gp = GraphProperties() gp.title = "Thalesians FX trend strategy" gp.source = 'Thalesians/BBG (calc with PyThalesians Python library)' gp.scale_factor = 1 gp.file_output = 'output_data/fx-trend-example.png' pf.plot_line_graph(port, adapter = 'pythalesians', gp = gp)
cache_algo = 'internet_load_return') # how to return data ltsf = LightTimeSeriesFactory() asset_df = ltsf.harvest_time_series(time_series_request) spot_df = asset_df logger.info("Running backtest...") # use technical indicator to create signals # (we could obviously create whatever function we wanted for generating the signal dataframe) tech_ind = TechIndicator() tech_ind.create_tech_ind(spot_df, indicator, tech_params); signal_df = tech_ind.get_signal() # use the same data for generating signals cash_backtest.calculate_trading_PnL(br, asset_df, signal_df) port = cash_backtest.get_cumportfolio() port.columns = [indicator + ' = ' + str(tech_params.sma_period) + ' ' + str(cash_backtest.get_portfolio_pnl_desc()[0])] signals = cash_backtest.get_porfolio_signal() # print the last positions (we could also save as CSV etc.) print(signals.tail(1)) pf = PlotFactory() gp = GraphProperties() gp.title = "Thalesians FX trend strategy" gp.source = 'Thalesians/BBG (calc with PyThalesians Python library)' gp.scale_factor = 3 gp.file_output = 'output_data/FX-trend-example.png' pf.plot_line_graph(port, adapter = 'pythalesians', gp = gp)
logger.info("Running backtest...") # use technical indicator to create signals # (we could obviously create whatever function we wanted for generating the signal dataframe) tech_ind = TechIndicator() tech_ind.create_tech_ind(spot_df, indicator, tech_params) signal_df = tech_ind.get_signal() # use the same data for generating signals cash_backtest.calculate_trading_PnL(br, asset_df, signal_df) port = cash_backtest.get_cumportfolio() port.columns = [ indicator + ' = ' + str(tech_params.sma_period) + ' ' + str(cash_backtest.get_portfolio_pnl_desc()[0]) ] signals = cash_backtest.get_porfolio_signal() # print the last positions (we could also save as CSV etc.) print(signals.tail(1)) pf = PlotFactory() gp = GraphProperties() gp.title = "Thalesians FX trend strategy" gp.source = 'Thalesians/BBG (calc with PyThalesians Python library)' gp.scale_factor = 1 gp.file_output = 'output_data/fx-trend-example.png' pf.plot_line_graph(port, adapter='pythalesians', gp=gp) ###### backtest simple trend following strategy for FX spot basket if True: