Giter Site home page Giter Site logo

ffn's People

Contributors

allensususu avatar anjum48 avatar bbergua avatar brandon-rhodes avatar cal97g avatar changlan avatar degiere avatar dependabot[bot] avatar finquest avatar fuckqqcom avatar geweiliang avatar guypago avatar johnsloper avatar jordanplatts avatar leogregianin avatar mirca avatar nathanramoscfa avatar noodlefrenzy avatar oldrichsmejkal avatar pmorissette avatar pratapvardhan avatar roryglenn avatar rubik avatar sfjep avatar simjason avatar sven337 avatar timkpaine avatar viktormalesevic avatar zhuoqiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffn's Issues

Bug: Yearly Kurtosis

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

"ZeroDivisionError: float division by zero" when calculating PerformanceStats.yearly_sharpe if all values in timeseries are same

Hey there!

In the following lines:

self.yearly_vol = yr.std()
self.yearly_sharpe = ((self.yearly_mean - self._yearly_rf) / self.yearly_vol)

self.yearly_vol is type 'float' instead of type 'numpy.float64' like self.monthly_vol and self.daily_vol so when you try to calculate self.yearly_sharpe you get a division by zero error.

I managed a workaround by calculating the yearly volatility like:

self.yearly_vol = yr.std() / np.sqrt(1)

similar to how you calculated the daily and monthly volatility

best,
Spencer

Arguments for performance function

Hi. I am looking to the get performance stats for a Pandas DF of monthly returns. Seems this is not possible -correct? Do you have any plans to add this? (Novice programmer -so please forgive me for the stupid question)

Import error PyQt4

