Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinearFactorModels: Issue when number of portfolios larger than number of observations #173

Closed
matbuechner opened this issue Oct 7, 2018 · 2 comments

Comments

@matbuechner
Copy link

I have been running into a problem when using the LinearFactorModel functionality, that only appears to occur when the number of portfolios is larger than the number of observations per portfolio. The error message pertains to a constant being present (which should not be the case here). My guess is that the has_constant util delivers a faulty output in this use case. The error received is the following:

File ".../anaconda3/lib/python3.6/site-packages/linearmodels/asset_pricing/model.py", line 331, in __init__ super(LinearFactorModel, self).__init__(portfolios, factors) File ".../anaconda3/lib/python3.6/site-packages/linearmodels/asset_pricing/model.py", line 67, in __init__ self._validate_data() File ".../anaconda3/lib/python3.6/site-packages/linearmodels/asset_pricing/model.py", line 102, in _validate_data raise ValueError('portfolios must not contains a constant or equivalent.') ValueError: portfolios must not contains a constant or equivalent.

To aid the debugging, I have constructed a minimal example. Please see below:

import pandas as pd
import numpy as np
from linearmodels.asset_pricing import LinearFactorModel
PF = pd.read_pickle('testPFs.pkl')
factors = pd.read_pickle('testfactors.pkl')

model = LinearFactorModel(PF,factors)
modelres = model.fit()

The necessary data is made available at the following location: https://www.dropbox.com/sh/h6iwxw8t6h0njig/AABcguLzp7XrmSXJ8wuYdygja?dl=0

Any help is very appreciated!

bashtage added a commit that referenced this issue Oct 7, 2018
Fix has_constant to work with fewer observations and columns
Change dimension checks to reflect actual requirements

closes #173
bashtage added a commit that referenced this issue Oct 8, 2018
Fix has_constant to work with fewer observations and columns
Change dimension checks to reflect actual requirements

closes #173
@bashtage
Copy link
Owner

bashtage commented Oct 8, 2018

Thanks. I've fixed this in master. The rank checks weren't correct for asset pricing models -- looked like a bit of copy/paste logic from more standard regressions.

@matbuechner
Copy link
Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants