skfolio.optimization.EqualWeighted#

class skfolio.optimization.EqualWeighted(portfolio_params=None)[source]#

Equally Weighted estimator.

Each asset weight is equal to 1/n_assets.

Parameters:
portfolio_paramsdict, optional

Portfolio parameters passed to the portfolio evaluated by the predict and score methods. If not provided, the name, transaction_costs, management_fees, previous_weights and risk_free_rate are copied from the optimization model and passed to the portfolio.

Attributes:
weights_ndarray of shape (n_assets,) or (n_optimizations, n_assets)

Weights of the assets.

Methods

fit(X[, y])

Fit the Equal Weighted estimator.

fit_predict(X)

Perform fit on X and returns the predicted Portfolio or Population of Portfolio on X based on the fitted weights.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predict the Portfolio or Population of Portfolio on X based on the fitted weights.

score(X[, y])

Prediction score.

set_params(**params)

Set the parameters of this estimator.

fit(X, y=None)[source]#

Fit the Equal Weighted estimator.

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

Price returns of the assets.

yIgnored

Not used, present for API consistency by convention.

Returns:
selfEqualWeighted

Fitted estimator.

fit_predict(X)#

Perform fit on X and returns the predicted Portfolio or Population of Portfolio on X based on the fitted weights. For factor models, use fit(X, y) then predict(X) separately.

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

Price returns of the assets.

Returns:
predictionPortfolio | Population

Portfolio or Population of Portfolio estimated on X based on the fitted weights.

get_metadata_routing()#

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.

predict(X)#

Predict the Portfolio or Population of Portfolio on X based on the fitted weights.

Optimization estimators can return a 1D or a 2D array of weights. For a 1D array, the prediction returns a Portfolio. For a 2D array, the prediction returns a Population of Portfolio.

If name is not provided in the portfolio arguments, we use the first 500 characters of the estimator name.

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

Price returns of the assets.

Returns:
predictionPortfolio | Population

Portfolio or Population of Portfolio estimated on X based on the fitted weights.

score(X, y=None)#

Prediction score. If the prediction is a single Portfolio, the score is the Sharpe Ratio. If the prediction is a Population of Portfolio, the score is the mean of all the portfolios Sharpe Ratios in the population.

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

Price returns of the assets.

yIgnored

Not used, present here for API consistency by convention.

Returns:
scorefloat

The Sharpe Ratio of the portfolio if the prediction is a single Portfolio or the mean of all the portfolios Sharpe Ratios if the prediction is a Population of Portfolio.

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.