I have used ffn with no issues but after the weekend I suddenly got this error (I'm a python beginner).
`---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in ()
----> 1 import ffn

C:\Anaconda2\lib\site-packages\ffn_init_.py in ()
----> 1 from . import core
2 from . import data
3
4 from .data import get
5 #from .core import year_frac, PerformanceStats, GroupStats, merge

C:\Anaconda2\lib\site-packages\ffn\core.py in ()
8 from pandas.core.base import PandasObject
9 from tabulate import tabulate
---> 10 from matplotlib import pyplot as plt
11 import sklearn.manifold
12 import sklearn.cluster

C:\Anaconda2\lib\site-packages\matplotlib\pyplot.py in ()
112
113 from matplotlib.backends import pylab_setup
--> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
115
116 _IP_REGISTERED = None

C:\Anaconda2\lib\site-packages\matplotlib\backends_init_.pyc in pylab_setup()
30 # imports. 0 means only perform absolute imports.
31 backend_mod = import(backend_name,
---> 32 globals(),locals(),[backend_name],0)
33
34 # Things we pull in from all backends

C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt4agg.py in ()
16
17
---> 18 from .backend_qt5agg import FigureCanvasQTAggBase as _FigureCanvasQTAggBase
19
20 from .backend_agg import FigureCanvasAgg

C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5agg.py in ()
13
14 from .backend_agg import FigureCanvasAgg
---> 15 from .backend_qt5 import QtCore
16 from .backend_qt5 import QtGui
17 from .backend_qt5 import FigureManagerQT

C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5.py in ()
29 figureoptions = None
30
---> 31 from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, version
32 from matplotlib.backends.qt_editor.formsubplottool import UiSubplotTool
33

C:\Anaconda2\lib\site-packages\matplotlib\backends\qt_compat.py in ()
122 # have been changed in the above if block
123 if QT_API in [QT_API_PYQT, QT_API_PYQTv2]: # PyQt4 API
--> 124 from PyQt4 import QtCore, QtGui
125
126 try:

ImportError: No module named PyQt4`

Python ffn package - bug in calc_stats()

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!

import error

I use the

ffn                       0.1.9                     <pip>

I try to import ffn

import ffn

Then it shows the error

In [1]: import ffn
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-30624921af03> in <module>()
----> 1 import ffn

/opt/anaconda/envs/py27matt/lib/python2.7/site-packages/ffn/__init__.py in <module>()
----> 1 from . import core
      2 from . import data
      3
      4 from .data import get
      5 #from .core import year_frac, PerformanceStats, GroupStats, merge

/opt/anaconda/envs/py27matt/lib/python2.7/site-packages/ffn/core.py in <module>()
      1 from __future__ import print_function
----> 2 from future.utils import listvalues
      3 import random
      4 from . import utils
      5 from .utils import fmtp, fmtn, fmtpn, get_period_name

ImportError: No module named future.utils

TypeError: last() takes exactly 2 arguments (1 given)

Trying to run the first example from bt and getting the following error in ffn:

  File "/home/dan/.virtualenvs/landscape/lib/python2.7/site-packages/ffn/core.py", line 1087, in calc_perf_stats
    return PerformanceStats(prices)

  File "/home/dan/.virtualenvs/landscape/lib/python2.7/site-packages/ffn/core.py", line 65, in __init__
    self._update(self.prices)

  File "/home/dan/.virtualenvs/landscape/lib/python2.7/site-packages/ffn/core.py", line 84, in _update
    self._calculate(obj)

  File "/home/dan/.virtualenvs/landscape/lib/python2.7/site-packages/ffn/core.py", line 165, in _calculate
    self.daily_prices = obj.resample('D').last()

TypeError: last() takes exactly 2 arguments (1 given)

Is this supposed to be calling last() from pandas (which seems to require an offset argument)?

ImportError with pandas 0.23 pandas-datareader 0.6

ImportError with pandas 0.23 pandas-datareader 0.6

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-9d4b951d98c0> in <module>()
----> 1 import ffn

~/anaconda3/lib/python3.6/site-packages/ffn/__init__.py in <module>()
      1 from . import core
----> 2 from . import data
      3 
      4 from .data import get
      5 #from .core import year_frac, PerformanceStats, GroupStats, merge

~/anaconda3/lib/python3.6/site-packages/ffn/data.py in <module>()
      3 from . import utils
      4 import pandas as pd
----> 5 from pandas_datareader import data as pdata
      6 
      7 

~/anaconda3/lib/python3.6/site-packages/pandas_datareader/__init__.py in <module>()
      1 from ._version import get_versions
----> 2 from .data import (DataReader, Options, get_components_yahoo,
      3                    get_dailysummary_iex, get_data_enigma, get_data_famafrench,
      4                    get_data_fred, get_data_google, get_data_moex,
      5                    get_data_morningstar, get_data_quandl, get_data_stooq,

~/anaconda3/lib/python3.6/site-packages/pandas_datareader/data.py in <module>()
     12     ImmediateDeprecationError
     13 from pandas_datareader.famafrench import FamaFrenchReader
---> 14 from pandas_datareader.fred import FredReader
     15 from pandas_datareader.google.daily import GoogleDailyReader
     16 from pandas_datareader.google.options import Options as GoogleOptions

~/anaconda3/lib/python3.6/site-packages/pandas_datareader/fred.py in <module>()
----> 1 from pandas.core.common import is_list_like
      2 from pandas import concat, read_csv
      3 
      4 from pandas_datareader.base import _BaseReader
      5 

ImportError: cannot import name 'is_list_like'

Starting with returns.

Hi All,

Having looked at FFN I'm keen to try it out to see the performance statistics of my trading strategy, however it looks like the I can only start with prices rather than returns.

How can I use FFN with the returns from my trading strategy (a basic example would be amazing) ?

D

RemoteDataError: Unable to read URL

Hi,

I am running this on Python 3.5:
ffn.get('aapl,msft,c,gs,ge', start='2010-01-01').to_returns().dropna()

But I get the folllowing error:
RemoteDataError: Unable to read URL: http://ichart.finance.yahoo.com/table.csv?f=2017&g=d&e=20&c=2010&d=2&s=aapl&a=0&b=1&ignore=.csv

Any ideas of how to solve this? Thanks.

Import Error cannot import name 'core' from 'numpy' on Jupyter Notebook

Hi guys, i'm a student who is totally new to Python3 and have no previous experience in coding. I installed Anaconda 3.7 Python and opened Jupyter Notebook to do some of my work. While i was trying to import Numpy, this error popped up at the bottom.

ImportError: cannot import name 'core' from 'numpy'

I've tried to look everywhere but it hasn't got any luck.

ffn.core.to_monthly not picking the last month?

Hi,firstly i want to say thank you! this is an awesome package for financial researchers.

This is my code -

from pandas.io.data import DataReader
import ffn
moat=DataReader('MOAT','yahoo').reset_index().loc[:,['Date','Adj Close']].set_index('Date')
moat=moat[moat.index<='31-aug-2014']
moat.tail()
ffn.core.to_monthly(moat).tail()

my question is, why do we not see the August data after converting to monthly?

after upgrade to pandas 0.22 break ffn, reverting to 0.21 - ffn is OK


TypeError Traceback (most recent call last)
pandas/index.pyx in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990)()

pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589)()

