Repository navigation
BUG: Raise a ValueError if LinearFactorModelGMM has too few observations - #807
Merged
Merged
Conversation
LinearFactorModelGMM has nportfolio * (nfactor + 1) + nfactor moment conditions. Their covariance weights the moment conditions, and it is singular unless there are more observations than moment conditions. The estimator then raised "LinAlgError: Singular matrix", or returned a J-statistic that was NaN or arbitrary, such as -4.6e35 with 5 portfolios, 2 factors and 6 observations. It also raised a bare ZeroDivisionError with as many observations as factors plus one. The model now raises a ValueError when it is created if the number of observations, after the observations with missing values are dropped, does not exceed the number of moment conditions. The message gives both numbers and the way the number of moment conditions is computed. With the default centering of the moment conditions the covariance is singular for as many observations as moment conditions, and it is not for one more, which is the boundary that the tests check, with and without an estimated risk-free rate. Fewer observations were never enough, and more observations than this are not changed. The docstring of the model gives the number of moment conditions and the requirement.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #807 +/- ##
==========================================
+ Coverage 99.62% 99.66% +0.03%
==========================================
Files 143 161 +18
Lines 28244 30653 +2409
Branches 1985 2099 +114
==========================================
+ Hits 28138 30550 +2412
+ Misses 41 40 -1
+ Partials 65 63 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LinearFactorModelGMM has nportfolio * (nfactor + 1) + nfactor moment conditions. Their covariance weights the moment conditions, and it is singular unless there are more observations than moment conditions. The estimator then raised "LinAlgError: Singular matrix", or returned a J-statistic that was NaN or arbitrary, such as -4.6e35 with 5 portfolios, 2 factors and 6 observations. It also raised a bare ZeroDivisionError with as many observations as factors plus one.
The model now raises a ValueError when it is created if the number of observations, after the observations with missing values are dropped, does not exceed the number of moment conditions. The message gives both numbers and the way the number of moment conditions is computed. With the default centering of the moment conditions the covariance is singular for as many observations as moment conditions, and it is not for one more, which is the boundary that the tests check, with and without an estimated risk-free rate. Fewer observations were never enough, and more observations than this are not changed.
The docstring of the model gives the number of moment conditions and the requirement.