Comments (6)
Looks good Brad. Thank you. I really like the rolling functionality - didn't think it was possible to make it this fast!
from pyfinance.
example:
from pyfinance import ols
import pandas as pd
import numpy as np
X = pd.DataFrame(index=list(range(5)), data=list(range(5)), columns=['X'])
Y = pd.DataFrame(index=list(range(5)), data=list(np.arange(0,10,2)+1), columns=['Y'])
window = 2
reg_df = pd.concat([Y, X],axis=1)
rolling_reg = ols.PandasRollingOLS(y=reg_df.iloc[:,0], # Series
x=reg_df.iloc[:,1:], # DataFrame
window=window,
has_const=False,
use_const=False,
names=['Const','X'])
print(rolling_reg.beta)
output:
Const X
1 1.0 2.0
2 1.0 2.0
3 1.0 2.0
4 1.0 2.0
if you try to run without specifying a name for the constant in "names" parameter:
ValueError: Shape of passed values is (2, 4), indices imply (1, 4)
from pyfinance.
Thank you for catching this @prd1 and I'm sorry it's taken me so long to have a look. Hopefully better late than never. It seems to be a legitimate bug. The signature for ols._clean_xy()
is:
def _clean_xy(y, x=None, has_const=False, use_const=True):
However, in ols.RollingOLS.__init__()
, it gets called just as:
def __init__(self, y, x=None, has_const=False, use_const=True):
self.x, self.y, self.k = _clean_xy(y, x)
Noticeably leaving the other two parameters unpassed and so ignoring them.
I'll make a correction, push the updated changes and post a new package version on PyPI.
from pyfinance.
Closed via 5d07d1e and 4d7d7b5 - please let me know if that doesn't clear everything up @prd1. These changes are reflected on PyPI as well.
from pyfinance.
Hi Brad. Sorry still having a couple issues with constants. Using 1.2.1.
Issue1:
from pyfinance import ols
import pandas as pd
import numpy as np
X = pd.DataFrame(index=list(range(5)), data=list(range(5)), columns=['X'])
X.loc[:,'Const'] = 1
Y = pd.DataFrame(index=list(range(5)), data=list(np.arange(0,10,2)+1), columns=['Y'])
reg_df = pd.concat([Y, X],axis=1)
rolling_reg = ols.OLS(y=reg_df.iloc[:,0], # Series
x=reg_df.iloc[:,1:], # DataFrame
has_const=False,
use_const=True,
)
print(rolling_reg.beta)
returns: ValueError: data already contains a constant
As it should. But, executing the same code with has_const = True returns:
ValueError: Data does not contain a constant; specify has_const=False
Issue 2: (I think)
from pyfinance import ols
import pandas as pd
import numpy as np
X = pd.DataFrame(index=list(range(5)), data=list(range(5)), columns=['X'])
# X.loc[:,'Const'] = 1
Y = pd.DataFrame(index=list(range(5)), data=list(np.arange(0,10,2)+1), columns=['Y'])
reg_df = pd.concat([Y, X],axis=1)
rolling_reg = ols.OLS(y=reg_df.iloc[:,0], # Series
x=reg_df.iloc[:,1:], # DataFrame
has_const=False,
use_const=True,
)
print(rolling_reg.beta)
Above does not add a constant. Is it supposed to?
Currently, adding the constant manually and specifying has_const and use_cost both as False will give the desired result with constant.
from pyfinance.
Hi @prd1, thanks for bearing with me here. I've made a few more commits with minor fixes and tests that should correct the issues you pointed out here, too. Current version is 1.2.2 and the commits are 6de1db1 and 5046dd9. Please let me know if this clears everything up, and I'll leave things open til then. Using pip install --upgrade pyfinance
should give you the latest version.
from pyfinance.
Related Issues (18)
- Can't get sample to work HOT 1
- PandasRollingOLS reports ValueError HOT 2
- Bad ValueError raised in window-length check HOT 1
- it does not make sense when calling the property "rsq" and "rsq_adj"
- install error HOT 1
- semi_stdev function is wrong
- RollingOLS unnecesarily implements LRUCache, which causes memory issues with larger objects.
- FreqGroup class seems to be in pandas._libs.tslibs.dtypes HOT 3
- Looking for new project maintainer
- Deprecation warning for file: returns.py line: 124
- KeyError for file: utils.py line: 555
- function "get_anlz_factor" return error
- Testing... some suggestions HOT 2
- Should add option of minimum periods of none when there is a specific window size HOT 1
- Installation via pip doesn't work HOT 1
- min_window option in RollingOLS HOT 3
- random minor fix HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyfinance.