Feature: handle zero ratio in `analyze allocate --rebalance`
rapidleft opened this issue · comments
It can be convenient to set an asset class allocation ratio to 0, for example to exit a position of a certain fund or market segment.
It seems like most lak
commands handle this just fine, however lak analyze allocate --rebalance
does not allow this.
$ lak analyze allocate --account MyBrokerage --rebalance
<...>
AssertionError: Desired ratio of asset class MyZeroAsset cannot be zero.
I think this should work. The MyZeroAsset
asset should be rebalanced to 0 and the funds moved to other assets.
A hacky work around is to set the ratio to to almost zero e.g. 0.00000000000001
.
You are right, allocate doesn't work with 0 ratio.
The issue is that the "relative" ratio doesn't work around 0 as any deviation from 0 => infinite error.
In addition to the hack mentioned above, you can also do lak whatif asset -a MyZeroAsset -$current_balance
to zero out the asset before running lak analyze allocate (lak analyze allocate --account MyBrokerage --rebalance --exclude_assets MyZeroAsset
). Would this be a better solution (hack)?
I do see that this is inconvenient.
rapidleft: Not sure if you are still working on this, do you mind if I try to fix this issue?