pmorissette / ffn

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

Python ffn package - bug in calc_stats() #23

Closed cyrpy closed 6 years ago

cyrpy commented 7 years ago

Hello, There seem to be a case where calc_stats() breaks. There is a division by zero which is occuring when the the computation of twelve_month_win_perc occurs.

Here is the example: import ffn data = ffn.get('agg,hyg,spy,eem,efa', start='2010-01-01', end='2014-01-01') data.ix['2012-07':'2013-03'].calc_stats()

If I may I'll tend to amend that this way: tot = 0 win = 0 if len(mr) >11: for i in range(11, len(mr)): tot = tot + 1 if mp[i] / mp[i - 11] > 1: win = win + 1 self.twelve_month_win_perc = float(win) / max(tot,1)

Thank you in advance for your help!