seq_up() tests a list or array of numbers are sequentially increasing.
Code:
def seq_up(ts):
for x in xrange(1, len(ts)):
if ts[x - 1] > ts[x]:
return False
return True
Name | Type | Default | Information |
---|---|---|---|
time series data | list | required | list of numbers |
Type | Notes |
---|---|
boolean | True if numbers are increasing, else False |
Check if the daily bar highs are sequentially increasing. Backtest for TQQQ on 2016/06/15 from 9:30-16:00.
from cloudquant.interfaces import Strategy
import ktgfunc
class TestKTGFunc(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == 'TQQQ' and service.time_to_string(service.system_time, '%Y-%m-%d') == '2016-06-15'
# called at the beginning of each instance
def on_start(self, md, order, service, account):
t = service.time_to_string(service.system_time, '%Y-%m-%d')
bar = md.bar.daily(start=-13)
print bar.high
#[ 105.20999908 105.19000244 104.72100067 105.62999725 105.30000305 105.18000031 104.37000275 101.77999878 100.4536972 98.98999786]
ts_up = bar.high[2:4]
ts_down = bar.high[4:6]
print '\ntimeseries up', ts_up
print '\ntimeseries down', ts_down
print '\nktgfunc.seq_up( ts_up )'
print ('test time: %s\t%s') % (t, ktgfunc.seq_up( ts_up ) ) # True
print '\nktgfunc.seq_up( ts_down )'
print ('test time: %s\t%s') % (t, ktgfunc.seq_up( ts_down ) ) # False
service.terminate()
Console
[ 105.20999908 105.19000244 104.72100067 105.62999725 105.30000305 105.18000031 104.37000275 101.77999878 100.4536972 98.98999786] timeseries up [ 104.72100067 105.62999725] timeseries down [ 105.30000305 105.18000031] ktgfunc.seq_up( ts_up ) test time: 2016-06-15 True ktgfunc.seq_up( ts_down ) test time: 2016-06-15 False