How to use the finmarketpy.backtest.TradeAnalysis function in finmarketpy

To help you get started, we’ve selected a few finmarketpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_bbg_example.py View on Github external
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_BBG_Example()

        from finmarketpy.backtest import TradeAnalysis

        ta = TradeAnalysis()
        ta.run_strategy_returns_stats(model, engine='finmarketpy')

        # which backtesting parameters to change
        # names of the portfolio
        # broad type of parameter name
        parameter_list = [
            {'portfolio_vol_adjust': True, 'signal_vol_adjust' : True},
            {'portfolio_vol_adjust': False, 'signal_vol_adjust' : False}]

        pretty_portfolio_names = \
            ['Vol target',
             'No vol target']

        parameter_type = 'vol target'

        ta.run_arbitrary_sensitivity(strategy,
github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_example.py View on Github external
# 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()
        ta.run_strategy_returns_stats(model, engine='finmarketpy')
github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_bbg_example.py View on Github external
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 False:
        from finmarketpy.backtest import TradeAnalysis
        model = TradingModelFXTrend_BBG_Example()
        model.construct_strategy()

        tradeanalysis = TradeAnalysis()
        tradeanalysis.run_strategy_returns_stats(strategy)
github cuemacro / finmarketpy / finmarketpy_examples / returns_examples.py View on Github external
__author__ = 'saeedamen'


# 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(
                start_date = "01 Jan 1996",                         # start date
github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_example.py View on Github external
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
        # names of the portfolio
        # broad type of parameter name
        parameter_list = [
            {'portfolio_vol_adjust': True, 'signal_vol_adjust' : True},
            {'portfolio_vol_adjust': False, 'signal_vol_adjust' : False}]

        pretty_portfolio_names = \
            ['Vol target',
             'No vol target']

        parameter_type = 'vol target'

        ta.run_arbitrary_sensitivity(strategy,
github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_bbg_example.py View on Github external
# create a FX trend strategy then chart the returns, leverage over time
    if True:
        model = TradingModelFXTrend_BBG_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_BBG_Example()

        from finmarketpy.backtest import TradeAnalysis

        ta = TradeAnalysis()
        ta.run_strategy_returns_stats(model, engine='finmarketpy')
github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_example.py View on Github external
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 False:
        from finmarketpy.backtest import TradeAnalysis
        model = TradingModelFXTrend_Example()
        model.construct_strategy()

        tradeanalysis = TradeAnalysis()
        tradeanalysis.run_strategy_returns_stats(strategy)