Mariner Backtesting - Reference Other Symbols

Reference (get) other symbols market data

Interface:

md[some_other_symbol].object.attribute

md[some_other_symbol].attribute
Remarks:
  • works on md
Working Example:

Reference SPY data, without qualifying it in is_symbol_qualified()

# Copyright Cloudquant, LLC. All right reserved.
from cloudquant.interfaces import Strategy
class MyStrategy(Strategy):


  @classmethod
  def is_symbol_qualified(cls, symbol, md, service, account):
      return symbol == 'AMZN'

  @classmethod
  def backtesting_extra_symbols(cls, symbol, md, service, account):
    # this loads spy's data.
    #  It will not be called, in on_start() for example, but you can access SPY information.
    return symbol == 'SPY'

  def on_start(self, md, order, service, account):
      print(self.symbol + "\n---------- in on_start " + service.time_to_string(service.system_time))

      # print information about the current symbol and SPY
      for symb in [self.symbol, 'SPY']:
        print '\n' + symb
        # use md[symb] to get the market data for the specified symbol
        print '\t', 'prev_close:', md[symb].stat.prev_close
        print '\t', 'prev_avol:', md[symb].stat.avol
        print '\t', 'prev_exchange:', md[symb].stat.exchange
        print '\t', 'atr:', md[symb].stat.atr

        service.terminate()

Console

AMZN
---------- in on_start 2016-09-07 09:30:00.000000

AMZN
    prev_close: 788.869995117
    prev_avol: 1990781
    prev_exchange: Q
    atr: 7.93349981308

SPY
    prev_close: 219.030807495
    prev_avol: 69144813
    prev_exchange: P
    atr: 1.4960000515