pmorissette / ffn

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

Bug: Yearly Kurtosis #81

Open AnthonyFJGarner opened 5 years ago

AnthonyFJGarner commented 5 years ago

Using 849 data points and 1188 calendar days between start and end, an error is thrown in the calculation of yearly kurtosis. A runtime warning is given as shown below. Adding a day of data solves that problem. For some reason a divide by zero error is caused. No doubt I will find the source of the error but I thought I would report it nonetheless.

start: datetime.date = '2001-10-02' end: datetime.date = '2005-01-02' 1188 days 849 data points \lib\site-packages\ffn\core.py:2056: RuntimeWarning: divide by zero encountered in true_divide res = np.divide(er.mean(), std)

start: datetime.date = '2001-10-02' end: datetime.date = '2005-01-03' 1189 days 850 data points No error occurs

yitelee commented 3 years ago

function calc_sortino_ratio may encounter situations that all given returns are positive, makes the std = 0 and thus the divide by zero error.

    negative_returns = np.minimum(returns[1:], 0.)
    std = np.std(negative_returns, ddof=1)
    res = np.divide(er.mean(), std)
keepcosmos commented 1 year ago

Any update?