skfolio.prior.ReturnDistribution#
- class skfolio.prior.ReturnDistribution(mu, covariance, returns, sample_weight=None, factor_model=None)[source]#
Return distribution estimated by a prior estimator.
Prior estimators always return the full universe (all assets that have ever been part of the investment universe). Assets that are not investable at the current point in time (e.g. delisted, not yet listed, warm-up period) are represented with
NaNinmu,covariance, and/orreturns.An asset is considered investable when both
mu[i]andcovariance[i, i]are finite. Theinvestable_maskproperty infers this condition on first access and reconciles warm-up periods across independent moment estimators.NaN values in
returnsare restricted to the columns of non-investable assets. Prior estimators resolve missing observations of investable assets into finite scenario values (for example,EmpiricalPriorzero-fills them), so thatinvestable_subsetreturns fully finite arrays.Use
investable_subsetbefore passing the distribution to downstream routines that operate only on the investable universe.- Attributes:
- mundarray of shape (n_assets,)
Estimation of expected asset returns.
- covariancendarray of shape (n_assets, n_assets)
Estimation of the assets covariance matrix.
- returnsndarray of shape (n_observations, n_assets)
Estimation of the assets returns.
- sample_weightndarray of shape (n_observations,), optional
Sample weights for each observation. If
None, equal weights are assumed.- factor_modelFactorModel, optional
Factor model decomposition and diagnostics. The default is
None.
Methods
investable_subset([slim])Return a
ReturnDistributionrestricted to investable assets.- property covariance_sqrt#
Covariance square root for SOC-based optimization.
When a
FactorModelis available, delegates toFactorModel.covariance_sqrtto exploit the low-rank factor structure. Otherwise, falls back to the Cholesky decomposition ofcovariance.When non-investable assets are represented with
NaNentries and no factor model is available, callers should applyinvestable_subsetfirst.- Returns:
- CovarianceSqrt
- property investable_mask[source]#
Boolean mask where
Truemarks investable assets.The mask is inferred as the intersection of finite
muvalues and a finite diagonal incovariance. ReturnsNonewhen all assets are investable.- Raises:
- ValueError
If no asset is investable (all
NaNinmuand/orcovariance).
- investable_subset(slim=False)[source]#
Return a
ReturnDistributionrestricted to investable assets.- Parameters:
- slimbool, default=False
When
True, heavy diagnostic fields on the nestedFactorModel(e.g.exposures,idio_returns,idio_variances,benchmark_weights) are set toNoneto reduce memory usage. This is typically used by optimization estimators that only needloading_matrix, covariance, and return series.
- Returns:
- subsetReturnDistribution
Distribution over the investable assets only. If all assets are already investable and
slim=False,selfis returned.
- property n_assets#
Total number of assets in the full universe.
- property n_investable_assets#
Number of investable assets.