Open femtotrader opened 10 years ago
see https://www.quantopian.com/posts/bracket-orders and maybe also OCA orders (one cancel all) https://www.quantopian.com/posts/oca-orders
@femtotrader for your own stuff, reading through the quantstrat
code would be beneficial. I only learned R so I could understand it.
The OCO logic is fairly straight forward iirc. The only gotcha is that if a single bar triggers multiple orders in the orderset. For my stuff, it's modeled like so:
Executor receives price event
passes price, orderbook to execution_model
execution_model gathers all possible triggered fills
if multiple orders from same orderset can be triggered:
execution_model calls orderset_model that determines the winner
Executor now has all fills modeled by execution_model.
executes orders and Orderbook cancels any orphan orderset orders.
I think what's important is that you don't execute immediately on limit/stop price trigger because you might have multiple triggered orders. You can break the tie randomly, default to adverse outcome, or maybe dip down to more granular data to determine which order was triggered first. If you're working on sub-minutely data, I don't know how often you'd run into the multiple trigger problem.
You can actually unit test your python code against R/quantstrat. http://nbviewer.ipython.org/gist/dalejung/3357531/faber.ipynb is an example of getting the equivalent output from R and python. That's notebook is like 2 years old so I dunno if it'll still work, but more of an example.
Hello,
it will be nice if Zipline / Quantopian could support bracketed order http://optionstradingbeginner.blogspot.fr/2010/08/bracketed-order.html http://optionstradingbeginner.blogspot.fr/2008/11/types-of-orders-in-trading.html
Bracket OCO http://help.tradestation.com/09_01/tradestationhelp/ob/about_oco_oso_orders.htm
see also this issue: https://github.com/quantopian/zipline/issues/189
Kind regards