model.plot_strategy_leverage() # plot the leverage of the portfolio model.plot_strategy_group_pnl_trades( ) # plot the individual trade P&Ls model.plot_strategy_group_benchmark_pnl( ) # plot all the cumulative P&Ls of each component model.plot_strategy_group_benchmark_pnl_ir( ) # plot all the IR of individual components model.plot_strategy_group_leverage( ) # plot all the individual leverages from finmarketpy.backtest import TradeAnalysis ta = TradeAnalysis() # create statistics for the model returns using both finmarketpy and pyfolio ta.run_strategy_returns_stats(model, engine='finmarketpy') # ta.run_strategy_returns_stats(model, engine='pyfolio') # model.plot_strategy_group_benchmark_annualised_pnl() # create a FX CTA strategy, then examine how P&L changes with different vol targeting # and later transaction costs if True: strategy = TradingModelFXTrend_Example() from finmarketpy.backtest import TradeAnalysis ta = TradeAnalysis() ta.run_strategy_returns_stats(model, engine='finmarketpy') # which backtesting parameters to change
'signal_vol_adjust': False }] pretty_portfolio_names = \ ['Vol target', 'No vol target'] parameter_type = 'vol target' ta.run_arbitrary_sensitivity( strategy, parameter_list=parameter_list, pretty_portfolio_names=pretty_portfolio_names, parameter_type=parameter_type) # now examine sensitivity to different transaction costs tc = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2.0] ta.run_tc_shock(strategy, tc=tc) # how does P&L change on day of month ta.run_day_of_month_analysis(strategy) # create a FX CTA strategy then use TradeAnalysis (via pyfolio) to analyse returns if True: from finmarketpy.backtest import TradeAnalysis model = TradingModelFXTrend_Example() model.construct_strategy() tradeanalysis = TradeAnalysis() tradeanalysis.run_strategy_returns_stats(strategy)
model.construct_strategy() model.plot_strategy_pnl() # plot the final strategy model.plot_strategy_leverage() # plot the leverage of the portfolio model.plot_strategy_group_pnl_trades() # plot the individual trade P&Ls model.plot_strategy_group_benchmark_pnl() # plot all the cumulative P&Ls of each component model.plot_strategy_group_benchmark_pnl_ir() # plot all the IR of individual components model.plot_strategy_group_leverage() # plot all the individual leverages from finmarketpy.backtest import TradeAnalysis ta = TradeAnalysis() # create statistics for the model returns using both finmarketpy and pyfolio ta.run_strategy_returns_stats(model, engine='finmarketpy') # ta.run_strategy_returns_stats(model, engine='pyfolio') # model.plot_strategy_group_benchmark_annualised_pnl() # create a FX CTA strategy, then examine how P&L changes with different vol targeting # and later transaction costs if True: strategy = TradingModelFXTrend_Example() from finmarketpy.backtest import TradeAnalysis ta = TradeAnalysis() ta.run_strategy_returns_stats(model, engine='finmarketpy') # which backtesting parameters to change
from findatapy.timeseries import Calculations from findatapy.util.loggermanager import LoggerManager ta = TradeAnalysis() calc = Calculations() logger = LoggerManager().getLogger(__name__) chart = Chart(engine='matplotlib') market = Market(market_data_generator=MarketDataGenerator()) # Choose run_example = 0 for everything # run_example = 1 - use PyFolio to analyse gold's return properties run_example = 0 ###### Use PyFolio to analyse gold's return properties if run_example == 1 or run_example == 0: md_request = MarketDataRequest( start_date="01 Jan 1996", # start date data_source='bloomberg', # use Bloomberg as data source tickers=['Gold'], fields=['close'], # which fields to download vendor_tickers=['XAUUSD Curncy'], # ticker (Bloomberg) vendor_fields=['PX_LAST'], # which Bloomberg fields to download cache_algo='internet_load_return') # how to return data df = market.fetch_market(md_request) ta.run_strategy_returns_stats(None, index=df, engine='pyfolio')