1) I think you've worked out the 2% logic now, but I've changed it a little. You have to check for open orders.
2) To increase backtest speed, you ideally need to remove all loops. Some loops are unavoidable, but otherwise try to use all pandas/numpy functions that work on arrays. At the moment, you have context.N = 900 days (about 42 months), which is going to be slow with a DollarVolumeUniverse. No way of getting around that really. You could reduce this to 750 days and still get the required 30 months of prices. If you could define a different universe using fundamental data instead (https://www.quantopian.com/help#sample-fundamentals) that might be quicker.
That's very nice of you - help comes for free - but if you feel so inclined, you may pick any cancer research charity (I'm not familiar with US charities).
3) I'm not 100% on what you mean there, but see the example. You can get the past 3 hrs of minutes (or less, if the day just started) and do something with that. If you want to check on that every minute, it will be slow to test.
4) volatile ETFs - that's tricky, but you can rule out most of the leveraged ETFs by checking you don't order any sid in
security_lists.leveraged_etf_list. Although I don't think historical leveraged ETFs are included in that list.
What's with the
prices.resample(... closed='left') ?
I believe the
rangesD are the same but reversed in order (ignoring sign), i.e.
ranges.iloc[0:10] == rangesD.iloc[-10:]. See example.
context.account.leverage is gross leverage.
See what you think. Do check my logic.