markowizard.core¶
core ¶
Core portfolio optimization using Markowitz Modern Portfolio Theory.
Uses scipy.optimize to compute the efficient frontier.
MarkowitzOptimizer ¶
MarkowitzOptimizer(returns: DataFrame)
Performs Markowitz mean-variance optimization to find the efficient frontier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
DataFrame
|
DataFrame of historical asset returns, where each column is an asset and each row is a time period (e.g., monthly returns). Returns should be in decimal form (e.g., 0.01 = 1%), not percentage form. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
tickers |
Index
|
Asset tickers/column names. |
returns |
DataFrame
|
The input returns data. |
portfolios |
DataFrame | None
|
DataFrame of optimized portfolios along the efficient frontier, containing weights for each asset plus 'Expected Return', 'Risk' (std), and 'Sharpe' (Sharpe ratio). |
n_assets |
int
|
Number of assets in the portfolio. |
compute_sharpe ¶
compute_sharpe(risk_free_rate: float) -> pd.DataFrame
Compute the Sharpe ratio for each portfolio on the efficient frontier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
risk_free_rate
|
float
|
Risk-free rate (e.g., monthly rate). Should be in decimal form (e.g., 0.005 for 0.5% a.m.). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The portfolios DataFrame with an added 'Sharpe' column. |
max_sharpe_portfolio ¶
max_sharpe_portfolio() -> pd.Series
Return the portfolio with the highest Sharpe ratio.
Returns:
| Type | Description |
|---|---|
Series
|
The tangency (maximum Sharpe) portfolio. |
optimize ¶
optimize() -> pd.DataFrame
Compute the efficient frontier by solving quadratic programming problems for a range of risk-aversion parameters (mu).
Uses warm-starting: the optimal weights from one mu value serve as the initial guess for the next, reducing total iterations.
Returns:
| Type | Description |
|---|---|
DataFrame
|
Efficient frontier portfolios with columns for each asset weight, 'Expected Return', 'Risk', and 'Sharpe'. |