pmorissette / ffn

ffn - a financial function library for Python
pmorissette.github.io/ffn
MIT License
2.03k stars 300 forks source link

Fix for calc_inv_vol_weights() in case of zero volatility #7

Closed vfilimonov closed 9 years ago

vfilimonov commented 9 years ago

If some returns series supplied to calc_inv_vol_weights() are equal to zero, then inverse-volatility will be infinite.

I suggest to remove assets with zero volatility from the portfolio rather than returning a list of zeros (sum of all weights will be also infinite -> individual weights of good assets are equal to zero).

There're three options:

I think the last variant is better: user might expect series of the same structure as the initial dataframe with returns, so dropna() is not good. Also it is consistent with the following situation: if we pass a series of NaN then this weight will be equal to NaN

pmorissette commented 9 years ago

Looks good to me - thanks!