bsolomon1124 / pyfinance

Python package designed for general financial and security returns analysis.
https://pypi.python.org/pypi/pyfinance
MIT License
325 stars 66 forks source link

Bad ValueError raised in window-length check #12

Closed bsolomon1124 closed 5 years ago

bsolomon1124 commented 5 years ago

Version: 1.2.4

Example:

>>> from pyfinance import ols
>>> data = {"A": [2, 3, 4, 5, 6], "B": [10, 11, 12, 13, 14]}
>>> import pandas as pd
>>> df = pd.DataFrame(data)
>>> rolling = ols.RollingOLS(y=df["B"], x=df["A"], window=3, has_const=False, use_const=False)

ValueError                                Traceback (most recent call last)
<ipython-input-6-b8d3bfa13f07> in <module>
----> 1 rolling = ols.RollingOLS(y=df["B"], x=df["A"], window=3, has_const=False, use_const=False)

.../pyfinance/ols.py in __init__(self, y, x, window, has_const, use_const)
    373                                            use_const=use_const)
    374         self.window = self.n = window
--> 375         self.xwins = utils.rolling_windows(self.x, window=window)
    376         self.ywins = utils.rolling_windows(self.y, window=window)
    377         self.solution = _rolling_lstsq(self.xwins, self.ywins)

.../pyfinance/utils.py in rolling_windows(a, window)
    703     if window > a.shape[0]:
    704         raise ValueError('Specified `window` length of {0} exceeds length of'
--> 705                          ' `a`, {1}.'.format(window, a.shape[0]))
    706     if isinstance(a, (Series, DataFrame)):
    707         a = a.values

ValueError: Specified `window` length of 3 exceeds length of `a`, 1.
bsolomon1124 commented 5 years ago

Closed in d59e7ca