Understanding Daily Market Data and Candlesticks

In this online post we introduce how to use the md.bar.daily market data daily bars and output some values.

https://info.cloudquant.com/2017/12/understanding-candlestick-bars-in-market-data-for-algo-programmers/

`from cloudquant.interfaces import Strategy

class barsDemo(Strategy):

@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
    return symbol=="GOOG"

# called at the beginning of each instance
def on_start(self, md, order, service, account):

    daily_bars = md.bar.daily(start=-20,include_empty=False) # grab 20 bars of historical data 

    print self.symbol
    print
    print "Open   1 day ago",daily_bars.open[-1]
    print "High   1 day ago",daily_bars.high[-1]
    print "Low    1 day ago",daily_bars.low[-1]
    print "Close  1 day ago",daily_bars.close[-1]
    print "Volume 1 day ago",daily_bars.volume[-1]
    print
    print "Close  1 day  ago",daily_bars.close[-1]
    print "Close  2 days ago",daily_bars.close[-2]
    print "Close  3 days ago",daily_bars.close[-3]
    print "Close  4 days ago",daily_bars.close[-4]
    print "Close  5 days ago",daily_bars.close[-5]
    print
    print "Close for all fetched bars",daily_bars.close[:]
    print
    print "Average Volume for all fetched bars",sum(daily_bars.volume)/len(daily_bars.volume)
    print
    print "Average Volume for most recent 10 bars",sum(daily_bars.volume[-10:])/len(daily_bars.volume[-10:])
    print
    print "Average Volume for 10 bars before that",sum(daily_bars.volume[-20:-10])/len(daily_bars.volume[-20:-10])
    print

    service.terminate()`
Tagged:
Sign In or Register to comment.