# create a FX trend strategy then chart the returns, leverage over time if True: model = TradingModelFXTrend_Example() 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()
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()
""" Shows how to calculate returns of an asset """ # Loading data import datetime from chartpy import Chart, Style from finmarketpy.backtest import TradeAnalysis from findatapy.market import Market, MarketDataGenerator, MarketDataRequest from chartpy.style import Style 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(