TypeError: an integer is required

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/indexes/base.py in get_loc(self, key, method, tolerance)
1944 try:
-> 1945 return self._engine.get_loc(key)
1946 except KeyError:

pandas/index.pyx in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140)()

pandas/index.pyx in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046)()

pandas/index.pyx in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210)()

KeyError: 'next'

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
pandas/index.pyx in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990)()

pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589)()

TypeError: an integer is required

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/tseries/index.py in get_loc(self, key, method, tolerance)
1430 try:
-> 1431 return Index.get_loc(self, key, method, tolerance)
1432 except (KeyError, ValueError, TypeError):

~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/indexes/base.py in get_loc(self, key, method, tolerance)
1946 except KeyError:
-> 1947 return self._engine.get_loc(self._maybe_cast_indexer(key))
1948

pandas/index.pyx in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140)()

pandas/index.pyx in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046)()

pandas/index.pyx in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210)()

KeyError: 'next'

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
ValueError: Error parsing datetime string "next" at position 0

The above exception was the direct cause of the following exception:

SystemError Traceback (most recent call last)
in ()
1 portshow=port #[port.index < pd.to_datetime(date(2017, 1, 1)) ]
2
----> 3 stats = portshow[['close','spy_close','qqq_close']].calc_stats()
4 print(portshow['close'].calc_total_return()*100)
5 print(portshow['close'].calc_cagr()*100)

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in calc_stats(prices)
1040 return PerformanceStats(prices)
1041 elif isinstance(prices, pd.DataFrame):
-> 1042 return GroupStats(*[prices[x] for x in prices.columns])
1043 else:
1044 raise NotImplementedError('Unsupported type')

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in init(self, *prices)
644 self._end = self._prices.index[-1]
645 # calculate stats for entire series
--> 646 self._update(self._prices)
647
648 def getitem(self, key):

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in _update(self, data)
653
654 def _update(self, data):
--> 655 self._calculate(data)
656 # lookback returns dataframe
657 self.lookback_returns = pd.DataFrame(

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in _calculate(self, data)
666 for c in data.columns:
667 prc = data[c]
--> 668 self[c] = PerformanceStats(prc)
669
670 def _stats(self):

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in init(self, prices, rf)
61 self.rf = rf
62
---> 63 self._update(self.prices)
64
65 def set_riskfree_rate(self, rf):

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in _update(self, obj)
80 def _update(self, obj):
81 # calc
---> 82 self._calculate(obj)
83
84 # update derived structure

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in _calculate(self, obj)
189 self.daily_vol = r.std() * np.sqrt(252)
190 self.daily_sharpe = r.calc_sharpe(rf=self.rf, nperiods=252)
--> 191 self.daily_sortino = calc_sortino_ratio(r, rf=self.rf, nperiods=252)
192 self.best_day = r.max()
193 self.worst_day = r.min()

~/anaconda3/envs/newenv/lib/python3.6/site-packages/ffn/core.py in calc_sortino_ratio(returns, rf, nperiods, annualize)
1981
1982 er = returns.to_excess_returns(rf, nperiods=nperiods)
-> 1983 res = er.mean() / er[er < 0].std()
1984
1985 if annualize:

~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/core/series.py in getitem(self, key)
616 raise
617
--> 618 if com.is_iterator(key):
619 key = list(key)
620

~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/core/common.py in is_iterator(obj)
1447 def is_iterator(obj):
1448 # python 3 generators have next instead of next
-> 1449 return hasattr(obj, 'next') or hasattr(obj, 'next')
1450
1451

~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/core/generic.py in getattr(self, name)
2668 return object.getattribute(self, name)
2669 else:
-> 2670 if name in self._info_axis:
2671 return self[name]
2672 return object.getattribute(self, name)

~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/tseries/base.py in contains(self, key)
182 def contains(self, key):
183 try:
--> 184 res = self.get_loc(key)
185 return lib.isscalar(res) or type(res) == slice or np.any(res)
186 except (KeyError, TypeError, ValueError):

~/anaconda3/envs/newenv/lib/python3.6/site-packages/pandas/tseries/index.py in get_loc(self, key, method, tolerance)
1437
1438 try:
-> 1439 stamp = Timestamp(key, tz=self.tz)
1440 return Index.get_loc(self, stamp, method, tolerance)
1441 except (KeyError, ValueError):

pandas/tslib.pyx in pandas.tslib.Timestamp.new (pandas/tslib.c:9203)()

pandas/tslib.pyx in pandas.tslib.convert_to_tsobject (pandas/tslib.c:24653)()

pandas/tslib.pyx in pandas.tslib.convert_str_to_tsobject (pandas/tslib.c:26273)()

pandas/src/datetime.pxd in datetime._string_to_dts (pandas/tslib.c:85631)()

SystemError: <class 'str'> returned a result with an error set

ffn.core.calc_erc_weights: Define lookback period for risk weights

is maximum_iterations the look back period for defining risk weights? default of 100 equal to last 100 days?

ffn.core.calc_erc_weights(returns, initial_weights=None, risk_weights=None, covar_method='ledoit-wolf', risk_parity_method='ccd', maximum_iterations=100, tolerance=1e-08)

Handling non-daily data (proposition for ffn/core.py)

Hi, and before anything thanks a lot for this great library!

As I have used the package a lot recently, I realized that the .stats object (as opposed to the .display()) gives weird results when given something else than daily data. I gave it monthly data, and then due to line 103 .dropduplicates in ffn/core.py, "best_month" would disappear, and the wished result would be in "best_day" (among other examples).

To overcome this type of issues I propose these changes in the ffn/core.py

Line 103:
[x[0] for x in st if x[0] is not None])
Just deleting the .dropdupplicates()

