1. Support Center
  2. Mariner Backtesting

Mariner Backtesting - CQ Elite 1

CloudQuant Elite 1

In this tutorial, we will be using the system method on_trade() to count the number of trades per symbol for 11/1/16.

Counting Trades using on_trade()
Code Used in This Tutorial:
 # Copyright Cloudquant, LLC. All right reserved.
from cloudquant.interfaces import Strategy


class first_script(Strategy):
    # note that this doesn't start with "self" because it's a @staticmethod
    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol in ['AAPL', 'MSFT']

    # called at the beginning of each instance
    def on_start(self, md, order, service, account):
        print('Current Symbols:\t' + self.symbol)
        print('Current Time:\t' + service.time_to_string(service.system_time) + '\n')
        self.trade_count = 0

    def on_trade(self, event, md, order, service, account):
        self.trade_count += 1

    def on_finish(self, md, order, service, account):
        print('on_finish\tCurrent Symbols:\t' + self.symbol)
        print('on_finish\tCurrent Time:\t' + service.time_to_string(service.system_time) + '\n')
        print('trade_count:\t' + str(self.trade_count))
Console

The console output from running our code:

 Current Symbols:    AAPL
Current Time:   2016-11-01 09:30:00.000000

Current Symbols:    MSFT
Current Time:   2016-11-01 09:30:00.000000

on_finish   Current Symbols:    AAPL
on_finish   Current Time:   2016-11-01 16:00:00.000000

trade_count:    234393
on_finish   Current Symbols:    MSFT
on_finish   Current Time:   2016-11-01 16:00:00.000000

trade_count:    134053