Hello.
After a few days grinding on this issue I'm stumped.
Basic question, how do I maintain an existing position's size(NUMBER of shares when the trade was originally put on) using order_optimal_portfolio()?
Put another way, if I already have some trades on and I want to place more trades(different stocks) at a later point in time, how do I leave the existing trades alone(unchanged)?
Example:
-----Go Long XYZ stock @ 25% of portfolio value on today's open. Let's say that is 100 shares of XYZ stock.
Psuedo code on today's open.
objective = opt.TargetWeights({'XYZ': 0.25})
constraints=[]
order_optimal_portfolio(objective, constraints)
-----Go Long ABC stock @ 25% of portfolio value on tomorrow's close AND hold the XYZ position at it's ORIGINAL size(100 shares).
Psuedo code on tomorrow's close.
objective = opt.TargetWeights({'ABC': 0.25, 'XYZ': 0.25}### 'XYZ': 0.25 isn't what I want
constraints=[]
order_optimal_portfolio(objective, constraints)
Now, if you hold the XYZ position for a month and make several other trades in between opening and closing the XYZ trade, you wind up with more XYZ trades than intended if the original weight is used. That makes sense of course, because as your balance changes and the price of XYZ changes, 25% of your balance will be a different number of shares. opt.TargetWeights re-balances that position by some number of shares every time you hit order_optimal_portfolio.
Here's the big rub. Over a two plus year back test, if your algo trades frequently and trades >100 stocks, these micro trades add up.
In my case, this behavior adds >10,000 trades that my contest algos don't really want to make. This results in all kinds of ghost trades, false turnover rates and a dilution of many of my performance metrics.
I would really appreciate any guidance on this, because it's a really big issue for me and I would guess for others too.
Thank you
Bryan