Line 166:
self.daily_prices = obj.resample('D').last()
_Instead of self.daily_prices = obj _

Line 173:
p = self.daily_prices
Instead of p = obj

With these changes it now gives NaN for all daily figures when given something else than daily data.
And there is no risk of loosing a useful row in the .stats object anymore if two values happen to be identical.

Only drawback: .stats seem to have "yearly_sharpe" twice now, and due to the .resample('D').last() we might be slightly decreasing the execution speed.

Thanks again for this great package!

Yahoo changed their returned field values breaking ffn.get() for Yahoo

pandas-datareader 0.7.0 (released today) fixes the latest Yahoo data breakage, but Yahoo is now using new field values which breaks ffn.get(). For instance, 'Adj Close' changed to 'adjclose'. I replaced the two references to 'Adj Close' with 'adjclose' in data.py and now ffn.get() returns data, but the dataframe is only number indexed rather than date indexed. It's my first day with ffn so I'm not sure what typical behavior is, but I was just comparing my results to the examples and saw this discrepancy.

Bugs in class PerformanceStats

First, thank all the contributors of ffn and bt!

There is a typo in class PerformanceStats -
Line 395 in ffn/core.py
"('yearly_sharpe', 'Yearly Sortino', 'n'),"
The short name should be "yearly_sortino"

