Install any skill in seconds. Free to start, no credit card required.
Get Started Free →brycewang-stanford/portfolio-optimization-guide
Portfolio theory, optimization algorithms, and asset allocation methods
Passed 0 of 22 test cases with the skill, and 11 of 22 without it.
1 fixed17 passed either way4 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
The instructions your model reads when the skill loads.
A skill for implementing and researching portfolio optimization methods, from classical mean-variance optimization to modern robust and factor-based approaches. Covers Markowitz theory, Black-Litterman, risk parity, and machine learning-enhanced portfolio construction.
import numpy as np
from scipy.optimize import minimize
def mean_variance_optimize(expected_returns: np.ndarray,
cov_matrix: np.ndarray,
target_return: float = None,
risk_free_rate: float = 0.02) -> dict:
"""
Markowitz mean-variance optimization.
expected_returns: array of expected returns for each asset
cov_matrix: covariance matrix of asset returns
target_return: target portfolio return (None for max Sharpe)
"""
n_assets = len(expected_returns)
def portfolio_volatility(weights):
return np.sqrt(weights @ cov_matrix @ weights)
def neg_sharpe(weights):
ret = weights @ expected_returns
vol = portfolio_volatility(weights)
return -(ret - risk_free_rate) / vol
# Constraints
constraints = [
{"type": "eq", "fun": lambda w: np.sum(w) - 1}, # weights sum to 1
]
if target_return is not None:
constraints.append(
{"type": "eq", "fun": lambda w: w @ expected_returns - target_return}
)
test cases passed, vs 11 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.