Mariner Backtesting - Bar - bar

bar Overview

bar is a member of md. The bar object has methods for shaping and accessing the system's bar data.

Attributes:

See each of the types of bars, listed below by the methods that return them, for their specific attributes:

Methods:

Remarks:

  • Since the consumption of bars data isn't one size fits all, we provide a couple of methods format the data as desired.
  • Methods return a BarView tuple. The tuple is mostly arrays of equal length data.
  • BarView is slightly different for minute and daily bars

Working Example:

 import itertools
from cloudquant.interfaces import Strategy


class PrintingBarData(Strategy):
    @classmethod
    def on_strategy_start(cls, md, service, account):
        print service.time_to_string(service.system_time, '%Y-%m-%d')

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

    def on_start(self, md, order, service, account):
        # get bars
        bars = md.bar.daily(start=-21)

        print '\nget the last high value'
        print 'bars.high[-1]\t-\t', bars.high[-1]

        print '\nget the first low value'
        print 'bars.low[0]\t-\t', bars.low[0]

        # print the bar data
        fields = bars._fields
        for key, value in enumerate(bars):
            print '\n\n', fields[key], '\n', value

        service.terminate()

Console

2016-11-11

get the last high value
bars.high[-1]   -   126.70110321

get the first low value
bars.low[0] -   119.669998169


symbol 
['TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ'
 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ' 'TQQQ'
 'TQQQ']


length 
[23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400
 23400 23400 23400 23400 23400 23400 23400 23400 23400]


timestamp 
[1476365400000000 1476451800000000 1476711000000000 1476797400000000
 1476883800000000 1476970200000000 1477056600000000 1477315800000000
 1477402200000000 1477488600000000 1477575000000000 1477661400000000
 1477920600000000 1478007000000000 1478093400000000 1478179800000000
 1478266200000000 1478529000000000 1478615400000000 1478701800000000
 1478788200000000]


open 
[ 121.91000366  124.70999908  123.30000305  126.75        125.38999939
  125.08999634  125.33000183  129.05999756  131.22999573  127.30000305
  128.86999512  124.33999634  124.55999756  123.44999695  119.73999786
  116.52999878  112.58999634  117.79000092  120.          118.41000366
  125.98999786]


high 
[ 124.05999756  126.31999969  123.93810272  127.43000031  126.16999817
  126.01999664  126.79000092  131.36999512  131.41999817  129.36180115
  129.17999268  126.33999634  124.55999756  123.44999695  120.55000305
  117.62999725  115.06999969  120.77999878  124.37999725  125.02999878
  126.70110321]


low 
[ 119.66999817  123.22000122  121.98709869  125.5         124.98999786
  123.01999664  124.23000336  128.96000671  129.28829956  126.09999847
  124.95999908  122.          122.59999847  116.81999969  116.20999908
  113.20999908  111.77999878  117.33000183  119.19999695  118.06999969
  113.47000122]


close 
[ 123.05000305  123.33000183  122.48000336  125.62000275  125.66999817
  125.13999939  126.5         131.11000061  129.80000305  127.30999756
  125.52999878  123.36000061  122.66000366  120.13999939  117.01000214
  113.63999939  112.34999847  120.40000153  122.76000214  124.48000336
  118.55999756]


volume 
[2175582 1704427 1163800 1603522  980294 1457302 1221370 1430167 1244003
 1985592 2146713 2978276 1185507 2123423 1703435 1812758 1769276 2103406
 2303928 3753104 5165969]


vwap 
[ 121.73429871  124.7767334   122.80847931  126.5140686   125.61797333
  124.69200134  125.81477356  130.1771698   130.27629089  127.46583557
  126.83183289  123.99119568  123.45432281  119.97286224  118.39886475
  115.29000854  113.67202759  119.45043182  122.29109192  121.90427399
  119.14435577]


spread 
[ 0.02932563  0.03182294  0.03189036  0.03361049  0.0206065   0.02196015
  0.01750633  0.01705382  0.01699058  0.01571736  0.01430142  0.01259803
  0.01551066  0.02122752  0.02196823  0.02215978  0.01963826  0.02115857
  0.0222968   0.03018158  0.0326326 ]


bidvol 
[ 655004  538141  311218  389639  288655  456211  392628  433242  390844
  652545  779226 1144122  382143  641051  518453  580192  531627  531989
  608739 1110770 1681857]


askvol 
[ 632728  424135  329988  427326  319627  412458  430390  510382  412937
  690834  718390 1220281  441819  526899  538396  450141  576886  714485
  600648  908684 1383826]


count 
[11193  9018  5787  7660  4916  7039  6178  7195  6647 10967 11550 19819
  7080 12331 12145 10981 11571 11936 12352 21327 30820]


valid 
[ True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True]


closing_trade 
[ 123.05000305  123.33000183  122.48000336  125.62000275  125.66999817
  125.13999939  126.5         131.11000061  129.80000305  127.30999756
  125.52999878  123.36000061  122.66000366  120.13999939  117.01000214
  113.63999939  112.34999847  120.40000153  122.76000214  124.48000336
  118.55999756]


opening_trade 
[ 121.83000183  124.84999847  123.30000305  126.83999634  125.26000214
  125.08999634  125.33000183  128.96000671  131.33999634  127.23999786
  128.86999512  124.33999634  124.55999756  123.44999695  119.73999786
  116.44999695  112.77999878  118.          120.          118.51000214
  126.15000153]