Besides, in class PerformanceStats def _create_stats_series -
Line 586 in ffn/core.py
"pd.Series(values, short_names).drop_duplicates()"
Using drop_duplicates() here directly may be problematic -
Consider when ytd = 0.1 and mtd = 0.1 as well. The row "mtd = 0.1" will be dropped.

FTCA is broken with the latest Pandas

The calc_ftca method currently fails with the following exception:

'Series' object has no attribute 'order'

The error can be fixed by replacing order with sort_values here:

ffn/ffn/core.py

Lines 1746 to 1751 in 7a42003

cur_corr = corr[remain].ix[remain]
# get mean correlations, ordered
mc = cur_corr.mean().order()
# get lowest and highest mean correlation
low = mc.index[0]
high = mc.index[-1]

error again due to invalid negative value

I moved to pyCharm and using ffn now to make equity curves etc...
Receive this error again that i used to in jupyter but that went away. What do i need to do when i run in pyCharm:

C:\Users.....\venv\lib\site-packages\ffn\core.py:2054: RuntimeWarning: invalid value encountered in minimum
negative_returns = np.minimum(returns, 0.)

wrong version on pip

Hi,

I downloaded version 0.3.4 via PIP but it isn't the same code as on github. For example, it is missing the new "data frequency" feature (around line 190 of core.py)

Cheers

module 'pandas' has no attribute 'scatter_matrix'

I have just tried to rerun some code I wrote previously that worked at the time (March 2018) and now I receive an error.

When trying to use the ".plot_scatter_matrix()" method I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-69af71d84436> in <module>
----> 1 perf.plot_scatter_matrix()

~\.conda\envs\report_bt\lib\site-packages\ffn\core.py in plot_scatter_matrix(self, freq, title, figsize, **kwargs)
    915         plt.figure()
    916         ser = self._get_series(freq).to_returns().dropna()
--> 917         pd.scatter_matrix(ser, figsize=figsize, **kwargs)
    918         return plt.suptitle(title)
    919 

AttributeError: module 'pandas' has no attribute 'scatter_matrix'

<Figure size 432x288 with 0 Axes>

The code that causes the issue is as follows:

import pandas as pd
import ffn

%matplotlib inline

import pandas_datareader.data as web

stocks = ['AAPL','AMZN','MSFT','NFLX']

data = web.DataReader(stocks,data_source='yahoo',start='01/01/2010')['Adj Close']

data.sort_index(ascending=True,inplace=True)

perf = data.calc_stats()

perf.plot_scatter_matrix()

Relevant packages used in environment:

numpy==1.16.3
pandas==0.24.2
pandas-datareader==0.7.0
ffn==0.3.4
matplotlib==3.1.0

Is this something that is known about, or something that is being caused by an incorrect module version etc.?

This link (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.plotting.scatter_matrix.html) seems to suggest it could be because the "scatter_matrix" method is under "pandas.plotting" rather than just "pandas". Could that be the cause?

Return stats in absolute instead of % terms for fixed income strategies

I have been writing some strategies for fixed income products which generally look at absolute returns in terms of basis points (with 0 starting capital) instead of % points with a starting capital of 1. Is there a way to calculate all the return metrics in FFN using absolute returns?

It's unclear that ffn injects new methods into pandas objects

I was just wondering what magic I had to do to get an ffn data object, because I wanted to use df.calc_stats - had to read some source and google before I realised that you inject new methods into pandas.

We can save people time by making this apparent in the documentation.

Getting a runtime error on data.calc_stats()

I am using Python 3.7 and I am getting this error when I try to run the calc_stats() method.
C:\Python_3.7\lib\site-packages\ffn\core.py:2054: RuntimeWarning: invalid value encountered in minimum
negative_returns = np.minimum(returns, 0.)
Can you help me out? I really like the library.
Thanks.

