Return a daily bars slice structure that goes back one or more market day(s).
Interface:
daily(start=-1,
end=None,
include_empty=False)
Sample - Calling method
md.bar.daily(start=-10)
Name | Type | Default | Information |
---|---|---|---|
start | integer or muts | -1 | Offset. May be a negative integer as a reference to now (e.g. -10 ... 10 days ago), or timestamp to a specific date.
|
end | integer or muts | None | Offset. May be a negative integer as a reference to now (e.g. -10 ... 10 days ago), a timestamp to a specific date, or None. A value of None indicates to include the most-recently-formed bar.
|
include_empty | boolean | False | If True, return bars for empty days instead of skipping over them, and check the "valid" property on the resulting bar slice to verify whether a bar is empty or not.
|
Daily BarView - tuple of mostly arrays
Daily BarView Attributes:
Name | Type | Information |
---|---|---|
askvol | Array[integer] | items in the array - the volume of trades that occurred at the ask during timeframe |
bidvol | Array[integer] | the volume of trades that occurred at the bid during timeframe |
bvwap | Array[float] | the vwap for the bar |
close | Array[float] | final, or closing price for the bar |
closing_trade | Array[float] | closing price for the symbol's primary exchange |
count | Array[integer] | number of items contributing to the bar |
high | Array[float] | highest price for the bar |
length | integer | time length for the bar |
low | Array[float] | lowest price for the bar |
open | Array[float] | first qualifying trade of the bar |
opening_trade | Array[float] | opening price for the symbol's primary exchange |
spread | Array[float] | average difference between the ask and the bid for the bar |
symbol | string | symbol for the bar |
timestamp | Array[integer] | timestamps for the beginning of each bar |
valid | Array[bool] | whether or not bar is valid |
volume | Array[integer] | volume for the bar |
vwap | Array[float] | volume weighted average price(vwap) of the bar |
- There are a lot of bar examples under Knowledge.
- Bars are formed - not forming. Forming data is part of L1.
- Daily bar data is static information (it doesn't change during the trading day). You should only need to request a symbol's daily bar data once in a script (example - in on_start() or in a function )
- When using this method, it may help to think of the daily bars as snapshots of trading data from previous days relative to the current simulation day.
- By default, if there is no market data on a given day between start and end, the returned array will contain fewer items than expected. To retrieve the exact number of daily bars requested, set include_empty=True. When include_empty=True, the valid property (see below) provides a boolean which indicates if the bar was empty (valid == True means "not empty").
- The returned slice can be accessed via .property, where property may be one of the following: symbol, length, timestamp, open, high, low, close, volume, vwap, bvwap, spread, bidvol, askvol, count, avgdelta, valid.
- When using include_empty, be aware the max() and min() and the first item in the array is NaN can cause the return value to be NaN even if there are other values besides NaN. See http://stackoverflow.com/questions/4237914/python-max-min-builtin-functions-depend-on-parameter-order
- At the moment one any given testing/trading day, 1 year of daily bars is available (starting 1/1/11).
import itertools
from cloudquant.interfaces import Strategy
class DailyBarsExample(Strategy):
@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
get the last high value bars.high[-1] - 104.449996948 get the first low value bars.low[0] - 93.6299972534 symbol ['AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL' 'AAPL'] length [23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400 23400] timestamp [1467207000000000 1467293400000000 1467379800000000 1467725400000000 1467811800000000 1467898200000000 1467984600000000 1468243800000000 1468330200000000 1468416600000000 1468503000000000 1468589400000000 1468848600000000 1468935000000000 1469021400000000 1469107800000000 1469194200000000 1469453400000000 1469539800000000 1469626200000000 1469712600000000] open [ 93.97000122 94.44000244 95.48999786 95.38999939 94.59999847 95.69999695 96.48999786 96.75 97.16999817 97.41000366 97.38999939 98.91999817 98.69999695 99.55999756 100. 99.83000183 99.26000214 98.25 96.81999969 104.26499939 102.83000183] high [ 94.55000305 95.76999664 96.46499634 95.40000153 95.66000366 96.5 96.88999939 97.65000153 97.69999695 97.66999817 98.98000336 99.30000305 100.12999725 100. 100.45999908 101. 99.30000305 98.83999634 97.97000122 104.34999847 104.44999695] low [ 93.62999725 94.30000305 95.33000183 94.45999908 94.37000275 95.62000275 96.05000305 96.73999786 97.12000275 96.83999634 97.31999969 98.5 98.61000061 99.33999634 99.73500061 99.12999725 98.30999756 96.91999817 96.41999817 102.75 102.81999969] close [ 94.40000153 95.58000183 95.88999939 95.04000092 95.52999878 95.94000244 96.68000031 96.98000336 97.41999817 96.87000275 98.79000092 98.77999878 99.83000183 99.87000275 99.95999908 99.40000153 98.66000366 97.33999634 96.66999817 103.02999878 104.33999634] volume [36532435 35953026 26007244 27724722 30951005 25141361 28929900 23795922 24167463 25892533 38921985 30137795 36679958 23780554 26277068 32779214 28378442 40373629 56270102 92346874 39869985] vwap [ 94.23366547 95.21818542 96.02340698 94.80203247 95.13683319 96.06842804 96.63038635 97.26353455 97.40542603 97.18331146 98.3677063 98.86615753 99.78375244 99.79320526 99.98825073 99.9590683 98.6979599 97.68746948 97.06649017 103.53497314 103.88442993] spread [ 0.00982997 0.00990416 0.00992139 0.01000847 0.00990139 0.00993327 0.00983547 0.00987558 0.00972609 0.00990837 0.00958601 0.01024598 0.0097909 0.01007923 0.00989556 0.00984205 0.00994838 0.00992271 0.0098503 0.01009011 0.00970959] bidvol [11698070 14279332 9647840 9269781 11285611 8078345 9289119 7259073 8155971 10761212 12907579 9155765 14177175 9121777 8901961 10286266 8741883 13287066 13817396 30352321 11964169] askvol [14018939 10348263 8302942 7677200 11576578 8758522 8333373 9335631 8511582 7532046 15455691 12922405 11675214 7016688 9221600 10956753 10764836 12235336 13000567 25665777 12841713] count [216409 204314 154609 153279 187589 143924 168670 144022 151231 144845 231502 157727 200056 134943 146681 169900 153518 224064 289094 484311 216364] valid [ True True True True True True True True True True True True True True True True True True True True True] closing_trade [ 94.40000153 95.59999847 95.88999939 94.98999786 95.52999878 95.94000244 96.68000031 96.98000336 97.41999817 96.87000275 98.79000092 98.77999878 99.83000183 99.87000275 99.95999908 99.43000031 98.66000366 97.33999634 96.66999817 102.94999695 104.33999634] opening_trade [ 93.97000122 94.45999908 95.5 95.37999725 94.59999847 95.69999695 96.48999786 96.76000214 97.16999817 97.41000366 97.33000183 99.05999756 98.69999695 99.5 100. 100. 99.26000214 98.19999695 96.83000183 104.25 102.83000183]