Pre-Start initiating event
on_start() is used for pre-running activity. Data initialization should happen here, including reading of historic bars, and creation of any internal data structures. The strategy should also set its calculate and evaluate triggers with the appropriate calls to service.
Interface: def on_start(self,
md,
order,
service,
account):
pass
Same for on_finish()
Name | Type | Default | Information |
---|---|---|---|
self | object | required | The instance of Strategy (used by the system). |
md | object | required | Market data object. It should not be saved, as it may change in future calls. |
order | object | required | Order object. It should not be saved, as it may change in future calls. |
service | object | required | Service object. It should not be saved, as it may change in future calls. |
account | object | required | Account object. It should not be saved, as it may change in future calls. |
Remarks:
- Best place to read daily bars (md.bar.daily(-10)), since the data isn't changing.
- service.terminate() can be called in on_start() (e.g. a symbol no longer qualifies for model).
- Good place to schedule on_timer() calls
from cloudquant.interfaces import Strategy
class OnStartExample(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == "AAL"
def on_start(self, md, order, service, account):
print(self.symbol +"\n"+ service.time_to_string(service.system_time) +"\n\n")
print ("on_start has begun")
self.ep = 0 # establish variables
print ("on_start has completed")
Console
AAL 2016-08-09 09:24:32.989000 on_start has begun on_start has completed