2525 GMMFactorModelResults ,
2626 LinearFactorModelResults ,
2727)
28+ from linearmodels .iv .covariance import KERNEL_LOOKUP
2829from linearmodels .iv .data import IVData , IVDataLike
2930from linearmodels .shared import hypotheses
3031from linearmodels .shared .alignment import check_alignment , row_labels
31- from linearmodels .shared .exceptions import missing_warning , unknown_option_error
32+ from linearmodels .shared .exceptions import (
33+ check_cov_config ,
34+ lower_option ,
35+ missing_warning ,
36+ unknown_option_error ,
37+ )
3238from linearmodels .shared .hypotheses import WaldTestStatistic
3339from linearmodels .shared .linalg import has_constant
3440from linearmodels .shared .rsquared import r_squared
3844
3945# The names of the covariance estimators of the models
4046COV_TYPES = ("heteroskedastic" , "kernel" , "robust" )
47+ _COV_KEYS = {"heteroskedastic" : (), "robust" : (), "kernel" : ("kernel" , "bandwidth" )}
4148
4249
4350def callback_factory (
@@ -422,7 +429,7 @@ def fit(
422429 Parameters
423430 ----------
424431 cov_type : {"robust", "heteroskedastic", "kernel"}, optional
425- Name of covariance estimator. The names are case sensitive. The
432+ Name of covariance estimator. The names are not case sensitive. The
426433 default is "robust". "heteroskedastic" is the same as "robust".
427434 debiased : bool, optional
428435 Flag indicating whether to debias the covariance estimator using
@@ -446,6 +453,11 @@ def fit(
446453 If ``debiased`` is True and the number of observations is not larger
447454 than the number of factors plus one, or if the bandwidth is selected
448455 from the data and there are too few observations. See Notes.
456+ ValueError
457+ If a key of ``cov_config`` is not accepted by the covariance estimator
458+ that ``cov_type`` selects. The message names the key and lists the
459+ accepted keys. It is raised before the model is estimated. Releases
460+ before 7.1 ignored the key.
449461
450462 Notes
451463 -----
@@ -492,6 +504,8 @@ def fit(
492504 alphas and the loadings, ``risk_premia_se`` and the covariance with
493505 ``debiased=False`` do not change.
494506 """
507+ cov_type = lower_option (cov_type )
508+ check_cov_config (cov_config , cov_type , _COV_KEYS , KERNEL_LOOKUP )
495509 self ._check_debiased (debiased )
496510 p = self .portfolios .ndarray
497511 f = self .factors .ndarray
@@ -933,7 +947,7 @@ def fit(
933947 Parameters
934948 ----------
935949 cov_type : {"robust", "heteroskedastic", "kernel"}, optional
936- Name of covariance estimator. The names are case sensitive. The
950+ Name of covariance estimator. The names are not case sensitive. The
937951 default is "robust". "heteroskedastic" is the same as "robust".
938952 debiased : bool, optional
939953 Flag indicating whether to debias the covariance estimator using
@@ -957,6 +971,11 @@ def fit(
957971 If ``debiased`` is True and the number of observations is not larger
958972 than the number of factors plus one, or if the bandwidth is selected
959973 from the data and there are too few observations. See Notes.
974+ ValueError
975+ If a key of ``cov_config`` is not accepted by the covariance estimator
976+ that ``cov_type`` selects. The message names the key and lists the
977+ accepted keys. It is raised before the model is estimated. Releases
978+ before 7.1 ignored the key.
960979
961980 Notes
962981 -----
@@ -972,6 +991,8 @@ def fit(
972991 the kernel with fewer observations. See
973992 :func:`~linearmodels.iv.covariance.kernel_optimal_bandwidth`.
974993 """
994+ cov_type = lower_option (cov_type )
995+ check_cov_config (cov_config , cov_type , _COV_KEYS , KERNEL_LOOKUP )
975996 nobs , nf , nport , _ , s1 , s2 , s3 = self ._boundaries ()
976997 excess_returns = not self ._risk_free
977998 self ._check_debiased (debiased )
@@ -1372,7 +1393,7 @@ def fit(
13721393 Maximum number of iterations when minimizing objective. Must be
13731394 positive. The default is 1000.
13741395 cov_type : {"robust", "heteroskedastic", "kernel"}, optional
1375- Name of covariance estimator. The names are case sensitive. The
1396+ Name of covariance estimator. The names are not case sensitive. The
13761397 default is "robust". "heteroskedastic" is the same as "robust".
13771398 debiased : bool, optional
13781399 Flag indicating whether to debias the covariance estimator using
@@ -1404,6 +1425,11 @@ def fit(
14041425 If ``starting`` does not have one element for each parameter, or if
14051426 the bandwidth is selected from the data and there are too few
14061427 observations. See Notes.
1428+ ValueError
1429+ If a key of ``cov_config`` is not accepted by the covariance estimator
1430+ that ``cov_type`` selects. The message names the key and lists the
1431+ accepted keys. It is raised before the model is estimated. Releases
1432+ before 7.1 ignored the key.
14071433
14081434 Notes
14091435 -----
@@ -1420,6 +1446,8 @@ def fit(
14201446 observations. See
14211447 :func:`~linearmodels.iv.covariance.kernel_optimal_bandwidth`.
14221448 """
1449+ cov_type = lower_option (cov_type )
1450+ check_cov_config (cov_config , cov_type , _COV_KEYS , KERNEL_LOOKUP )
14231451
14241452 nobs , n = self .portfolios .shape
14251453 k = self .factors .shape [1 ]
0 commit comments