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