Hello,
I’ve published my first value strategy. It’s a simple strategy that ranks on ev/ebitda and rebalances annually. I’ve also implemented a simple timing rule that only buys if the 50d MA is greater than the 200d MA, otherwise it buys a bond ETF. I am analyzing the trading activity of the algorithm and have some questions I’m hoping someone can help with.
1) For the trades on 2009-06-02 :
the strategy buys only 343 shares of IEF (the bond ETF) which is much smaller than the actual portfolio value. In the strategy my code first clears existing positions,
#sell existing portfolio
for s in context.portfolio.positions:
#log.info("selling " + s.symbol)
order_target_percent(s,0)
sellcount = sellcount + 1
log.info("sell orders " + str(sellcount))
then places a buy order for IEF
#TODO: Why isn't 100% of portfolio being bought
order_target_percent(context.shy,0.99)
log.info("buying risk free asset")
log.info("portfolio value = " + str(context.account.total_positions_value))
Is there an issue in my order logic which is preventing the entire portfolio (99%) going into IEF?
2) For the trades on 2005-06-02 :
There are 67 transactions, 48 sells from the previous period but only 19 buys even though 49 buy orders are placed (1 order is not placed because there is no data for it). Similarly for ‘2006-06-04’ there are 57 transactions corresponding to 19 sell orders and 38 buy orders despite 50 buy orders being placed.
Not sure what I’m missing, an help would be appreciated. Also any general comments on how to improve the code are welcome.
Regards,
Mark