fxmanager.strategies package

Package contents

This sub-package contains the mudules used for building and injecting trading strategies int FX-Manager’s trading simulations.

Public Modules:
  • naieve_momentum: This module contains simple implementation of momentum trading strategy, used as default for simulations.

fxmanager.strategies.naieve_momentum module

This module contains simple implementation of momentum trading strategy.

Public Functions:
  • get_orders(): sample trading strategy for purposes of testing live and historic trading simulators.

fxmanager.strategies.naieve_momentum.get_orders(prices, **kwargs)

sample trading strategy for purposes of testing live and historic trading simulators.

Args:
  • prices: pandas DataFrame with range index and a the following columns:
    • ask_open: open ask price of the candle stick.

    • bid_open: open bid price of the candle stick.

    • ask_close: close ask price of the candle stick.

    • bid_close: close bid price of the candle stick.

  • kwargs: special dictionary to hold any number of required arguments for the function.

Returns:
  • orders: pandas DataFrame with ONE RAW and the following columns:
    • order_type: can be one of 3 values (buy, sell, hold)

    • SL : stop loss.

    • TP : take profit.

fxmanager.strategies.template module

This module contains a class that is used by user to create a strategy object which is passed to fxmanager’s built-in live and historical simulators.

Public Classes:
  • strategy_template: Class for injecting user defined trading strategies into fxmanager’s built-in live and historical simulators.

class fxmanager.strategies.template.strategy_template(strategy, take_all_prices=False)

Bases: object

Class for injecting user defined trading strategies into fxmanager’s built-in live and historical simulators.

Args:
  • strategyreference to a user defined function for some trading strategy. The function MUST be structured as follows in order for the simulation to work proberly:
    • takes ONLY ONE positional argument called ‘prices’. This argument is a pandas DataFrame with range index and the following columns:
      • ask_open: open ask price of the candle stick.

      • bid_open: open bid price of the candle stick.

      • ask_close: close ask price of the candle stick.

      • bid_close: close bid price of the candle stick.

    • takes **kwargs for any other keword arguments.

    • returns a pandas DataFrame with ONE RAW and the following columns:
      • order_type: can be one of 3 values (buy, sell, hold)

      • SL : stop loss.

      • TP : take profit.

  • take_all_prices: boolean that controls the frequency of the range index of ‘prices’ DataFrame.

    If True: all the prices history since the begining of the day is passed to the strategy function, the index is a normal range index (0, 1, 2, …). the time difference between every reading is determined by the ‘sleep_time’ argument in the ‘fxmanager.simulation.live.run()’ or ‘fxmanager.simulation.historic.run()’ functions. If False: the frequncy of the prices becomes dependant on the time frame in which we want to generate an order, for examble, if we want to open a position in ‘EURUSD’ in the ‘5min’ time frame, the index will become (0, 5, 10, ..).

Methods:
  • get_orders: used in ‘fxmanager.simulation.live.run()’ and ‘fxmanager.simulation.historic.run()’ functions.

get_orders(prices, **kwargs)
get_portfolios_template()

returns a list of dictionaries of length = num_days where each dictionary is a portfolio used for a given day.

kwargs_template()

returns a template dictionary for keyword args used in used defined strategies.

template(**kwargs)

function template for the user to build trading strategies.

Args:
  • prices: pandas DataFrame with range index and the following columns:
    • ask_open: open ask price of the candle stick.

    • bid_open: open bid price of the candle stick.

    • ask_close: close ask price of the candle stick.

    • bid_close: close bid price of the candle stick.

  • kwargs: special dictionary to hold any number of required arguments for the function.

Returns:
  • orders: pandas DataFrame with ONE RAW and the following columns:
    • order_type: can be one of 3 values (buy, sell, hold)

    • SL : stop loss.

    • TP : take profit.