Replacing ffn with empyrical and pyfolio

Maybe we should just use empyrical and pyfolio instead of ffn.
@pmorissette @FinQuest What do you guys think?

They seem similar and they have a strong community already. empyrical can replace the generic functions in ffn and pyfolio can replace PerformanceStats. We could still use ffn for calculations that they don't include like calc_mean_var_weights or calc_erc_weights but we wouldn't have to worry about maintaining the portfolio statistics or plots. Over time we could see about contributing any functionality they don't include into their libraries.

I still prefer bt over zipline because it is easier to understand and verify the functionality is correct. Trusting the backtesting tool is essential if you are going to use the results to put money to work.

computing annualized stats assuming different number of days per year

It seems that my daily data is being annualized assuming 252 days in the year. I'm wondering if it's possible to annualize using 365 days

It looks like thee annualize function in the core module is capable of annualizing daily data based on a varying number of days in the year -- with the one_year param. However, when instantiating a GroupStats or PerformanceStats I don't se an option for specifying the number of days per year to use for annualization.

I see an attribute of GroupStats or PerformanceStats named one_year in the source code, but it looks like this might not refer to the days per year for annualization. I also don't think it would be smart to set this explicitly then recalc the stats (something like the below)?

ps = PerformanceStats(prices)
ps.one_year = 365
ps._update()

ps.display()

Thank you!

Install error

when I install ffn, there's a error:

(base) E:\Python\ffn>python -m pip install -e .
Obtaining file:///E:/Python/quantaxis/ffn
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "E:\Python\quantaxis\ffn\setup.py", line 16, in <module>
        re.MULTILINE
    AttributeError: 'NoneType' object has no attribute 'groups'

then I found this function has a problem:

In [8]: local_file('ffn/__init__.py').read()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-cb625aa46290> in <module>()
----> 1 local_file('ffn/__init__.py').read()

<ipython-input-2-b4939a16acc3> in local_file(filename)
      1 def local_file(filename):
      2     return codecs.open(
----> 3         os.path.join(os.path.dirname(__file__), filename), 'r', 'utf-8'
      4     )

NameError: name '__file__' is not defined

so I modify the function local_file

def local_file(filename):
    return open(
        os.path.join(os.path.dirname(__file__), filename), 'r', encoding='utf-8'
    )

then the installing is ok.

Can't import data

Hi, I am new to python and I am trying to figure out ffn. However, when I try one of the examples I get an error that says ffn has no attribute data. Can someone please help with this?

bug in sortino ratio algorithm

according to wiki, sortino should be calculated as:

    negative_returns = np.minimum(daily_returns, 0)
    return np.mean(daily_returns) / np.std(negative_returns, ddof=1) * np.sqrt(period)

something wrong with pic

I found the perf.plot() got something wrong with the pic.
that is an example.

SSE50CLOSE.head is larger than SSE50CLOSE.tail, but the pic doesnot correctly show this.

data.head():
AHCLOSE SSE50CLOSE AH-50 HSCEICLOSE
date
2010-01-04 00:00:00.005 4479.3079 2514.646 0.300000 12750.55
2010-01-05 00:00:00.005 4549.3529 2543.991 0.303968 13142.03
2010-01-06 00:00:00.005 4519.9358 2514.014 0.309321 13246.21
2010-01-07 00:00:00.005 4442.2438 2463.758 0.311962 13073.20
2010-01-08 00:00:00.005 4444.8397 2466.165 0.311584 13035.09

data.tail()
AHCLOSE SSE50CLOSE AH-50 HSCEICLOSE
date
2017-02-09 00:00:00.005 5361.2946 2354.9009 0.560428 10075.17
2017-02-10 00:00:00.005 5382.9735 2368.1834 0.559986 10125.21
2017-02-13 00:00:00.005 5433.5871 2379.3057 0.566862 10257.84
2017-02-14 00:00:00.005 5425.7344 2373.5138 0.567413 10254.44
2017-02-15 00:00:00.005 5469.0834 2372.1920 0.577616 10436.04

