Open andreas-vester opened 12 months ago
Fees and slippage aren't taken into account when target percentage is translated into number of shares in order to satisfy the 100% portfolio value requirement. Thus, you short buy slightly more than you can afford (you can see this when you print the allocation with pf.asset_value() / pf.value()
).
@polakowo
Thus, you short buy slightly more than you can afford
I don't fully understand this. Do you mind to elaborate?
Still, no matter how you treat fees/slippage in the first place, I feel that long_only
and short_only
returns should add up to both
returns.
Coming back to my example above (periods marked in yellow in the second dataframe), if I am only invested on the short_only
side, the return in these specific periods will solely be responsible for the overall (both
) portfolio return, won't it?
If my only portfolio position is to be short one asset and this asset looses 5% in a single period, then I expect my return on the short_only
side to be +5%. As this is my only position, the portfolio return should be equally +5%, shouldn't it?
@polakowo Any thoughts?
@polakowo is this a bug?
I created a simple test strategy (SMA crossover). I set it up so that
long_only
,short_only
andboth
can be analyzed.When analyzing the periodic returns, I stumbled upon the fact that the sum of periodic
long_only
andshort_only
returns doesn't always equal the correspondingboth
returns.Here are some daily returns where the above assumption is true:
However, as soon as I introduce fees or slippage, the
short_only
side doesn't correspond to theboth
side (and we are not talking about rounding issues), whilelong_only
looks quite reasonable.Am I missing something? Is this a bug / incorrect computation?
Here's the code to reproduce the issue: