Mariner Backtesting - Scripts a.k.a. your algo

Script

The script is a Python program that represents a trading strategy to be executed on the CloudQuant backtesting system. inherit from the cloudquant.Strategy class. The trading system will instantiate this class for each symbol you want to backtest the trading strategy on and call various methods in it when events related to the script's symbol occur.

Lesson 1
Lesson 2

Working Example:

This script is running for IBM and AAPL. There are two instances running - one for IBM and one for AAPL. Each instance is tracking the number of trades that occur.

# Copyright Cloudquant, LLC. All right reserved.
from cloudquant.interfaces import Strategy


class BasicCounter(Strategy):
    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        # limit symbol universe to IBM AAPL
        return symbol in ['IBM', 'AAPL']

    def on_start(self, md, order, service, account):
        # establish instance variable for count
        self.count = 0

    def on_trade(self, event, md, order, service, account):
        # increment counter
        self.count += 1

    def on_finish(self, md, order, service, account):
        # print count
        print "{0}\t{1}\t{2}".format(service.time_to_string(service.system_time), self.symbol, self.count)

Pairs/Baskets:

In some situations, you need to evaluate multiple symbols together (e.g. pairs, or a basket). There are methods for registering other/additional symbols events to an instance of a script. This technique is explored in advanced topics.

Scheduling Backtests:

When you schedule backtesting jobs, there are several options you can put in, such as the dates you are testing for or the time of the day. Options are a way of more accurately telling the system what to do and when to do it.

Executions in a Backtest:

While you can have the simulator fill an order for any number of shares, we recommend using "Allow partial fills" which gives you the most available shares at the moment of your trade. This is advisable to give you a more realistic simulation.

Separating the Entry and Exit Scripts:

While a script can be written to handle both the entry and exit in the same script, the system supports having different scripts for entry (scanning) and the exit. The system handles the creation of the exit (dependent) scripts automatically after the entry order is completed. A dependent script is a way to organize your trading model. This works great for scripts that have multiple entries and want to have the exit logic evaluated in the context of each entry price.