skfolio.prior.FactorModel#

class skfolio.prior.FactorModel(loading_matrix_estimator=None, factor_prior_estimator=None, residual_variance=True, higham=False, max_iteration=100)[source]#

Factor Model estimator.

The purpose of Factor Models is to impose a structure on financial variables and their covariance matrix by explaining them through a small number of common factors. This can help overcome estimation error by reducing the number of parameters, i.e. the dimensionality of the estimation problem, making portfolio optimization more robust against noise in the data. Factor Models also provide a decomposition of financial risk into systematic and security-specific components.

Parameters:
loading_matrix_estimatorLoadingMatrixEstimator, optional

Estimator of the loading matrix (betas) of the factors. The default (None) is to use LoadingMatrixRegression which fit the factors using LassoCV on each asset separately.

factor_prior_estimatorBasePrior, optional

The factors prior estimator. It is used to estimate the PriorModel containing the factors expected returns and covariance matrix. The default (None) is to use EmpiricalPrior.

residual_variancebool, default=True

If this is set to True, the diagonal term of the residuals covariance (residuals variance) is added to the factor model covariance.

highambool, default=False

If this is set to True, we use the Higham & Nick (2002) algorithm to find the nearest covariance matrix that is positive semi-definite. It is more accurate but slower that the default clipping method. For more information see cov_nearest.

max_iterationint, default=100

Only used when higham is set to True. Maximum number of iterations of the Higham & Nick (2002) algorithm.

Attributes:
prior_model_PriorModel

The PriorModel.

factor_prior_estimator_BasePrior

Fitted factor_prior_estimator.

loading_matrix_estimator_BaseLoadingMatrix

Fitted loading_matrix_estimator.

n_features_in_int

Number of assets seen during fit.

feature_names_in_ndarray of shape (n_features_in_,)

Names of features seen during fit. Defined only when X has feature names that are all strings.

Methods

fit(X, y, **fit_params)

Fit the Factor Model estimator.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

fit(X, y, **fit_params)[source]#

Fit the Factor Model estimator.

Parameters:
Xarray-like of shape (n_observations, n_assets)

Price returns of the assets.

yarray-like of shape (n_observations, n_factors)

Factors’ returns.

**fit_paramsdict

Parameters to pass to the underlying estimators. Only available if enable_metadata_routing=True, which can be set by using sklearn.set_config(enable_metadata_routing=True). See Metadata Routing User Guide for more details.

Returns:
selfFactorModel

Fitted estimator.

get_metadata_routing()[source]#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.