Mariner Backtesting - Strategy

Strategy is a class of cloudquant's interface.

Overview:

Strategy is a class of CloudQuant's interface.  As your script runs as an instance of the system, the system's calls into the methods of your script. This section covers the available methods, behaviors and functionality.

Import:
 from cloudquant.interfaces import Strategy
Categories:

The methods are organized into:

 from cloudquant.interfaces import Strategy

class MyClass(Strategy):

    ########################################################################################
    #
    # high level strategy - start/finish
    #
    ########################################################################################

    # called when the strategy starts (aka before anything else)
    @classmethod
    def on_strategy_start(cls, md, service, account):
        pass

    # called when the strategy finish (aka after everything else has stopped)
    @classmethod
    def on_strategy_finish(cls, md, service, account):
        pass

    ########################################################################################
    #
    # symbol universe 
    #
    ########################################################################################

    # note that this doesn't start with "self" because it's a @staticmethod
    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return True

    # used to load other symbols data not in is_symbol_qualified(). Only used in backtesting
    @classmethod
    def backtesting_extra_symbols(cls, symbol, md, service, account):
        return False

    ########################################################################################
    #
    # start/finish instance related methods
    #
    ########################################################################################

    # used to pass external parameters for each instance (same for values for every instance)
    def __init__(self): #, **params - if passing in parameters is desired
        pass

    # called at the beginning of each instance
    def on_start(self, md, order, service, account):
        pass

    # if running with an instance per symbol, call when an instance is terminated
    def on_finish(self, md, order, service, account):
        pass

    ########################################################################################
    #
    # timer method
    #
    ########################################################################################

    # called in timer event is received
    def on_timer(self, event, md, order, service, account):
        pass

    ########################################################################################
    #
    # market data related methods
    #
    ########################################################################################

    # called every minute before the first on_trade of every new minute, or 5 seconds after a new minute starts
    def on_minute_bar(self, event, md, order, service, account, bar):
        pass
    # called when time and sales message is received
    def on_trade(self, event, md, order, service, account):
        pass

    # called when national best bid offer (nbbo) prices change (not size)
    def on_nbbo_price( self, event, md, order, service, account ):
        pass

    # called when arca imbalance message is received
    def on_arca_imbalance(self, event, md, order, service, account):
        pass

    # called when nasdaq imbalance message is received
    def on_nasdaq_imbalance(self, event, md, order, service, account):
        pass

    # called when nyse/amex/nsye mkt/openbook message is received
    def on_nyse_imbalance(self, event, md, order, service, account):
        pass

    ########################################################################################
    #
    # order related methods
    #
    ########################################################################################

    # called when order considered pending by the system
    def on_ack(self, event, md, order, service, account):
        pass

    # called when an order is rejected (locally or other parts of the order processes e.g. the market)
    def on_reject(self, event, md, order, service, account):
        pass

    # called when the position changes in this account and symbol (whether manually or automated)
    def on_fill(self, event, md, order, service, account):
        pass

    # called when the market has confirmed an order has been canceled
    def on_cancel(self, event, md, order, service, account):
        pass
Remarks:
  • To use Strategy add the import to the beginning of your script