figure_7

Pandas DataReader Errors??!!?

When trying to do a simple test and retrieve market data, I get an error something to the order of "change import pandas.io.data to import pandas_datareader". I believe this error comes from the fact that pandas has updated the way that the datareader is imported!

So "ffn" is unusable with the current update of pandas. To fix this, I navigated to the "data.py" file in the ffn folder of python and changed line 4 to "import pandas_datareader.data as pdata" then changed line 113 to "return pdata.DataReader(name, **kwargs)". After that, everything works as it should!

Simple fix, thought I should leave a comment for anybody else who might stumble upon this!

Returns input

I' like to pass to ffn a strategy returns in order to calculate performance metrics.
How is possible?

Many thanks
t

Different ways of pulling in calc_stats/performance stats

Hi,
I see how once
perf = data.calc_stats,
perf.plot() shows the equity curve and if you do
perf.display() you get all the stats in a table.

As this table is not very easy to read, I'd like to express it in the form of a visual manner.
Perhaps say you have 5 assets and they have all these stats, but i'd like to see side -by-side histogram of the sharpe ratios say in one graph or any other stat. How would i perform this manipulation?

whl download file

Would it be possible to upload a whl download file? I use it a lot but cant seem to download on my new PC without the a wheel file?

Documentation: Links to term explainers?

Hey, I'm using your library as a method to learn various fintech methods and experiment, and have been reading your documentation and spending time looking up various terms in Investopedia. I think it'd be useful to have links from your documentation directly to explanations of the various terms (e.g. Calman Ratio).

I'm willing to do the work and submit the PR, but wanted to check with you first whether that's something you would appreciate/find useful.

Can't import ffn

How come I can't import ffn? It says cannot import name 'is_list_like'. Thanks.

image

PerformanceStats ".monthly_returns" fails to work if a whole month is missing data

Hi,

Firstly, LOVE this package - it has been a god send to me so many thanks for your hard work and choosing to share it with us all.

I have noticed what I believe to be a "bug" with the ".monthly_returns" when used on certain input data and with a PerformanceStats object.

When using daily periodicity data (or intra-day) as a base input to the PerformanceStats object, if there is a whole calendar month period without a corresponding entry in the series (or more than one month in a row), the resulting data returned seems to be incorrect/incomplete.

I have provided two csv input files and a Jupyter notebook that replicates the 2 issues I have found, with further explanation within.

I may be missing something my end which is causing this, but I do believe it to be a legitimate "bug".
ffn_bug_examples.zip

resample() error

I'm running python 2.7 and I'm not sure if this has something to do with it.. But I'm having an issue with the "core.py" file. Not sure what part of ffn is calling "core.py" but its having a problem with the resample() function. Apparently the "how" part of the function has been replaced with a new syntax. After looking at the documentation, I was able to fix this problem by navigating to the "core.py" file in ffn of the python folder and change lines 189 & 191 to: (respectively)

self.monthly_prices = obj.resample('M').last()

self.monthly_prices = obj.resample('A').last()

Runtime error

I am running the calc_stats() function on my data frame whihc seems to be formatted correctly and has no errors ( i tried it on the 297 lines of data then 50 then 10, errors on all the different frames), i get the following error:
C:\ProgramData\Anaconda3\lib\site-packages\ffn\core.py:2054: RuntimeWarning: invalid value encountered in minimum
negative_returns = np.minimum(returns, 0.)

I am not very proficient in Python but i have done my best to see whats wrong with the data and it all looks clean. I am not using Yahoo data as the data retrieval that ffn is using also fails me, so I created my own data from elsewhere.
Pls help as this would be very valuable to my project.

Thanks

Add Calmar Ratio

Would it be worthwhile to add the Calmar Ratio? I think this is just simply CAGR/Max drawdown

Maybe the Sortino ratio could be useful too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.