TLDR:
Don't do the below as it doesn't include the commission and the account will go short
order_value(sid(x), context.portfolio.cash)
Complete story:
In the attached algo, I get a crash in Q when I increase the commission from
set_commission(commission.PerShare(cost=0.005))
to
set_commission(commission.PerShare(cost=5))
Since it crashes with cost = 5, I cannot share the algo, and so in the source code shared, the cost is 0.005
The error is
*
Something went wrong on our end and we've been notified about it.
Sorry for the inconvenience. OverflowError: Can't order more than
100000000000 shares File test_algorithm_sycheck.py:29, in handle_data
File algoproxy.py:1258, in order File /zipline/algorithm.py:455, in
order File /zipline/finance/blotter.py:126, in order File
test_algorithm_sycheck.py:27, in handle_data File algoproxy.py:1258,
in order File /zipline/algorithm.py:455, in order File
/zipline/finance/blotter.py:126, in order File
test_algorithm_sycheck.py:13, in handle_data File algoproxy.py:1258,
in order File /zipline/algorithm.py:455, in order File
/zipline/finance/blotter.py:126, in order
*
HOWEVER, I suspect that the issue happens when the returns go negative below a certain percentage (100%?) and then the algo goes haywire and tries to buy a huge amount of stocks.
This happens only when I increase the commission to a very high value and play with smaller priced stocks (ARNA in this case).
I SUSPECT that the order or order_value does not include the commission before calculating how many stocks can be bought, and because the commission is included after the calculation of number of stocks to trade, the account gets short and then the algo misbehaves. Looking at zipline, that seems to be the case.
So what is the recommended method for order_value?
Is it to calculate the commission before using order_value especially if we try to use the entire cash we have?
Ajay