Mariner Backtesting - KTG Functions

ktgfunc is a library with classes and functions to help with using CloudQuant.

ktgfunc Overview:

ktgfunc is a library with classes and functions to help with using CloudQuant. This library contains common code that the professional quants and traders at the Kershner Trading Group have found useful to assist their algo development with CloudQuant's backtesting environment.

Classes Included

Functions / Methods Included

Import

Import the entire library

 import ktgfunc

Import a specific class or function

 from cloudquant.interfaces import Strategy, Event
from ktgfunc import TrackRange

class TestTrackRange(Strategy):

    @staticmethod
    def in_symbol_universe(symbol, md, service):
        return symbol == 'TQQQ'

    def on_start(self, md, order, service, account):
        print 'Test date:\t%s' % service.time_to_string(service.system_time, '%Y-%m-%d')
        self.test = TrackRange(md, 20)
        print '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' %  ('time', 'rvol', 'r_high', 'r_low', 'range', 'mx_high', 'mn_low', 'break amount')

    def on_trade(self, event, md, order, service, account):
        self.test.Calculate(md)

        if self.test.MaxAboveRange != 0 or self.test.MaxBelowRange != 0 or self.test.BreakAmount != 0:
            print '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' %  ( service.time_to_string(service.system_time), md.L1.rvol, self.test.RangeHigh, self.test.RangeLow, self.test.Range, self.test.MaxAboveRange, self.test.MaxBelowRange, self.test.BreakAmount )