Optimizations Reference
Portfolio Optimization Module
This module provides various portfolio optimization methods including Mean-Variance Optimization, Minimum Variance Portfolio, Maximum Sharpe Ratio, Hierarchical Risk Parity, Black-Litterman, Kelly Criterion, and other common portfolio optimization techniques.
black_litterman(returns, market_caps, views, view_confidences, tau=0.05, risk_free_rate=0.0)
Implement Black-Litterman portfolio optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
market_caps
|
array - like
|
Array of market capitalizations for each asset |
required |
views
|
dict
|
Dictionary mapping asset indices to expected returns |
required |
view_confidences
|
dict
|
Dictionary mapping asset indices to confidence levels (0-1) |
required |
tau
|
float
|
Uncertainty in the prior distribution |
0.05
|
risk_free_rate
|
float
|
Risk-free rate |
0.0
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |
equal_weight_portfolio(returns)
Create an equal-weighted portfolio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
Returns:
Type | Description |
---|---|
tuple
|
(weights, portfolio_return, portfolio_risk) |
hierarchical_risk_parity(returns, linkage_method='single', distance_metric='euclidean')
Implement Hierarchical Risk Parity (HRP) portfolio optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
linkage_method
|
str
|
Linkage method for hierarchical clustering ('single', 'complete', 'average', 'ward') |
'single'
|
distance_metric
|
str
|
Distance metric for clustering ('euclidean', 'correlation') |
'euclidean'
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |
kelly_criterion_optimization(returns, risk_free_rate=0.0, constraints=None, kelly_fraction=1.0)
Implement Kelly Criterion portfolio optimization.
The Kelly Criterion determines the optimal fraction of capital to allocate to each investment to maximize long-term growth rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
risk_free_rate
|
float
|
Risk-free rate |
0.0
|
constraints
|
list of dict
|
List of constraints for the optimization problem |
None
|
kelly_fraction
|
float
|
Fraction of Kelly Criterion to use (e.g., 0.5 for half-Kelly) |
1.0
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |
Notes
The Kelly Criterion maximizes the expected logarithmic growth rate of wealth. The full Kelly Criterion can be aggressive, so practitioners often use a fraction of the Kelly Criterion (e.g., half-Kelly) for more conservative position sizing.
market_cap_weight_portfolio(market_caps)
Create a market-cap weighted portfolio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
market_caps
|
array - like
|
Array of market capitalizations for each asset |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Market-cap weighted portfolio weights |
maximum_diversification_portfolio(returns, constraints=None)
Find the portfolio that maximizes diversification ratio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
constraints
|
list of dict
|
List of constraints for the optimization problem |
None
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |
maximum_sharpe_ratio(returns, risk_free_rate=0.0, constraints=None)
Find the portfolio with maximum Sharpe ratio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
risk_free_rate
|
float
|
Risk-free rate for Sharpe ratio calculation |
0.0
|
constraints
|
list of dict
|
List of constraints for the optimization problem |
None
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |
mean_variance_optimization(returns, target_return=None, risk_free_rate=0.0, constraints=None)
Perform Mean-Variance Optimization to find optimal portfolio weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
target_return
|
float
|
Target portfolio return. If None, maximizes Sharpe ratio |
None
|
risk_free_rate
|
float
|
Risk-free rate for Sharpe ratio calculation |
0.0
|
constraints
|
list of dict
|
List of constraints for the optimization problem |
None
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |
minimum_variance_portfolio(returns, constraints=None)
Find the portfolio with minimum variance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
constraints
|
list of dict
|
List of constraints for the optimization problem |
None
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |
risk_parity_portfolio(returns, constraints=None)
Find the portfolio where risk is equally distributed across assets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns
|
array - like
|
Matrix of asset returns where each column represents an asset |
required |
constraints
|
list of dict
|
List of constraints for the optimization problem |
None
|
Returns:
Type | Description |
---|---|
tuple
|
(optimal_weights, portfolio_return, portfolio_risk) |