[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-nvidia-portfolio-optimization":3,"mdc-n46zsn-key":37,"related-org-nvidia-portfolio-optimization":2549,"related-repo-nvidia-portfolio-optimization":2709},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":11,"stars":26,"repoUrl":27,"updatedAt":28,"license":29,"forks":30,"topics":31,"repo":32,"sourceUrl":35,"mdContent":36},"portfolio-optimization","optimize stock portfolios with NVIDIA cuOpt","Use when a user asks to build, optimize, backtest, rebalance, or analyze a stock portfolio with Mean-CVaR, Mean-Variance\u002FSOCP variance caps, efficient frontiers, scenario generation, or NVIDIA cuOpt.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},"nvidia","NVIDIA","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Fnvidia.png",[12,16,19,22,23],{"name":13,"slug":14,"type":15},"Portfolio Management","portfolio-management","tag",{"name":17,"slug":18,"type":15},"Finance","finance",{"name":20,"slug":21,"type":15},"Optimization","optimization",{"name":9,"slug":8,"type":15},{"name":24,"slug":25,"type":15},"Trading","trading",2473,"https:\u002F\u002Fgithub.com\u002FNVIDIA\u002Fskills","2026-08-05T05:58:09.89412","Apache-2.0",281,[],{"repoUrl":27,"stars":26,"forks":30,"topics":33,"description":34},[],"AI agent skills published by NVIDIA","https:\u002F\u002Fgithub.com\u002FNVIDIA\u002Fskills\u002Ftree\u002FHEAD\u002Fskills\u002Fportfolio-optimization","---\nname: portfolio-optimization\ndescription: Use when a user asks to build, optimize, backtest, rebalance, or analyze a stock portfolio with Mean-CVaR, Mean-Variance\u002FSOCP variance caps, efficient frontiers, scenario generation, or NVIDIA cuOpt.\nlicense: Apache-2.0\nmetadata:\n  author: Jake Goldberg \u003Cjgoldberg@nvidia.com>\n  tags:\n    - portfolio-optimization\n    - cvar\n    - cuopt\n    - quantitative-finance\n    - gpu\n---\n\n# Portfolio Optimization with NVIDIA cuOpt\n\n\u003C!--\nSPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0\n-->\n\n## Purpose\n\nBuild and analyze quantitative portfolios with NVIDIA-accelerated Mean-CVaR and Mean-Variance optimization. Use the `portfolio_optimization` package to compute returns, generate KDE scenarios for CVaR, solve variance-cap Markowitz allocations as SOCP\u002FQCQP problems with the cuOpt GPU solver, trace an efficient frontier, backtest portfolios, and run rebalancing workflows from price data.\n\n## When to Use\n\nUse this skill when the task is to:\n\n- Build or optimize a Mean-CVaR portfolio from stock prices.\n- Allocate weights across tickers while controlling downside CVaR risk.\n- Solve Mean-Variance or Markowitz allocations with a hard variance or volatility cap using cuOpt SOCP\u002FQCQP support.\n- Plot or inspect an efficient frontier for a portfolio universe.\n- Produce a weights-by-risk-aversion table.\n- Backtest an optimized portfolio against benchmarks.\n- Rebalance a portfolio on a schedule or drift trigger.\n- Run workflows on an S&P 500, S&P 100, Dow 30, or user-supplied price dataset.\n\nCommon trigger phrases include \"optimize my portfolio\", \"build a CVaR portfolio\", \"use cuOpt to optimize these tickers\", \"solve with cuOpt\", \"plot the efficient frontier\", \"show weights by risk aversion\", \"backtest this allocation\", \"rebalance monthly\", \"analyze my holdings with CVaR\", \"compare allocations\", \"reduce downside risk\", \"construct an allocation\", \"assess allocation options\", \"stress-test my holdings\", \"evaluate downside-risk exposure\", \"review my holdings under weight caps\", \"compare benchmark portfolios\", \"simulate CVaR scenarios\", \"screen portfolio risk\", \"optimize holdings under constraints\", \"solve a variance-cap portfolio\", \"use SOCP\", \"set a volatility cap\", and \"find a lower-risk allocation\".\n\nDo not use it for generic finance summaries, price forecasting, neural-network training, vehicle routing, or non-portfolio optimization.\n\n## Prerequisites\n\n- Python environment with the installed `portfolio_optimization` package.\n- NVIDIA GPU runtime with cuOpt and cuML installed. Mean-Variance SOCP workflows require a cuOpt build with QCQP\u002FSOCP support, such as the 26.06 line or newer.\n- CUDA extra matching the host and workflow: `uv sync --extra cuda12` for full cuOpt\u002FcuML 26.06 on CUDA 12, `uv sync --extra cuda13` for the current full CUDA 13 stack, or `uv sync --extra cuda13-socp` for CUDA 13 SOCP-only validation with cuOpt 26.06.\n- `cvxpy` exposing `cp.CUOPT`.\n- Network access on first run if the default price CSV must be downloaded.\n\n## Setup\n\nThis skill drives the installed `portfolio_optimization` package. A ready environment can come from the Brev launchable or from the `NVIDIA-AI-Blueprints\u002Fportfolio-optimization` repository after installing the matching CUDA extra.\n\nIn packaged agent\u002Feval sandboxes, `portfolio_optimization` may be available through `PYTHONPATH` rather than as a separately published wheel. Verify the local package with `python -c \"import portfolio_optimization\"` before declaring it missing. Do not `pip install portfolio_optimization`; do not reimplement the example workflows from scratch, and do not replace the package APIs with generic pandas\u002Fscipy\u002Fcvxpy portfolio code.\n\nFor concrete implementation details, use `references\u002Fworkflows\u002Fagent_recipes.md` as the source of truth. It contains exact working shapes for loading prices, preparing returns, solving with cuOpt, building a 25-point frontier, backtesting against equal weight, and calling the rebalancer.\n\nThe default dataset is `data\u002Fstock_data\u002Fsp500.csv`. It is gitignored. Before a first-run download, tell the user this fetches public market data through the package's yfinance data helper and ask them to confirm:\n\n```python\nimport cvxpy as cp\nfrom portfolio_optimization.cvar_parameters import CvarParameters\nfrom portfolio_optimization.utils import download_data\n\ndownload_data(\"data\u002Fstock_data\", datasets=[\"sp500\"])\nCVAR_SOLVER_SETTINGS = {\"solver\": cp.CUOPT, \"verbose\": False, \"solver_method\": \"PDLP\"}\ncvar_params = CvarParameters(\n    w_min=0.0, w_max=1.0,\n    c_min=0.0, c_max=0.0,\n    risk_aversion=1.0, confidence=0.95,\n)\n```\n\n## Instructions\n\nBriefly state the defaults being applied before execution, then use these guardrails:\n\n1. Load `data\u002Fstock_data\u002Fsp500.csv`; if it is missing, ask before downloading `sp500` with `portfolio_optimization.utils.download_data`. Do not glob, substitute, or fabricate price data.\n2. Validate user CSVs before solving: require a date-like index or first date column, numeric ticker columns, at least 60 rows after date filtering, and at least one requested ticker. If the user gives start\u002Fend dates, slice the price DataFrame before returns computation and report the retained date range. Filter tickers on the price DataFrame before returns are computed. `regime_dict` does not take a ticker field.\n3. Compute LOG returns with `utils.calculate_returns(...)`.\n4. For Mean-CVaR tasks, generate scenarios with `cvar_utils.generate_cvar_data(...)`, KDE, and `KDESettings(device=\"GPU\")`. For Mean-Variance SOCP variance-cap tasks, do not generate CVaR scenarios; use the `returns_dict` directly after LOG return computation.\n5. For ordinary Mean-CVaR portfolio requests, define `CvarParameters` with explicit `w_min` and `w_max`, and set `c_min=0.0` and `c_max=0.0` so the result is fully invested instead of 100 percent cash.\n6. For variance-cap, volatility-cap, Markowitz, SOCP, or QCQP requests, define `MeanVarianceParameters` with `var_limit` set to a positive variance bound, `c_min=0.0`, `c_max=0.0`, and `L_tar=1.0` for long-only fully invested allocations. If the user gives a volatility cap, square it before assigning `var_limit`.\n7. Build `cvar_optimizer.CVaR(returns_dict, cvar_params)` for Mean-CVaR tasks. Build `mean_variance_optimizer.MeanVariance(returns_dict, mean_variance_params, api_settings=ApiSettings(api=\"cuopt_python\"))` for direct cuOpt Mean-Variance SOCP tasks.\n8. Solve with NVIDIA cuOpt only. For CVaR, verify `hasattr(cp, \"CUOPT\")` and `str(cp.CUOPT) in {str(s) for s in cp.installed_solvers()}`, then pass `CVAR_SOLVER_SETTINGS` to every single-shot solve or looped frontier solve. For direct Mean-Variance SOCP, verify the `cuopt` Python package is importable and call the optimizer with `api=\"cuopt_python\"`; cuOpt auto-selects the barrier method for quadratic constraints. Never fall back to CLARABEL, SCS, ECOS, or another CPU solver. If cuOpt is absent, finish validation\u002Fsetup and report that the GPU\u002FcuOpt runtime is missing instead of fabricating a CPU result.\n9. For custom constraints, map user requests to the appropriate parameter model: CVaR risk controls to `CvarParameters`, variance or volatility caps to `MeanVarianceParameters.var_limit`, weight caps to `w_min`\u002F`w_max`, risk appetite to `risk_aversion`, confidence level to `confidence`, and cash allowance to `c_max`. Treat cardinality plus SOCP as unsupported unless the package exposes explicit mixed-integer conic support.\n10. If the user omits a benchmark for backtesting, use an equal-weight portfolio over the same tickers. If the user omits a constraint, keep the defaults table values and briefly restate consequential assumptions before solving.\n11. Deliver weights sorted by allocation, cash weight, expected return, solver label (`cuOpt GPU`), and the risk metric used: CVaR for Mean-CVaR or realized variance plus `var_limit` for SOCP. Include any requested frontier figure, weights table, backtest metrics, or rebalancing schedule. For tables, include tickers as columns or rows with decimal weights and percentages; for plots, preserve the figure returned by the package instead of redrawing from scratch.\n12. For report-grade answers, include evidence that the requested workflow actually ran. For an efficient frontier, state `len(results_df)` and use the requested `ra_num` (25 unless the user specifies otherwise). For a variance-cap SOCP solve, report `result_row[\"solver\"]`, realized variance, the requested `var_limit`, and confirm realized variance is at or below the cap. For a weights table, expand `results_df[\"weights\"]` into ticker columns and include `cash` plus `risk_aversion`. For a backtest, include `mean portfolio return`, `sharpe`, `sortino`, and `max drawdown` for both optimized and benchmark portfolios. For rebalancing, include `results_dataframe`, `re_optimize_dates`, and the tail of `cumulative_portfolio_value`.\n\n## Canonical Workflow Skeleton\n\nStart applicable portfolio optimization tasks from this shape and adapt only the requested output. For complete copyable functions, read `references\u002Fworkflows\u002Fagent_recipes.md` before writing custom code.\n\n### Mean-CVaR workflow\n\n```python\nimport cvxpy as cp\nimport pandas as pd\n\nfrom portfolio_optimization import backtest, cvar_optimizer, cvar_utils, rebalance, utils\nfrom portfolio_optimization.cvar_parameters import CvarParameters\nfrom portfolio_optimization.portfolio import Portfolio\nfrom portfolio_optimization.settings import KDESettings, ReturnsComputeSettings, ScenarioGenerationSettings\n\nif not hasattr(cp, \"CUOPT\") or str(cp.CUOPT) not in {str(s) for s in cp.installed_solvers()}:\n    raise RuntimeError(\"cuOpt GPU solver is required; do not substitute a CPU solver.\")\n\nCVAR_SOLVER_SETTINGS = {\"solver\": cp.CUOPT, \"verbose\": False, \"solver_method\": \"PDLP\"}\n\nprices = utils.get_input_data(\"data\u002Fstock_data\u002Fsp500.csv\")\nreturns_dict = utils.calculate_returns(\n    prices,\n    regime_dict=None,\n    returns_compute_settings=ReturnsComputeSettings(return_type=\"LOG\"),\n)\nreturns_dict = cvar_utils.generate_cvar_data(\n    returns_dict,\n    ScenarioGenerationSettings(\n        fit_type=\"kde\",\n        kde_settings=KDESettings(device=\"GPU\"),\n    ),\n)\ncvar_params = CvarParameters(\n    w_min=0.0,\n    w_max=1.0,\n    c_min=0.0,\n    c_max=0.0,\n    risk_aversion=1.0,\n    confidence=0.95,\n)\noptimizer = cvar_optimizer.CVaR(returns_dict, cvar_params)\nresult, optimal_portfolio = optimizer.solve_optimization_problem(\n    solver_settings=CVAR_SOLVER_SETTINGS,\n    print_results=False,\n)\n```\n\n### Mean-Variance SOCP workflow\n\n```python\nimport importlib.util\nimport numpy as np\n\nfrom portfolio_optimization import mean_variance_optimizer, utils\nfrom portfolio_optimization.mean_variance_parameters import MeanVarianceParameters\nfrom portfolio_optimization.settings import ApiSettings, ReturnsComputeSettings\n\nif importlib.util.find_spec(\"cuopt\") is None:\n    raise RuntimeError(\"cuOpt Python API is required; do not substitute a CPU solver.\")\n\nprices = utils.get_input_data(\"data\u002Fstock_data\u002Fsp500.csv\")\nreturns_dict = utils.calculate_returns(\n    prices,\n    regime_dict=None,\n    returns_compute_settings=ReturnsComputeSettings(return_type=\"LOG\"),\n)\nweights = np.ones(len(returns_dict[\"tickers\"])) \u002F len(returns_dict[\"tickers\"])\nvar_limit = float(weights @ returns_dict[\"covariance\"] @ weights) * 1.05\nmean_variance_params = MeanVarianceParameters(\n    w_min=0.0,\n    w_max=1.0,\n    c_min=0.0,\n    c_max=0.0,\n    L_tar=1.0,\n    var_limit=var_limit,\n)\noptimizer = mean_variance_optimizer.MeanVariance(\n    returns_dict,\n    mean_variance_params,\n    api_settings=ApiSettings(api=\"cuopt_python\"),\n)\nresult, optimal_portfolio = optimizer.solve_optimization_problem(print_results=False)\nrealized_variance = float(\n    optimal_portfolio.weights @ returns_dict[\"covariance\"] @ optimal_portfolio.weights\n)\n```\n\nFor an efficient frontier or weights table, call:\n\n```python\nresults_df, fig, ax = cvar_utils.create_efficient_frontier(\n    returns_dict,\n    cvar_params,\n    CVAR_SOLVER_SETTINGS,\n    ra_num=25,\n    show_plot=False,\n    show_discretized_portfolios=False,\n    benchmark_portfolios=False,\n    print_portfolio_results=False,\n)\nweights_table = pd.DataFrame(results_df[\"weights\"].tolist(), index=results_df.index)\n```\n\nFor a benchmark backtest, wrap the solved allocation in `Portfolio(name=\"cuOpt Optimal\", tickers=returns_dict[\"tickers\"], weights=optimal_portfolio.weights, cash=optimal_portfolio.cash)`, create an equal-weight `Portfolio` over the same `returns_dict[\"tickers\"]`, then use `backtest.portfolio_backtester(..., test_method=\"historical\").backtest_against_benchmarks(...)`. The backtester returns `(backtest_results, ax)`.\n\nFor monthly rebalancing, write the price DataFrame to a CSV path first. Instantiate `rebalance.rebalance_portfolio(dataset_directory=\u003Ccsv_path>, ...)` with `re_optimize_criteria={\"type\": \"drift_from_optimal\", \"threshold\": 0, \"norm\": 1}` and call `re_optimize(transaction_cost_factor=..., plot_title=\"Monthly Rebalancing\")`. The rebalancer returns `(results_dataframe, re_optimize_dates, cumulative_portfolio_value)`.\n\n## Data and Defaults\n\n| Setting | Default |\n|---|---|\n| Dataset | `data\u002Fstock_data\u002Fsp500.csv` |\n| Date range | Full available range |\n| Portfolio type | Long-only |\n| Max weight | None unless specified |\n| Risk aversion | `1.0` |\n| Confidence | `0.95` |\n| Scenario method | KDE on GPU |\n| Solver | CVaR: cuOpt GPU with PDLP; Mean-Variance SOCP: direct cuOpt Python API with barrier auto-selected |\n| Rebalancing | None unless requested |\n\nThe default S&P 500 file is a historical snapshot and can omit current constituents. User-supplied CSVs should be date-indexed price tables with ticker columns, compatible with `utils.get_input_data`. If requested tickers are absent, drop them, report the omissions, and continue with available columns unless the user explicitly asks you to fetch other data.\n\n## Key APIs\n\nUse the package APIs instead of reimplementing portfolio math or simulation loops. `portfolio_optimization` helpers return flat objects: `returns_dict` has keys such as `returns`, `mean`, `covariance`, and `tickers`; do not index it as `returns_dict[\"regime_1\"]`. `solve_optimization_problem(...)` returns `(result_row, portfolio)`, not a nested result dictionary.\n\n- Returns: `utils.calculate_returns(input_dataset, regime_dict, returns_compute_settings)`.\n- Regime filter: `regime_dict` is `None` or `{\"name\": \"...\", \"range\": (\"YYYY-MM-DD\", \"YYYY-MM-DD\")}`; it is not keyed by regime name and does not contain tickers.\n- Scenarios: `cvar_utils.generate_cvar_data(returns_dict, scenario_generation_settings)` for Mean-CVaR only.\n- CVaR optimizer: `cvar_optimizer.CVaR(returns_dict, cvar_params)`.\n- Mean-Variance SOCP optimizer: `mean_variance_optimizer.MeanVariance(returns_dict, mean_variance_params, api_settings=ApiSettings(api=\"cuopt_python\"))`.\n- CVaR solve: `result_row, portfolio = cvar_problem.solve_optimization_problem(solver_settings=CVAR_SOLVER_SETTINGS, print_results=False)`.\n- SOCP solve: `result_row, portfolio = mean_variance_problem.solve_optimization_problem(print_results=False)`.\n- Efficient frontier: `cvar_utils.create_efficient_frontier(returns_dict, cvar_params, solver_settings=CVAR_SOLVER_SETTINGS, ra_num=25)`. The returned `results_df` includes metrics, a `weights` dict column, and `cash`.\n- Portfolio: `Portfolio(name=\"\", tickers=None, weights=None, cash=0.0, time_range=None)`; pass tickers and a flat array-like `weights` aligned to those tickers.\n- Backtest: create `portfolio.Portfolio` objects for the optimized allocation and each benchmark; for an equal-weight benchmark, use weights of `1 \u002F len(tickers)` and `cash=0.0`, then call `backtest.portfolio_backtester(test_portfolio, returns_dict, risk_free_rate=0.0, test_method=\"historical\", benchmark_portfolios=[...]).backtest_against_benchmarks(...)`.\n- Rebalance: `rebalance.rebalance_portfolio(...)` requires `dataset_directory` to be a CSV path, not a DataFrame. Call `re_optimize(...)`; it returns `(results_dataframe, re_optimize_dates, cumulative_portfolio_value)`.\n- Settings models: `ReturnsComputeSettings`, `ScenarioGenerationSettings`, `KDESettings`, `ApiSettings`, `CvarParameters`, and `MeanVarianceParameters`.\n\n## Examples\n\n- \"Build the optimal portfolio from the S&P 500\": load prices, compute LOG returns, generate GPU KDE scenarios, set long-only fully invested `CvarParameters`, solve with cuOpt, and report diversified weights plus return\u002FCVaR.\n- \"Solve a variance-cap portfolio with SOCP\": load prices, compute LOG returns, set `MeanVarianceParameters(var_limit=...)`, solve with direct `api=\"cuopt_python\"`, and report expected return, realized variance, `var_limit`, and weights.\n- \"Plot the efficient frontier\": call `create_efficient_frontier(...)`, return `results_df`, and show or save the figure as requested.\n- \"Give me weights by risk aversion\": expand `results_df[\"weights\"]` into a per-asset table.\n- \"Backtest against equal weight\": build the optimized and equal-weight `Portfolio` objects, then use the package backtester and report Sharpe, Sortino, and max drawdown.\n- \"Backtest monthly rebalancing\": configure `rebalance_portfolio` with the drift trigger above and run `re_optimize(transaction_cost_factor=...)`.\n\n## Limitations\n\n- Requires an NVIDIA GPU with cuOpt and cuML; CPU solvers are intentionally disallowed.\n- Mean-Variance SOCP variance caps require cuOpt QCQP\u002FSOCP support. Use the 26.06 line or newer when installing CUDA extras.\n- `cuda13-socp` intentionally installs cuOpt without cuML because `cuml-cu13` 26.06 is not published yet; use it for direct SOCP\u002FQCQP validation, not GPU KDE CVaR workflows.\n- Cardinality plus SOCP is treated as unsupported unless the package exposes explicit mixed-integer conic support.\n- CPU-only eval containers can still validate routing, data handling, and reporting behavior, but they cannot produce a valid cuOpt solve. In that case, report the missing GPU\u002FcuOpt runtime explicitly.\n- Default price data is a historical snapshot and may omit current constituents.\n- First-run dataset download depends on network access unless the user supplies a CSV.\n\n## Troubleshooting\n\n- Missing default CSV or `FileNotFoundError`: explain that the package will fetch public market data with `download_data(\"data\u002Fstock_data\", datasets=[\"sp500\"])`; run it only after user confirmation.\n- `SolverError` or missing `cp.CUOPT`: install the CUDA extra matching the host and verify with `python -c \"import cvxpy as cp; print(hasattr(cp, 'CUOPT'), cp.installed_solvers())\"`.\n- `ImportError` for `cuml` or GPU KDE failures: confirm cuML is present with `python -c \"import cuml\"` and keep `KDESettings(device=\"GPU\")`. If using `cuda13-socp`, this is expected for CVaR\u002FKDE; switch to `cuda12` or `cuda13` for cuML workflows.\n- SOCP setup fails before solving: verify the installed `cuopt` package is on the 26.06 line or newer and that `MeanVarianceParameters.var_limit` is positive.\n- Ordinary optimization returns all cash: set `c_max=0.0` in `CvarParameters`.\n- Solver reports infeasible or no solution: check for contradictory bounds, too few tickers for the requested caps\u002Fcardinality, or a date filter that leaves too little data; report the smallest constraint change that would make the request feasible.\n- Requested tickers are absent from the default CSV: report them and proceed with the remaining requested tickers.\n- User CSV fails validation: ask for a date-indexed price table or a CSV whose first column is dates and remaining columns are numeric ticker prices; mention the minimum 60-row post-filter requirement.\n",{"data":38,"body":46},{"name":4,"description":6,"license":29,"metadata":39},{"author":40,"tags":41},"Jake Goldberg \u003Cjgoldberg@nvidia.com>",[4,42,43,44,45],"cvar","cuopt","quantitative-finance","gpu",{"type":47,"children":48},"root",[49,58,65,80,86,91,136,141,146,152,225,231,251,287,300,313,426,432,437,872,878,890,897,1232,1238,1508,1513,1606,1650,1685,1691,1847,1860,1866,1938,2210,2216,2322,2328,2380,2386,2543],{"type":50,"tag":51,"props":52,"children":54},"element","h1",{"id":53},"portfolio-optimization-with-nvidia-cuopt",[55],{"type":56,"value":57},"text","Portfolio Optimization with NVIDIA cuOpt",{"type":50,"tag":59,"props":60,"children":62},"h2",{"id":61},"purpose",[63],{"type":56,"value":64},"Purpose",{"type":50,"tag":66,"props":67,"children":68},"p",{},[69,71,78],{"type":56,"value":70},"Build and analyze quantitative portfolios with NVIDIA-accelerated Mean-CVaR and Mean-Variance optimization. Use the ",{"type":50,"tag":72,"props":73,"children":75},"code",{"className":74},[],[76],{"type":56,"value":77},"portfolio_optimization",{"type":56,"value":79}," package to compute returns, generate KDE scenarios for CVaR, solve variance-cap Markowitz allocations as SOCP\u002FQCQP problems with the cuOpt GPU solver, trace an efficient frontier, backtest portfolios, and run rebalancing workflows from price data.",{"type":50,"tag":59,"props":81,"children":83},{"id":82},"when-to-use",[84],{"type":56,"value":85},"When to Use",{"type":50,"tag":66,"props":87,"children":88},{},[89],{"type":56,"value":90},"Use this skill when the task is to:",{"type":50,"tag":92,"props":93,"children":94},"ul",{},[95,101,106,111,116,121,126,131],{"type":50,"tag":96,"props":97,"children":98},"li",{},[99],{"type":56,"value":100},"Build or optimize a Mean-CVaR portfolio from stock prices.",{"type":50,"tag":96,"props":102,"children":103},{},[104],{"type":56,"value":105},"Allocate weights across tickers while controlling downside CVaR risk.",{"type":50,"tag":96,"props":107,"children":108},{},[109],{"type":56,"value":110},"Solve Mean-Variance or Markowitz allocations with a hard variance or volatility cap using cuOpt SOCP\u002FQCQP support.",{"type":50,"tag":96,"props":112,"children":113},{},[114],{"type":56,"value":115},"Plot or inspect an efficient frontier for a portfolio universe.",{"type":50,"tag":96,"props":117,"children":118},{},[119],{"type":56,"value":120},"Produce a weights-by-risk-aversion table.",{"type":50,"tag":96,"props":122,"children":123},{},[124],{"type":56,"value":125},"Backtest an optimized portfolio against benchmarks.",{"type":50,"tag":96,"props":127,"children":128},{},[129],{"type":56,"value":130},"Rebalance a portfolio on a schedule or drift trigger.",{"type":50,"tag":96,"props":132,"children":133},{},[134],{"type":56,"value":135},"Run workflows on an S&P 500, S&P 100, Dow 30, or user-supplied price dataset.",{"type":50,"tag":66,"props":137,"children":138},{},[139],{"type":56,"value":140},"Common trigger phrases include \"optimize my portfolio\", \"build a CVaR portfolio\", \"use cuOpt to optimize these tickers\", \"solve with cuOpt\", \"plot the efficient frontier\", \"show weights by risk aversion\", \"backtest this allocation\", \"rebalance monthly\", \"analyze my holdings with CVaR\", \"compare allocations\", \"reduce downside risk\", \"construct an allocation\", \"assess allocation options\", \"stress-test my holdings\", \"evaluate downside-risk exposure\", \"review my holdings under weight caps\", \"compare benchmark portfolios\", \"simulate CVaR scenarios\", \"screen portfolio risk\", \"optimize holdings under constraints\", \"solve a variance-cap portfolio\", \"use SOCP\", \"set a volatility cap\", and \"find a lower-risk allocation\".",{"type":50,"tag":66,"props":142,"children":143},{},[144],{"type":56,"value":145},"Do not use it for generic finance summaries, price forecasting, neural-network training, vehicle routing, or non-portfolio optimization.",{"type":50,"tag":59,"props":147,"children":149},{"id":148},"prerequisites",[150],{"type":56,"value":151},"Prerequisites",{"type":50,"tag":92,"props":153,"children":154},{},[155,167,172,201,220],{"type":50,"tag":96,"props":156,"children":157},{},[158,160,165],{"type":56,"value":159},"Python environment with the installed ",{"type":50,"tag":72,"props":161,"children":163},{"className":162},[],[164],{"type":56,"value":77},{"type":56,"value":166}," package.",{"type":50,"tag":96,"props":168,"children":169},{},[170],{"type":56,"value":171},"NVIDIA GPU runtime with cuOpt and cuML installed. Mean-Variance SOCP workflows require a cuOpt build with QCQP\u002FSOCP support, such as the 26.06 line or newer.",{"type":50,"tag":96,"props":173,"children":174},{},[175,177,183,185,191,193,199],{"type":56,"value":176},"CUDA extra matching the host and workflow: ",{"type":50,"tag":72,"props":178,"children":180},{"className":179},[],[181],{"type":56,"value":182},"uv sync --extra cuda12",{"type":56,"value":184}," for full cuOpt\u002FcuML 26.06 on CUDA 12, ",{"type":50,"tag":72,"props":186,"children":188},{"className":187},[],[189],{"type":56,"value":190},"uv sync --extra cuda13",{"type":56,"value":192}," for the current full CUDA 13 stack, or ",{"type":50,"tag":72,"props":194,"children":196},{"className":195},[],[197],{"type":56,"value":198},"uv sync --extra cuda13-socp",{"type":56,"value":200}," for CUDA 13 SOCP-only validation with cuOpt 26.06.",{"type":50,"tag":96,"props":202,"children":203},{},[204,210,212,218],{"type":50,"tag":72,"props":205,"children":207},{"className":206},[],[208],{"type":56,"value":209},"cvxpy",{"type":56,"value":211}," exposing ",{"type":50,"tag":72,"props":213,"children":215},{"className":214},[],[216],{"type":56,"value":217},"cp.CUOPT",{"type":56,"value":219},".",{"type":50,"tag":96,"props":221,"children":222},{},[223],{"type":56,"value":224},"Network access on first run if the default price CSV must be downloaded.",{"type":50,"tag":59,"props":226,"children":228},{"id":227},"setup",[229],{"type":56,"value":230},"Setup",{"type":50,"tag":66,"props":232,"children":233},{},[234,236,241,243,249],{"type":56,"value":235},"This skill drives the installed ",{"type":50,"tag":72,"props":237,"children":239},{"className":238},[],[240],{"type":56,"value":77},{"type":56,"value":242}," package. A ready environment can come from the Brev launchable or from the ",{"type":50,"tag":72,"props":244,"children":246},{"className":245},[],[247],{"type":56,"value":248},"NVIDIA-AI-Blueprints\u002Fportfolio-optimization",{"type":56,"value":250}," repository after installing the matching CUDA extra.",{"type":50,"tag":66,"props":252,"children":253},{},[254,256,261,263,269,271,277,279,285],{"type":56,"value":255},"In packaged agent\u002Feval sandboxes, ",{"type":50,"tag":72,"props":257,"children":259},{"className":258},[],[260],{"type":56,"value":77},{"type":56,"value":262}," may be available through ",{"type":50,"tag":72,"props":264,"children":266},{"className":265},[],[267],{"type":56,"value":268},"PYTHONPATH",{"type":56,"value":270}," rather than as a separately published wheel. Verify the local package with ",{"type":50,"tag":72,"props":272,"children":274},{"className":273},[],[275],{"type":56,"value":276},"python -c \"import portfolio_optimization\"",{"type":56,"value":278}," before declaring it missing. Do not ",{"type":50,"tag":72,"props":280,"children":282},{"className":281},[],[283],{"type":56,"value":284},"pip install portfolio_optimization",{"type":56,"value":286},"; do not reimplement the example workflows from scratch, and do not replace the package APIs with generic pandas\u002Fscipy\u002Fcvxpy portfolio code.",{"type":50,"tag":66,"props":288,"children":289},{},[290,292,298],{"type":56,"value":291},"For concrete implementation details, use ",{"type":50,"tag":72,"props":293,"children":295},{"className":294},[],[296],{"type":56,"value":297},"references\u002Fworkflows\u002Fagent_recipes.md",{"type":56,"value":299}," as the source of truth. It contains exact working shapes for loading prices, preparing returns, solving with cuOpt, building a 25-point frontier, backtesting against equal weight, and calling the rebalancer.",{"type":50,"tag":66,"props":301,"children":302},{},[303,305,311],{"type":56,"value":304},"The default dataset is ",{"type":50,"tag":72,"props":306,"children":308},{"className":307},[],[309],{"type":56,"value":310},"data\u002Fstock_data\u002Fsp500.csv",{"type":56,"value":312},". It is gitignored. Before a first-run download, tell the user this fetches public market data through the package's yfinance data helper and ask them to confirm:",{"type":50,"tag":314,"props":315,"children":320},"pre",{"className":316,"code":317,"language":318,"meta":319,"style":319},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import cvxpy as cp\nfrom portfolio_optimization.cvar_parameters import CvarParameters\nfrom portfolio_optimization.utils import download_data\n\ndownload_data(\"data\u002Fstock_data\", datasets=[\"sp500\"])\nCVAR_SOLVER_SETTINGS = {\"solver\": cp.CUOPT, \"verbose\": False, \"solver_method\": \"PDLP\"}\ncvar_params = CvarParameters(\n    w_min=0.0, w_max=1.0,\n    c_min=0.0, c_max=0.0,\n    risk_aversion=1.0, confidence=0.95,\n)\n","python","",[321],{"type":50,"tag":72,"props":322,"children":323},{"__ignoreMap":319},[324,335,344,353,363,372,381,390,399,408,417],{"type":50,"tag":325,"props":326,"children":329},"span",{"class":327,"line":328},"line",1,[330],{"type":50,"tag":325,"props":331,"children":332},{},[333],{"type":56,"value":334},"import cvxpy as cp\n",{"type":50,"tag":325,"props":336,"children":338},{"class":327,"line":337},2,[339],{"type":50,"tag":325,"props":340,"children":341},{},[342],{"type":56,"value":343},"from portfolio_optimization.cvar_parameters import CvarParameters\n",{"type":50,"tag":325,"props":345,"children":347},{"class":327,"line":346},3,[348],{"type":50,"tag":325,"props":349,"children":350},{},[351],{"type":56,"value":352},"from portfolio_optimization.utils import download_data\n",{"type":50,"tag":325,"props":354,"children":356},{"class":327,"line":355},4,[357],{"type":50,"tag":325,"props":358,"children":360},{"emptyLinePlaceholder":359},true,[361],{"type":56,"value":362},"\n",{"type":50,"tag":325,"props":364,"children":366},{"class":327,"line":365},5,[367],{"type":50,"tag":325,"props":368,"children":369},{},[370],{"type":56,"value":371},"download_data(\"data\u002Fstock_data\", datasets=[\"sp500\"])\n",{"type":50,"tag":325,"props":373,"children":375},{"class":327,"line":374},6,[376],{"type":50,"tag":325,"props":377,"children":378},{},[379],{"type":56,"value":380},"CVAR_SOLVER_SETTINGS = {\"solver\": cp.CUOPT, \"verbose\": False, \"solver_method\": \"PDLP\"}\n",{"type":50,"tag":325,"props":382,"children":384},{"class":327,"line":383},7,[385],{"type":50,"tag":325,"props":386,"children":387},{},[388],{"type":56,"value":389},"cvar_params = CvarParameters(\n",{"type":50,"tag":325,"props":391,"children":393},{"class":327,"line":392},8,[394],{"type":50,"tag":325,"props":395,"children":396},{},[397],{"type":56,"value":398},"    w_min=0.0, w_max=1.0,\n",{"type":50,"tag":325,"props":400,"children":402},{"class":327,"line":401},9,[403],{"type":50,"tag":325,"props":404,"children":405},{},[406],{"type":56,"value":407},"    c_min=0.0, c_max=0.0,\n",{"type":50,"tag":325,"props":409,"children":411},{"class":327,"line":410},10,[412],{"type":50,"tag":325,"props":413,"children":414},{},[415],{"type":56,"value":416},"    risk_aversion=1.0, confidence=0.95,\n",{"type":50,"tag":325,"props":418,"children":420},{"class":327,"line":419},11,[421],{"type":50,"tag":325,"props":422,"children":423},{},[424],{"type":56,"value":425},")\n",{"type":50,"tag":59,"props":427,"children":429},{"id":428},"instructions",[430],{"type":56,"value":431},"Instructions",{"type":50,"tag":66,"props":433,"children":434},{},[435],{"type":56,"value":436},"Briefly state the defaults being applied before execution, then use these guardrails:",{"type":50,"tag":438,"props":439,"children":440},"ol",{},[441,469,482,494,523,567,615,636,679,737,742,762],{"type":50,"tag":96,"props":442,"children":443},{},[444,446,451,453,459,461,467],{"type":56,"value":445},"Load ",{"type":50,"tag":72,"props":447,"children":449},{"className":448},[],[450],{"type":56,"value":310},{"type":56,"value":452},"; if it is missing, ask before downloading ",{"type":50,"tag":72,"props":454,"children":456},{"className":455},[],[457],{"type":56,"value":458},"sp500",{"type":56,"value":460}," with ",{"type":50,"tag":72,"props":462,"children":464},{"className":463},[],[465],{"type":56,"value":466},"portfolio_optimization.utils.download_data",{"type":56,"value":468},". Do not glob, substitute, or fabricate price data.",{"type":50,"tag":96,"props":470,"children":471},{},[472,474,480],{"type":56,"value":473},"Validate user CSVs before solving: require a date-like index or first date column, numeric ticker columns, at least 60 rows after date filtering, and at least one requested ticker. If the user gives start\u002Fend dates, slice the price DataFrame before returns computation and report the retained date range. Filter tickers on the price DataFrame before returns are computed. ",{"type":50,"tag":72,"props":475,"children":477},{"className":476},[],[478],{"type":56,"value":479},"regime_dict",{"type":56,"value":481}," does not take a ticker field.",{"type":50,"tag":96,"props":483,"children":484},{},[485,487,493],{"type":56,"value":486},"Compute LOG returns with ",{"type":50,"tag":72,"props":488,"children":490},{"className":489},[],[491],{"type":56,"value":492},"utils.calculate_returns(...)",{"type":56,"value":219},{"type":50,"tag":96,"props":495,"children":496},{},[497,499,505,507,513,515,521],{"type":56,"value":498},"For Mean-CVaR tasks, generate scenarios with ",{"type":50,"tag":72,"props":500,"children":502},{"className":501},[],[503],{"type":56,"value":504},"cvar_utils.generate_cvar_data(...)",{"type":56,"value":506},", KDE, and ",{"type":50,"tag":72,"props":508,"children":510},{"className":509},[],[511],{"type":56,"value":512},"KDESettings(device=\"GPU\")",{"type":56,"value":514},". For Mean-Variance SOCP variance-cap tasks, do not generate CVaR scenarios; use the ",{"type":50,"tag":72,"props":516,"children":518},{"className":517},[],[519],{"type":56,"value":520},"returns_dict",{"type":56,"value":522}," directly after LOG return computation.",{"type":50,"tag":96,"props":524,"children":525},{},[526,528,534,536,542,544,550,552,558,559,565],{"type":56,"value":527},"For ordinary Mean-CVaR portfolio requests, define ",{"type":50,"tag":72,"props":529,"children":531},{"className":530},[],[532],{"type":56,"value":533},"CvarParameters",{"type":56,"value":535}," with explicit ",{"type":50,"tag":72,"props":537,"children":539},{"className":538},[],[540],{"type":56,"value":541},"w_min",{"type":56,"value":543}," and ",{"type":50,"tag":72,"props":545,"children":547},{"className":546},[],[548],{"type":56,"value":549},"w_max",{"type":56,"value":551},", and set ",{"type":50,"tag":72,"props":553,"children":555},{"className":554},[],[556],{"type":56,"value":557},"c_min=0.0",{"type":56,"value":543},{"type":50,"tag":72,"props":560,"children":562},{"className":561},[],[563],{"type":56,"value":564},"c_max=0.0",{"type":56,"value":566}," so the result is fully invested instead of 100 percent cash.",{"type":50,"tag":96,"props":568,"children":569},{},[570,572,578,579,585,587,592,594,599,601,607,609,614],{"type":56,"value":571},"For variance-cap, volatility-cap, Markowitz, SOCP, or QCQP requests, define ",{"type":50,"tag":72,"props":573,"children":575},{"className":574},[],[576],{"type":56,"value":577},"MeanVarianceParameters",{"type":56,"value":460},{"type":50,"tag":72,"props":580,"children":582},{"className":581},[],[583],{"type":56,"value":584},"var_limit",{"type":56,"value":586}," set to a positive variance bound, ",{"type":50,"tag":72,"props":588,"children":590},{"className":589},[],[591],{"type":56,"value":557},{"type":56,"value":593},", ",{"type":50,"tag":72,"props":595,"children":597},{"className":596},[],[598],{"type":56,"value":564},{"type":56,"value":600},", and ",{"type":50,"tag":72,"props":602,"children":604},{"className":603},[],[605],{"type":56,"value":606},"L_tar=1.0",{"type":56,"value":608}," for long-only fully invested allocations. If the user gives a volatility cap, square it before assigning ",{"type":50,"tag":72,"props":610,"children":612},{"className":611},[],[613],{"type":56,"value":584},{"type":56,"value":219},{"type":50,"tag":96,"props":616,"children":617},{},[618,620,626,628,634],{"type":56,"value":619},"Build ",{"type":50,"tag":72,"props":621,"children":623},{"className":622},[],[624],{"type":56,"value":625},"cvar_optimizer.CVaR(returns_dict, cvar_params)",{"type":56,"value":627}," for Mean-CVaR tasks. Build ",{"type":50,"tag":72,"props":629,"children":631},{"className":630},[],[632],{"type":56,"value":633},"mean_variance_optimizer.MeanVariance(returns_dict, mean_variance_params, api_settings=ApiSettings(api=\"cuopt_python\"))",{"type":56,"value":635}," for direct cuOpt Mean-Variance SOCP tasks.",{"type":50,"tag":96,"props":637,"children":638},{},[639,641,647,648,654,656,662,664,669,671,677],{"type":56,"value":640},"Solve with NVIDIA cuOpt only. For CVaR, verify ",{"type":50,"tag":72,"props":642,"children":644},{"className":643},[],[645],{"type":56,"value":646},"hasattr(cp, \"CUOPT\")",{"type":56,"value":543},{"type":50,"tag":72,"props":649,"children":651},{"className":650},[],[652],{"type":56,"value":653},"str(cp.CUOPT) in {str(s) for s in cp.installed_solvers()}",{"type":56,"value":655},", then pass ",{"type":50,"tag":72,"props":657,"children":659},{"className":658},[],[660],{"type":56,"value":661},"CVAR_SOLVER_SETTINGS",{"type":56,"value":663}," to every single-shot solve or looped frontier solve. For direct Mean-Variance SOCP, verify the ",{"type":50,"tag":72,"props":665,"children":667},{"className":666},[],[668],{"type":56,"value":43},{"type":56,"value":670}," Python package is importable and call the optimizer with ",{"type":50,"tag":72,"props":672,"children":674},{"className":673},[],[675],{"type":56,"value":676},"api=\"cuopt_python\"",{"type":56,"value":678},"; cuOpt auto-selects the barrier method for quadratic constraints. Never fall back to CLARABEL, SCS, ECOS, or another CPU solver. If cuOpt is absent, finish validation\u002Fsetup and report that the GPU\u002FcuOpt runtime is missing instead of fabricating a CPU result.",{"type":50,"tag":96,"props":680,"children":681},{},[682,684,689,691,697,699,704,706,711,713,719,721,727,729,735],{"type":56,"value":683},"For custom constraints, map user requests to the appropriate parameter model: CVaR risk controls to ",{"type":50,"tag":72,"props":685,"children":687},{"className":686},[],[688],{"type":56,"value":533},{"type":56,"value":690},", variance or volatility caps to ",{"type":50,"tag":72,"props":692,"children":694},{"className":693},[],[695],{"type":56,"value":696},"MeanVarianceParameters.var_limit",{"type":56,"value":698},", weight caps to ",{"type":50,"tag":72,"props":700,"children":702},{"className":701},[],[703],{"type":56,"value":541},{"type":56,"value":705},"\u002F",{"type":50,"tag":72,"props":707,"children":709},{"className":708},[],[710],{"type":56,"value":549},{"type":56,"value":712},", risk appetite to ",{"type":50,"tag":72,"props":714,"children":716},{"className":715},[],[717],{"type":56,"value":718},"risk_aversion",{"type":56,"value":720},", confidence level to ",{"type":50,"tag":72,"props":722,"children":724},{"className":723},[],[725],{"type":56,"value":726},"confidence",{"type":56,"value":728},", and cash allowance to ",{"type":50,"tag":72,"props":730,"children":732},{"className":731},[],[733],{"type":56,"value":734},"c_max",{"type":56,"value":736},". Treat cardinality plus SOCP as unsupported unless the package exposes explicit mixed-integer conic support.",{"type":50,"tag":96,"props":738,"children":739},{},[740],{"type":56,"value":741},"If the user omits a benchmark for backtesting, use an equal-weight portfolio over the same tickers. If the user omits a constraint, keep the defaults table values and briefly restate consequential assumptions before solving.",{"type":50,"tag":96,"props":743,"children":744},{},[745,747,753,755,760],{"type":56,"value":746},"Deliver weights sorted by allocation, cash weight, expected return, solver label (",{"type":50,"tag":72,"props":748,"children":750},{"className":749},[],[751],{"type":56,"value":752},"cuOpt GPU",{"type":56,"value":754},"), and the risk metric used: CVaR for Mean-CVaR or realized variance plus ",{"type":50,"tag":72,"props":756,"children":758},{"className":757},[],[759],{"type":56,"value":584},{"type":56,"value":761}," for SOCP. Include any requested frontier figure, weights table, backtest metrics, or rebalancing schedule. For tables, include tickers as columns or rows with decimal weights and percentages; for plots, preserve the figure returned by the package instead of redrawing from scratch.",{"type":50,"tag":96,"props":763,"children":764},{},[765,767,773,775,781,783,789,791,796,798,804,806,812,814,819,821,827,828,834,835,841,842,848,850,856,857,863,865,871],{"type":56,"value":766},"For report-grade answers, include evidence that the requested workflow actually ran. For an efficient frontier, state ",{"type":50,"tag":72,"props":768,"children":770},{"className":769},[],[771],{"type":56,"value":772},"len(results_df)",{"type":56,"value":774}," and use the requested ",{"type":50,"tag":72,"props":776,"children":778},{"className":777},[],[779],{"type":56,"value":780},"ra_num",{"type":56,"value":782}," (25 unless the user specifies otherwise). For a variance-cap SOCP solve, report ",{"type":50,"tag":72,"props":784,"children":786},{"className":785},[],[787],{"type":56,"value":788},"result_row[\"solver\"]",{"type":56,"value":790},", realized variance, the requested ",{"type":50,"tag":72,"props":792,"children":794},{"className":793},[],[795],{"type":56,"value":584},{"type":56,"value":797},", and confirm realized variance is at or below the cap. For a weights table, expand ",{"type":50,"tag":72,"props":799,"children":801},{"className":800},[],[802],{"type":56,"value":803},"results_df[\"weights\"]",{"type":56,"value":805}," into ticker columns and include ",{"type":50,"tag":72,"props":807,"children":809},{"className":808},[],[810],{"type":56,"value":811},"cash",{"type":56,"value":813}," plus ",{"type":50,"tag":72,"props":815,"children":817},{"className":816},[],[818],{"type":56,"value":718},{"type":56,"value":820},". For a backtest, include ",{"type":50,"tag":72,"props":822,"children":824},{"className":823},[],[825],{"type":56,"value":826},"mean portfolio return",{"type":56,"value":593},{"type":50,"tag":72,"props":829,"children":831},{"className":830},[],[832],{"type":56,"value":833},"sharpe",{"type":56,"value":593},{"type":50,"tag":72,"props":836,"children":838},{"className":837},[],[839],{"type":56,"value":840},"sortino",{"type":56,"value":600},{"type":50,"tag":72,"props":843,"children":845},{"className":844},[],[846],{"type":56,"value":847},"max drawdown",{"type":56,"value":849}," for both optimized and benchmark portfolios. For rebalancing, include ",{"type":50,"tag":72,"props":851,"children":853},{"className":852},[],[854],{"type":56,"value":855},"results_dataframe",{"type":56,"value":593},{"type":50,"tag":72,"props":858,"children":860},{"className":859},[],[861],{"type":56,"value":862},"re_optimize_dates",{"type":56,"value":864},", and the tail of ",{"type":50,"tag":72,"props":866,"children":868},{"className":867},[],[869],{"type":56,"value":870},"cumulative_portfolio_value",{"type":56,"value":219},{"type":50,"tag":59,"props":873,"children":875},{"id":874},"canonical-workflow-skeleton",[876],{"type":56,"value":877},"Canonical Workflow Skeleton",{"type":50,"tag":66,"props":879,"children":880},{},[881,883,888],{"type":56,"value":882},"Start applicable portfolio optimization tasks from this shape and adapt only the requested output. For complete copyable functions, read ",{"type":50,"tag":72,"props":884,"children":886},{"className":885},[],[887],{"type":56,"value":297},{"type":56,"value":889}," before writing custom code.",{"type":50,"tag":891,"props":892,"children":894},"h3",{"id":893},"mean-cvar-workflow",[895],{"type":56,"value":896},"Mean-CVaR workflow",{"type":50,"tag":314,"props":898,"children":900},{"className":316,"code":899,"language":318,"meta":319,"style":319},"import cvxpy as cp\nimport pandas as pd\n\nfrom portfolio_optimization import backtest, cvar_optimizer, cvar_utils, rebalance, utils\nfrom portfolio_optimization.cvar_parameters import CvarParameters\nfrom portfolio_optimization.portfolio import Portfolio\nfrom portfolio_optimization.settings import KDESettings, ReturnsComputeSettings, ScenarioGenerationSettings\n\nif not hasattr(cp, \"CUOPT\") or str(cp.CUOPT) not in {str(s) for s in cp.installed_solvers()}:\n    raise RuntimeError(\"cuOpt GPU solver is required; do not substitute a CPU solver.\")\n\nCVAR_SOLVER_SETTINGS = {\"solver\": cp.CUOPT, \"verbose\": False, \"solver_method\": \"PDLP\"}\n\nprices = utils.get_input_data(\"data\u002Fstock_data\u002Fsp500.csv\")\nreturns_dict = utils.calculate_returns(\n    prices,\n    regime_dict=None,\n    returns_compute_settings=ReturnsComputeSettings(return_type=\"LOG\"),\n)\nreturns_dict = cvar_utils.generate_cvar_data(\n    returns_dict,\n    ScenarioGenerationSettings(\n        fit_type=\"kde\",\n        kde_settings=KDESettings(device=\"GPU\"),\n    ),\n)\ncvar_params = CvarParameters(\n    w_min=0.0,\n    w_max=1.0,\n    c_min=0.0,\n    c_max=0.0,\n    risk_aversion=1.0,\n    confidence=0.95,\n)\noptimizer = cvar_optimizer.CVaR(returns_dict, cvar_params)\nresult, optimal_portfolio = optimizer.solve_optimization_problem(\n    solver_settings=CVAR_SOLVER_SETTINGS,\n    print_results=False,\n)\n",[901],{"type":50,"tag":72,"props":902,"children":903},{"__ignoreMap":319},[904,911,919,926,934,941,949,957,964,972,980,987,995,1003,1012,1021,1030,1039,1048,1056,1065,1074,1083,1092,1101,1110,1118,1126,1135,1144,1153,1162,1171,1180,1188,1197,1206,1215,1224],{"type":50,"tag":325,"props":905,"children":906},{"class":327,"line":328},[907],{"type":50,"tag":325,"props":908,"children":909},{},[910],{"type":56,"value":334},{"type":50,"tag":325,"props":912,"children":913},{"class":327,"line":337},[914],{"type":50,"tag":325,"props":915,"children":916},{},[917],{"type":56,"value":918},"import pandas as pd\n",{"type":50,"tag":325,"props":920,"children":921},{"class":327,"line":346},[922],{"type":50,"tag":325,"props":923,"children":924},{"emptyLinePlaceholder":359},[925],{"type":56,"value":362},{"type":50,"tag":325,"props":927,"children":928},{"class":327,"line":355},[929],{"type":50,"tag":325,"props":930,"children":931},{},[932],{"type":56,"value":933},"from portfolio_optimization import backtest, cvar_optimizer, cvar_utils, rebalance, utils\n",{"type":50,"tag":325,"props":935,"children":936},{"class":327,"line":365},[937],{"type":50,"tag":325,"props":938,"children":939},{},[940],{"type":56,"value":343},{"type":50,"tag":325,"props":942,"children":943},{"class":327,"line":374},[944],{"type":50,"tag":325,"props":945,"children":946},{},[947],{"type":56,"value":948},"from portfolio_optimization.portfolio import Portfolio\n",{"type":50,"tag":325,"props":950,"children":951},{"class":327,"line":383},[952],{"type":50,"tag":325,"props":953,"children":954},{},[955],{"type":56,"value":956},"from portfolio_optimization.settings import KDESettings, ReturnsComputeSettings, ScenarioGenerationSettings\n",{"type":50,"tag":325,"props":958,"children":959},{"class":327,"line":392},[960],{"type":50,"tag":325,"props":961,"children":962},{"emptyLinePlaceholder":359},[963],{"type":56,"value":362},{"type":50,"tag":325,"props":965,"children":966},{"class":327,"line":401},[967],{"type":50,"tag":325,"props":968,"children":969},{},[970],{"type":56,"value":971},"if not hasattr(cp, \"CUOPT\") or str(cp.CUOPT) not in {str(s) for s in cp.installed_solvers()}:\n",{"type":50,"tag":325,"props":973,"children":974},{"class":327,"line":410},[975],{"type":50,"tag":325,"props":976,"children":977},{},[978],{"type":56,"value":979},"    raise RuntimeError(\"cuOpt GPU solver is required; do not substitute a CPU solver.\")\n",{"type":50,"tag":325,"props":981,"children":982},{"class":327,"line":419},[983],{"type":50,"tag":325,"props":984,"children":985},{"emptyLinePlaceholder":359},[986],{"type":56,"value":362},{"type":50,"tag":325,"props":988,"children":990},{"class":327,"line":989},12,[991],{"type":50,"tag":325,"props":992,"children":993},{},[994],{"type":56,"value":380},{"type":50,"tag":325,"props":996,"children":998},{"class":327,"line":997},13,[999],{"type":50,"tag":325,"props":1000,"children":1001},{"emptyLinePlaceholder":359},[1002],{"type":56,"value":362},{"type":50,"tag":325,"props":1004,"children":1006},{"class":327,"line":1005},14,[1007],{"type":50,"tag":325,"props":1008,"children":1009},{},[1010],{"type":56,"value":1011},"prices = utils.get_input_data(\"data\u002Fstock_data\u002Fsp500.csv\")\n",{"type":50,"tag":325,"props":1013,"children":1015},{"class":327,"line":1014},15,[1016],{"type":50,"tag":325,"props":1017,"children":1018},{},[1019],{"type":56,"value":1020},"returns_dict = utils.calculate_returns(\n",{"type":50,"tag":325,"props":1022,"children":1024},{"class":327,"line":1023},16,[1025],{"type":50,"tag":325,"props":1026,"children":1027},{},[1028],{"type":56,"value":1029},"    prices,\n",{"type":50,"tag":325,"props":1031,"children":1033},{"class":327,"line":1032},17,[1034],{"type":50,"tag":325,"props":1035,"children":1036},{},[1037],{"type":56,"value":1038},"    regime_dict=None,\n",{"type":50,"tag":325,"props":1040,"children":1042},{"class":327,"line":1041},18,[1043],{"type":50,"tag":325,"props":1044,"children":1045},{},[1046],{"type":56,"value":1047},"    returns_compute_settings=ReturnsComputeSettings(return_type=\"LOG\"),\n",{"type":50,"tag":325,"props":1049,"children":1051},{"class":327,"line":1050},19,[1052],{"type":50,"tag":325,"props":1053,"children":1054},{},[1055],{"type":56,"value":425},{"type":50,"tag":325,"props":1057,"children":1059},{"class":327,"line":1058},20,[1060],{"type":50,"tag":325,"props":1061,"children":1062},{},[1063],{"type":56,"value":1064},"returns_dict = cvar_utils.generate_cvar_data(\n",{"type":50,"tag":325,"props":1066,"children":1068},{"class":327,"line":1067},21,[1069],{"type":50,"tag":325,"props":1070,"children":1071},{},[1072],{"type":56,"value":1073},"    returns_dict,\n",{"type":50,"tag":325,"props":1075,"children":1077},{"class":327,"line":1076},22,[1078],{"type":50,"tag":325,"props":1079,"children":1080},{},[1081],{"type":56,"value":1082},"    ScenarioGenerationSettings(\n",{"type":50,"tag":325,"props":1084,"children":1086},{"class":327,"line":1085},23,[1087],{"type":50,"tag":325,"props":1088,"children":1089},{},[1090],{"type":56,"value":1091},"        fit_type=\"kde\",\n",{"type":50,"tag":325,"props":1093,"children":1095},{"class":327,"line":1094},24,[1096],{"type":50,"tag":325,"props":1097,"children":1098},{},[1099],{"type":56,"value":1100},"        kde_settings=KDESettings(device=\"GPU\"),\n",{"type":50,"tag":325,"props":1102,"children":1104},{"class":327,"line":1103},25,[1105],{"type":50,"tag":325,"props":1106,"children":1107},{},[1108],{"type":56,"value":1109},"    ),\n",{"type":50,"tag":325,"props":1111,"children":1113},{"class":327,"line":1112},26,[1114],{"type":50,"tag":325,"props":1115,"children":1116},{},[1117],{"type":56,"value":425},{"type":50,"tag":325,"props":1119,"children":1121},{"class":327,"line":1120},27,[1122],{"type":50,"tag":325,"props":1123,"children":1124},{},[1125],{"type":56,"value":389},{"type":50,"tag":325,"props":1127,"children":1129},{"class":327,"line":1128},28,[1130],{"type":50,"tag":325,"props":1131,"children":1132},{},[1133],{"type":56,"value":1134},"    w_min=0.0,\n",{"type":50,"tag":325,"props":1136,"children":1138},{"class":327,"line":1137},29,[1139],{"type":50,"tag":325,"props":1140,"children":1141},{},[1142],{"type":56,"value":1143},"    w_max=1.0,\n",{"type":50,"tag":325,"props":1145,"children":1147},{"class":327,"line":1146},30,[1148],{"type":50,"tag":325,"props":1149,"children":1150},{},[1151],{"type":56,"value":1152},"    c_min=0.0,\n",{"type":50,"tag":325,"props":1154,"children":1156},{"class":327,"line":1155},31,[1157],{"type":50,"tag":325,"props":1158,"children":1159},{},[1160],{"type":56,"value":1161},"    c_max=0.0,\n",{"type":50,"tag":325,"props":1163,"children":1165},{"class":327,"line":1164},32,[1166],{"type":50,"tag":325,"props":1167,"children":1168},{},[1169],{"type":56,"value":1170},"    risk_aversion=1.0,\n",{"type":50,"tag":325,"props":1172,"children":1174},{"class":327,"line":1173},33,[1175],{"type":50,"tag":325,"props":1176,"children":1177},{},[1178],{"type":56,"value":1179},"    confidence=0.95,\n",{"type":50,"tag":325,"props":1181,"children":1183},{"class":327,"line":1182},34,[1184],{"type":50,"tag":325,"props":1185,"children":1186},{},[1187],{"type":56,"value":425},{"type":50,"tag":325,"props":1189,"children":1191},{"class":327,"line":1190},35,[1192],{"type":50,"tag":325,"props":1193,"children":1194},{},[1195],{"type":56,"value":1196},"optimizer = cvar_optimizer.CVaR(returns_dict, cvar_params)\n",{"type":50,"tag":325,"props":1198,"children":1200},{"class":327,"line":1199},36,[1201],{"type":50,"tag":325,"props":1202,"children":1203},{},[1204],{"type":56,"value":1205},"result, optimal_portfolio = optimizer.solve_optimization_problem(\n",{"type":50,"tag":325,"props":1207,"children":1209},{"class":327,"line":1208},37,[1210],{"type":50,"tag":325,"props":1211,"children":1212},{},[1213],{"type":56,"value":1214},"    solver_settings=CVAR_SOLVER_SETTINGS,\n",{"type":50,"tag":325,"props":1216,"children":1218},{"class":327,"line":1217},38,[1219],{"type":50,"tag":325,"props":1220,"children":1221},{},[1222],{"type":56,"value":1223},"    print_results=False,\n",{"type":50,"tag":325,"props":1225,"children":1227},{"class":327,"line":1226},39,[1228],{"type":50,"tag":325,"props":1229,"children":1230},{},[1231],{"type":56,"value":425},{"type":50,"tag":891,"props":1233,"children":1235},{"id":1234},"mean-variance-socp-workflow",[1236],{"type":56,"value":1237},"Mean-Variance SOCP workflow",{"type":50,"tag":314,"props":1239,"children":1241},{"className":316,"code":1240,"language":318,"meta":319,"style":319},"import importlib.util\nimport numpy as np\n\nfrom portfolio_optimization import mean_variance_optimizer, utils\nfrom portfolio_optimization.mean_variance_parameters import MeanVarianceParameters\nfrom portfolio_optimization.settings import ApiSettings, ReturnsComputeSettings\n\nif importlib.util.find_spec(\"cuopt\") is None:\n    raise RuntimeError(\"cuOpt Python API is required; do not substitute a CPU solver.\")\n\nprices = utils.get_input_data(\"data\u002Fstock_data\u002Fsp500.csv\")\nreturns_dict = utils.calculate_returns(\n    prices,\n    regime_dict=None,\n    returns_compute_settings=ReturnsComputeSettings(return_type=\"LOG\"),\n)\nweights = np.ones(len(returns_dict[\"tickers\"])) \u002F len(returns_dict[\"tickers\"])\nvar_limit = float(weights @ returns_dict[\"covariance\"] @ weights) * 1.05\nmean_variance_params = MeanVarianceParameters(\n    w_min=0.0,\n    w_max=1.0,\n    c_min=0.0,\n    c_max=0.0,\n    L_tar=1.0,\n    var_limit=var_limit,\n)\noptimizer = mean_variance_optimizer.MeanVariance(\n    returns_dict,\n    mean_variance_params,\n    api_settings=ApiSettings(api=\"cuopt_python\"),\n)\nresult, optimal_portfolio = optimizer.solve_optimization_problem(print_results=False)\nrealized_variance = float(\n    optimal_portfolio.weights @ returns_dict[\"covariance\"] @ optimal_portfolio.weights\n)\n",[1242],{"type":50,"tag":72,"props":1243,"children":1244},{"__ignoreMap":319},[1245,1253,1261,1268,1276,1284,1292,1299,1307,1315,1322,1329,1336,1343,1350,1357,1364,1372,1380,1388,1395,1402,1409,1416,1424,1432,1439,1447,1454,1462,1470,1477,1485,1493,1501],{"type":50,"tag":325,"props":1246,"children":1247},{"class":327,"line":328},[1248],{"type":50,"tag":325,"props":1249,"children":1250},{},[1251],{"type":56,"value":1252},"import importlib.util\n",{"type":50,"tag":325,"props":1254,"children":1255},{"class":327,"line":337},[1256],{"type":50,"tag":325,"props":1257,"children":1258},{},[1259],{"type":56,"value":1260},"import numpy as np\n",{"type":50,"tag":325,"props":1262,"children":1263},{"class":327,"line":346},[1264],{"type":50,"tag":325,"props":1265,"children":1266},{"emptyLinePlaceholder":359},[1267],{"type":56,"value":362},{"type":50,"tag":325,"props":1269,"children":1270},{"class":327,"line":355},[1271],{"type":50,"tag":325,"props":1272,"children":1273},{},[1274],{"type":56,"value":1275},"from portfolio_optimization import mean_variance_optimizer, utils\n",{"type":50,"tag":325,"props":1277,"children":1278},{"class":327,"line":365},[1279],{"type":50,"tag":325,"props":1280,"children":1281},{},[1282],{"type":56,"value":1283},"from portfolio_optimization.mean_variance_parameters import MeanVarianceParameters\n",{"type":50,"tag":325,"props":1285,"children":1286},{"class":327,"line":374},[1287],{"type":50,"tag":325,"props":1288,"children":1289},{},[1290],{"type":56,"value":1291},"from portfolio_optimization.settings import ApiSettings, ReturnsComputeSettings\n",{"type":50,"tag":325,"props":1293,"children":1294},{"class":327,"line":383},[1295],{"type":50,"tag":325,"props":1296,"children":1297},{"emptyLinePlaceholder":359},[1298],{"type":56,"value":362},{"type":50,"tag":325,"props":1300,"children":1301},{"class":327,"line":392},[1302],{"type":50,"tag":325,"props":1303,"children":1304},{},[1305],{"type":56,"value":1306},"if importlib.util.find_spec(\"cuopt\") is None:\n",{"type":50,"tag":325,"props":1308,"children":1309},{"class":327,"line":401},[1310],{"type":50,"tag":325,"props":1311,"children":1312},{},[1313],{"type":56,"value":1314},"    raise RuntimeError(\"cuOpt Python API is required; do not substitute a CPU solver.\")\n",{"type":50,"tag":325,"props":1316,"children":1317},{"class":327,"line":410},[1318],{"type":50,"tag":325,"props":1319,"children":1320},{"emptyLinePlaceholder":359},[1321],{"type":56,"value":362},{"type":50,"tag":325,"props":1323,"children":1324},{"class":327,"line":419},[1325],{"type":50,"tag":325,"props":1326,"children":1327},{},[1328],{"type":56,"value":1011},{"type":50,"tag":325,"props":1330,"children":1331},{"class":327,"line":989},[1332],{"type":50,"tag":325,"props":1333,"children":1334},{},[1335],{"type":56,"value":1020},{"type":50,"tag":325,"props":1337,"children":1338},{"class":327,"line":997},[1339],{"type":50,"tag":325,"props":1340,"children":1341},{},[1342],{"type":56,"value":1029},{"type":50,"tag":325,"props":1344,"children":1345},{"class":327,"line":1005},[1346],{"type":50,"tag":325,"props":1347,"children":1348},{},[1349],{"type":56,"value":1038},{"type":50,"tag":325,"props":1351,"children":1352},{"class":327,"line":1014},[1353],{"type":50,"tag":325,"props":1354,"children":1355},{},[1356],{"type":56,"value":1047},{"type":50,"tag":325,"props":1358,"children":1359},{"class":327,"line":1023},[1360],{"type":50,"tag":325,"props":1361,"children":1362},{},[1363],{"type":56,"value":425},{"type":50,"tag":325,"props":1365,"children":1366},{"class":327,"line":1032},[1367],{"type":50,"tag":325,"props":1368,"children":1369},{},[1370],{"type":56,"value":1371},"weights = np.ones(len(returns_dict[\"tickers\"])) \u002F len(returns_dict[\"tickers\"])\n",{"type":50,"tag":325,"props":1373,"children":1374},{"class":327,"line":1041},[1375],{"type":50,"tag":325,"props":1376,"children":1377},{},[1378],{"type":56,"value":1379},"var_limit = float(weights @ returns_dict[\"covariance\"] @ weights) * 1.05\n",{"type":50,"tag":325,"props":1381,"children":1382},{"class":327,"line":1050},[1383],{"type":50,"tag":325,"props":1384,"children":1385},{},[1386],{"type":56,"value":1387},"mean_variance_params = MeanVarianceParameters(\n",{"type":50,"tag":325,"props":1389,"children":1390},{"class":327,"line":1058},[1391],{"type":50,"tag":325,"props":1392,"children":1393},{},[1394],{"type":56,"value":1134},{"type":50,"tag":325,"props":1396,"children":1397},{"class":327,"line":1067},[1398],{"type":50,"tag":325,"props":1399,"children":1400},{},[1401],{"type":56,"value":1143},{"type":50,"tag":325,"props":1403,"children":1404},{"class":327,"line":1076},[1405],{"type":50,"tag":325,"props":1406,"children":1407},{},[1408],{"type":56,"value":1152},{"type":50,"tag":325,"props":1410,"children":1411},{"class":327,"line":1085},[1412],{"type":50,"tag":325,"props":1413,"children":1414},{},[1415],{"type":56,"value":1161},{"type":50,"tag":325,"props":1417,"children":1418},{"class":327,"line":1094},[1419],{"type":50,"tag":325,"props":1420,"children":1421},{},[1422],{"type":56,"value":1423},"    L_tar=1.0,\n",{"type":50,"tag":325,"props":1425,"children":1426},{"class":327,"line":1103},[1427],{"type":50,"tag":325,"props":1428,"children":1429},{},[1430],{"type":56,"value":1431},"    var_limit=var_limit,\n",{"type":50,"tag":325,"props":1433,"children":1434},{"class":327,"line":1112},[1435],{"type":50,"tag":325,"props":1436,"children":1437},{},[1438],{"type":56,"value":425},{"type":50,"tag":325,"props":1440,"children":1441},{"class":327,"line":1120},[1442],{"type":50,"tag":325,"props":1443,"children":1444},{},[1445],{"type":56,"value":1446},"optimizer = mean_variance_optimizer.MeanVariance(\n",{"type":50,"tag":325,"props":1448,"children":1449},{"class":327,"line":1128},[1450],{"type":50,"tag":325,"props":1451,"children":1452},{},[1453],{"type":56,"value":1073},{"type":50,"tag":325,"props":1455,"children":1456},{"class":327,"line":1137},[1457],{"type":50,"tag":325,"props":1458,"children":1459},{},[1460],{"type":56,"value":1461},"    mean_variance_params,\n",{"type":50,"tag":325,"props":1463,"children":1464},{"class":327,"line":1146},[1465],{"type":50,"tag":325,"props":1466,"children":1467},{},[1468],{"type":56,"value":1469},"    api_settings=ApiSettings(api=\"cuopt_python\"),\n",{"type":50,"tag":325,"props":1471,"children":1472},{"class":327,"line":1155},[1473],{"type":50,"tag":325,"props":1474,"children":1475},{},[1476],{"type":56,"value":425},{"type":50,"tag":325,"props":1478,"children":1479},{"class":327,"line":1164},[1480],{"type":50,"tag":325,"props":1481,"children":1482},{},[1483],{"type":56,"value":1484},"result, optimal_portfolio = optimizer.solve_optimization_problem(print_results=False)\n",{"type":50,"tag":325,"props":1486,"children":1487},{"class":327,"line":1173},[1488],{"type":50,"tag":325,"props":1489,"children":1490},{},[1491],{"type":56,"value":1492},"realized_variance = float(\n",{"type":50,"tag":325,"props":1494,"children":1495},{"class":327,"line":1182},[1496],{"type":50,"tag":325,"props":1497,"children":1498},{},[1499],{"type":56,"value":1500},"    optimal_portfolio.weights @ returns_dict[\"covariance\"] @ optimal_portfolio.weights\n",{"type":50,"tag":325,"props":1502,"children":1503},{"class":327,"line":1190},[1504],{"type":50,"tag":325,"props":1505,"children":1506},{},[1507],{"type":56,"value":425},{"type":50,"tag":66,"props":1509,"children":1510},{},[1511],{"type":56,"value":1512},"For an efficient frontier or weights table, call:",{"type":50,"tag":314,"props":1514,"children":1516},{"className":316,"code":1515,"language":318,"meta":319,"style":319},"results_df, fig, ax = cvar_utils.create_efficient_frontier(\n    returns_dict,\n    cvar_params,\n    CVAR_SOLVER_SETTINGS,\n    ra_num=25,\n    show_plot=False,\n    show_discretized_portfolios=False,\n    benchmark_portfolios=False,\n    print_portfolio_results=False,\n)\nweights_table = pd.DataFrame(results_df[\"weights\"].tolist(), index=results_df.index)\n",[1517],{"type":50,"tag":72,"props":1518,"children":1519},{"__ignoreMap":319},[1520,1528,1535,1543,1551,1559,1567,1575,1583,1591,1598],{"type":50,"tag":325,"props":1521,"children":1522},{"class":327,"line":328},[1523],{"type":50,"tag":325,"props":1524,"children":1525},{},[1526],{"type":56,"value":1527},"results_df, fig, ax = cvar_utils.create_efficient_frontier(\n",{"type":50,"tag":325,"props":1529,"children":1530},{"class":327,"line":337},[1531],{"type":50,"tag":325,"props":1532,"children":1533},{},[1534],{"type":56,"value":1073},{"type":50,"tag":325,"props":1536,"children":1537},{"class":327,"line":346},[1538],{"type":50,"tag":325,"props":1539,"children":1540},{},[1541],{"type":56,"value":1542},"    cvar_params,\n",{"type":50,"tag":325,"props":1544,"children":1545},{"class":327,"line":355},[1546],{"type":50,"tag":325,"props":1547,"children":1548},{},[1549],{"type":56,"value":1550},"    CVAR_SOLVER_SETTINGS,\n",{"type":50,"tag":325,"props":1552,"children":1553},{"class":327,"line":365},[1554],{"type":50,"tag":325,"props":1555,"children":1556},{},[1557],{"type":56,"value":1558},"    ra_num=25,\n",{"type":50,"tag":325,"props":1560,"children":1561},{"class":327,"line":374},[1562],{"type":50,"tag":325,"props":1563,"children":1564},{},[1565],{"type":56,"value":1566},"    show_plot=False,\n",{"type":50,"tag":325,"props":1568,"children":1569},{"class":327,"line":383},[1570],{"type":50,"tag":325,"props":1571,"children":1572},{},[1573],{"type":56,"value":1574},"    show_discretized_portfolios=False,\n",{"type":50,"tag":325,"props":1576,"children":1577},{"class":327,"line":392},[1578],{"type":50,"tag":325,"props":1579,"children":1580},{},[1581],{"type":56,"value":1582},"    benchmark_portfolios=False,\n",{"type":50,"tag":325,"props":1584,"children":1585},{"class":327,"line":401},[1586],{"type":50,"tag":325,"props":1587,"children":1588},{},[1589],{"type":56,"value":1590},"    print_portfolio_results=False,\n",{"type":50,"tag":325,"props":1592,"children":1593},{"class":327,"line":410},[1594],{"type":50,"tag":325,"props":1595,"children":1596},{},[1597],{"type":56,"value":425},{"type":50,"tag":325,"props":1599,"children":1600},{"class":327,"line":419},[1601],{"type":50,"tag":325,"props":1602,"children":1603},{},[1604],{"type":56,"value":1605},"weights_table = pd.DataFrame(results_df[\"weights\"].tolist(), index=results_df.index)\n",{"type":50,"tag":66,"props":1607,"children":1608},{},[1609,1611,1617,1619,1625,1627,1633,1635,1641,1643,1649],{"type":56,"value":1610},"For a benchmark backtest, wrap the solved allocation in ",{"type":50,"tag":72,"props":1612,"children":1614},{"className":1613},[],[1615],{"type":56,"value":1616},"Portfolio(name=\"cuOpt Optimal\", tickers=returns_dict[\"tickers\"], weights=optimal_portfolio.weights, cash=optimal_portfolio.cash)",{"type":56,"value":1618},", create an equal-weight ",{"type":50,"tag":72,"props":1620,"children":1622},{"className":1621},[],[1623],{"type":56,"value":1624},"Portfolio",{"type":56,"value":1626}," over the same ",{"type":50,"tag":72,"props":1628,"children":1630},{"className":1629},[],[1631],{"type":56,"value":1632},"returns_dict[\"tickers\"]",{"type":56,"value":1634},", then use ",{"type":50,"tag":72,"props":1636,"children":1638},{"className":1637},[],[1639],{"type":56,"value":1640},"backtest.portfolio_backtester(..., test_method=\"historical\").backtest_against_benchmarks(...)",{"type":56,"value":1642},". The backtester returns ",{"type":50,"tag":72,"props":1644,"children":1646},{"className":1645},[],[1647],{"type":56,"value":1648},"(backtest_results, ax)",{"type":56,"value":219},{"type":50,"tag":66,"props":1651,"children":1652},{},[1653,1655,1661,1662,1668,1670,1676,1678,1684],{"type":56,"value":1654},"For monthly rebalancing, write the price DataFrame to a CSV path first. Instantiate ",{"type":50,"tag":72,"props":1656,"children":1658},{"className":1657},[],[1659],{"type":56,"value":1660},"rebalance.rebalance_portfolio(dataset_directory=\u003Ccsv_path>, ...)",{"type":56,"value":460},{"type":50,"tag":72,"props":1663,"children":1665},{"className":1664},[],[1666],{"type":56,"value":1667},"re_optimize_criteria={\"type\": \"drift_from_optimal\", \"threshold\": 0, \"norm\": 1}",{"type":56,"value":1669}," and call ",{"type":50,"tag":72,"props":1671,"children":1673},{"className":1672},[],[1674],{"type":56,"value":1675},"re_optimize(transaction_cost_factor=..., plot_title=\"Monthly Rebalancing\")",{"type":56,"value":1677},". The rebalancer returns ",{"type":50,"tag":72,"props":1679,"children":1681},{"className":1680},[],[1682],{"type":56,"value":1683},"(results_dataframe, re_optimize_dates, cumulative_portfolio_value)",{"type":56,"value":219},{"type":50,"tag":59,"props":1686,"children":1688},{"id":1687},"data-and-defaults",[1689],{"type":56,"value":1690},"Data and Defaults",{"type":50,"tag":1692,"props":1693,"children":1694},"table",{},[1695,1714],{"type":50,"tag":1696,"props":1697,"children":1698},"thead",{},[1699],{"type":50,"tag":1700,"props":1701,"children":1702},"tr",{},[1703,1709],{"type":50,"tag":1704,"props":1705,"children":1706},"th",{},[1707],{"type":56,"value":1708},"Setting",{"type":50,"tag":1704,"props":1710,"children":1711},{},[1712],{"type":56,"value":1713},"Default",{"type":50,"tag":1715,"props":1716,"children":1717},"tbody",{},[1718,1735,1748,1761,1774,1791,1808,1821,1834],{"type":50,"tag":1700,"props":1719,"children":1720},{},[1721,1727],{"type":50,"tag":1722,"props":1723,"children":1724},"td",{},[1725],{"type":56,"value":1726},"Dataset",{"type":50,"tag":1722,"props":1728,"children":1729},{},[1730],{"type":50,"tag":72,"props":1731,"children":1733},{"className":1732},[],[1734],{"type":56,"value":310},{"type":50,"tag":1700,"props":1736,"children":1737},{},[1738,1743],{"type":50,"tag":1722,"props":1739,"children":1740},{},[1741],{"type":56,"value":1742},"Date range",{"type":50,"tag":1722,"props":1744,"children":1745},{},[1746],{"type":56,"value":1747},"Full available range",{"type":50,"tag":1700,"props":1749,"children":1750},{},[1751,1756],{"type":50,"tag":1722,"props":1752,"children":1753},{},[1754],{"type":56,"value":1755},"Portfolio type",{"type":50,"tag":1722,"props":1757,"children":1758},{},[1759],{"type":56,"value":1760},"Long-only",{"type":50,"tag":1700,"props":1762,"children":1763},{},[1764,1769],{"type":50,"tag":1722,"props":1765,"children":1766},{},[1767],{"type":56,"value":1768},"Max weight",{"type":50,"tag":1722,"props":1770,"children":1771},{},[1772],{"type":56,"value":1773},"None unless specified",{"type":50,"tag":1700,"props":1775,"children":1776},{},[1777,1782],{"type":50,"tag":1722,"props":1778,"children":1779},{},[1780],{"type":56,"value":1781},"Risk aversion",{"type":50,"tag":1722,"props":1783,"children":1784},{},[1785],{"type":50,"tag":72,"props":1786,"children":1788},{"className":1787},[],[1789],{"type":56,"value":1790},"1.0",{"type":50,"tag":1700,"props":1792,"children":1793},{},[1794,1799],{"type":50,"tag":1722,"props":1795,"children":1796},{},[1797],{"type":56,"value":1798},"Confidence",{"type":50,"tag":1722,"props":1800,"children":1801},{},[1802],{"type":50,"tag":72,"props":1803,"children":1805},{"className":1804},[],[1806],{"type":56,"value":1807},"0.95",{"type":50,"tag":1700,"props":1809,"children":1810},{},[1811,1816],{"type":50,"tag":1722,"props":1812,"children":1813},{},[1814],{"type":56,"value":1815},"Scenario method",{"type":50,"tag":1722,"props":1817,"children":1818},{},[1819],{"type":56,"value":1820},"KDE on GPU",{"type":50,"tag":1700,"props":1822,"children":1823},{},[1824,1829],{"type":50,"tag":1722,"props":1825,"children":1826},{},[1827],{"type":56,"value":1828},"Solver",{"type":50,"tag":1722,"props":1830,"children":1831},{},[1832],{"type":56,"value":1833},"CVaR: cuOpt GPU with PDLP; Mean-Variance SOCP: direct cuOpt Python API with barrier auto-selected",{"type":50,"tag":1700,"props":1835,"children":1836},{},[1837,1842],{"type":50,"tag":1722,"props":1838,"children":1839},{},[1840],{"type":56,"value":1841},"Rebalancing",{"type":50,"tag":1722,"props":1843,"children":1844},{},[1845],{"type":56,"value":1846},"None unless requested",{"type":50,"tag":66,"props":1848,"children":1849},{},[1850,1852,1858],{"type":56,"value":1851},"The default S&P 500 file is a historical snapshot and can omit current constituents. User-supplied CSVs should be date-indexed price tables with ticker columns, compatible with ",{"type":50,"tag":72,"props":1853,"children":1855},{"className":1854},[],[1856],{"type":56,"value":1857},"utils.get_input_data",{"type":56,"value":1859},". If requested tickers are absent, drop them, report the omissions, and continue with available columns unless the user explicitly asks you to fetch other data.",{"type":50,"tag":59,"props":1861,"children":1863},{"id":1862},"key-apis",[1864],{"type":56,"value":1865},"Key APIs",{"type":50,"tag":66,"props":1867,"children":1868},{},[1869,1871,1876,1878,1883,1885,1891,1892,1898,1899,1905,1906,1912,1914,1920,1922,1928,1930,1936],{"type":56,"value":1870},"Use the package APIs instead of reimplementing portfolio math or simulation loops. ",{"type":50,"tag":72,"props":1872,"children":1874},{"className":1873},[],[1875],{"type":56,"value":77},{"type":56,"value":1877}," helpers return flat objects: ",{"type":50,"tag":72,"props":1879,"children":1881},{"className":1880},[],[1882],{"type":56,"value":520},{"type":56,"value":1884}," has keys such as ",{"type":50,"tag":72,"props":1886,"children":1888},{"className":1887},[],[1889],{"type":56,"value":1890},"returns",{"type":56,"value":593},{"type":50,"tag":72,"props":1893,"children":1895},{"className":1894},[],[1896],{"type":56,"value":1897},"mean",{"type":56,"value":593},{"type":50,"tag":72,"props":1900,"children":1902},{"className":1901},[],[1903],{"type":56,"value":1904},"covariance",{"type":56,"value":600},{"type":50,"tag":72,"props":1907,"children":1909},{"className":1908},[],[1910],{"type":56,"value":1911},"tickers",{"type":56,"value":1913},"; do not index it as ",{"type":50,"tag":72,"props":1915,"children":1917},{"className":1916},[],[1918],{"type":56,"value":1919},"returns_dict[\"regime_1\"]",{"type":56,"value":1921},". ",{"type":50,"tag":72,"props":1923,"children":1925},{"className":1924},[],[1926],{"type":56,"value":1927},"solve_optimization_problem(...)",{"type":56,"value":1929}," returns ",{"type":50,"tag":72,"props":1931,"children":1933},{"className":1932},[],[1934],{"type":56,"value":1935},"(result_row, portfolio)",{"type":56,"value":1937},", not a nested result dictionary.",{"type":50,"tag":92,"props":1939,"children":1940},{},[1941,1953,1981,1994,2005,2016,2028,2040,2075,2095,2130,2165],{"type":50,"tag":96,"props":1942,"children":1943},{},[1944,1946,1952],{"type":56,"value":1945},"Returns: ",{"type":50,"tag":72,"props":1947,"children":1949},{"className":1948},[],[1950],{"type":56,"value":1951},"utils.calculate_returns(input_dataset, regime_dict, returns_compute_settings)",{"type":56,"value":219},{"type":50,"tag":96,"props":1954,"children":1955},{},[1956,1958,1963,1965,1971,1973,1979],{"type":56,"value":1957},"Regime filter: ",{"type":50,"tag":72,"props":1959,"children":1961},{"className":1960},[],[1962],{"type":56,"value":479},{"type":56,"value":1964}," is ",{"type":50,"tag":72,"props":1966,"children":1968},{"className":1967},[],[1969],{"type":56,"value":1970},"None",{"type":56,"value":1972}," or ",{"type":50,"tag":72,"props":1974,"children":1976},{"className":1975},[],[1977],{"type":56,"value":1978},"{\"name\": \"...\", \"range\": (\"YYYY-MM-DD\", \"YYYY-MM-DD\")}",{"type":56,"value":1980},"; it is not keyed by regime name and does not contain tickers.",{"type":50,"tag":96,"props":1982,"children":1983},{},[1984,1986,1992],{"type":56,"value":1985},"Scenarios: ",{"type":50,"tag":72,"props":1987,"children":1989},{"className":1988},[],[1990],{"type":56,"value":1991},"cvar_utils.generate_cvar_data(returns_dict, scenario_generation_settings)",{"type":56,"value":1993}," for Mean-CVaR only.",{"type":50,"tag":96,"props":1995,"children":1996},{},[1997,1999,2004],{"type":56,"value":1998},"CVaR optimizer: ",{"type":50,"tag":72,"props":2000,"children":2002},{"className":2001},[],[2003],{"type":56,"value":625},{"type":56,"value":219},{"type":50,"tag":96,"props":2006,"children":2007},{},[2008,2010,2015],{"type":56,"value":2009},"Mean-Variance SOCP optimizer: ",{"type":50,"tag":72,"props":2011,"children":2013},{"className":2012},[],[2014],{"type":56,"value":633},{"type":56,"value":219},{"type":50,"tag":96,"props":2017,"children":2018},{},[2019,2021,2027],{"type":56,"value":2020},"CVaR solve: ",{"type":50,"tag":72,"props":2022,"children":2024},{"className":2023},[],[2025],{"type":56,"value":2026},"result_row, portfolio = cvar_problem.solve_optimization_problem(solver_settings=CVAR_SOLVER_SETTINGS, print_results=False)",{"type":56,"value":219},{"type":50,"tag":96,"props":2029,"children":2030},{},[2031,2033,2039],{"type":56,"value":2032},"SOCP solve: ",{"type":50,"tag":72,"props":2034,"children":2036},{"className":2035},[],[2037],{"type":56,"value":2038},"result_row, portfolio = mean_variance_problem.solve_optimization_problem(print_results=False)",{"type":56,"value":219},{"type":50,"tag":96,"props":2041,"children":2042},{},[2043,2045,2051,2053,2059,2061,2067,2069,2074],{"type":56,"value":2044},"Efficient frontier: ",{"type":50,"tag":72,"props":2046,"children":2048},{"className":2047},[],[2049],{"type":56,"value":2050},"cvar_utils.create_efficient_frontier(returns_dict, cvar_params, solver_settings=CVAR_SOLVER_SETTINGS, ra_num=25)",{"type":56,"value":2052},". The returned ",{"type":50,"tag":72,"props":2054,"children":2056},{"className":2055},[],[2057],{"type":56,"value":2058},"results_df",{"type":56,"value":2060}," includes metrics, a ",{"type":50,"tag":72,"props":2062,"children":2064},{"className":2063},[],[2065],{"type":56,"value":2066},"weights",{"type":56,"value":2068}," dict column, and ",{"type":50,"tag":72,"props":2070,"children":2072},{"className":2071},[],[2073],{"type":56,"value":811},{"type":56,"value":219},{"type":50,"tag":96,"props":2076,"children":2077},{},[2078,2080,2086,2088,2093],{"type":56,"value":2079},"Portfolio: ",{"type":50,"tag":72,"props":2081,"children":2083},{"className":2082},[],[2084],{"type":56,"value":2085},"Portfolio(name=\"\", tickers=None, weights=None, cash=0.0, time_range=None)",{"type":56,"value":2087},"; pass tickers and a flat array-like ",{"type":50,"tag":72,"props":2089,"children":2091},{"className":2090},[],[2092],{"type":56,"value":2066},{"type":56,"value":2094}," aligned to those tickers.",{"type":50,"tag":96,"props":2096,"children":2097},{},[2098,2100,2106,2108,2114,2115,2121,2123,2129],{"type":56,"value":2099},"Backtest: create ",{"type":50,"tag":72,"props":2101,"children":2103},{"className":2102},[],[2104],{"type":56,"value":2105},"portfolio.Portfolio",{"type":56,"value":2107}," objects for the optimized allocation and each benchmark; for an equal-weight benchmark, use weights of ",{"type":50,"tag":72,"props":2109,"children":2111},{"className":2110},[],[2112],{"type":56,"value":2113},"1 \u002F len(tickers)",{"type":56,"value":543},{"type":50,"tag":72,"props":2116,"children":2118},{"className":2117},[],[2119],{"type":56,"value":2120},"cash=0.0",{"type":56,"value":2122},", then call ",{"type":50,"tag":72,"props":2124,"children":2126},{"className":2125},[],[2127],{"type":56,"value":2128},"backtest.portfolio_backtester(test_portfolio, returns_dict, risk_free_rate=0.0, test_method=\"historical\", benchmark_portfolios=[...]).backtest_against_benchmarks(...)",{"type":56,"value":219},{"type":50,"tag":96,"props":2131,"children":2132},{},[2133,2135,2141,2143,2149,2151,2157,2159,2164],{"type":56,"value":2134},"Rebalance: ",{"type":50,"tag":72,"props":2136,"children":2138},{"className":2137},[],[2139],{"type":56,"value":2140},"rebalance.rebalance_portfolio(...)",{"type":56,"value":2142}," requires ",{"type":50,"tag":72,"props":2144,"children":2146},{"className":2145},[],[2147],{"type":56,"value":2148},"dataset_directory",{"type":56,"value":2150}," to be a CSV path, not a DataFrame. Call ",{"type":50,"tag":72,"props":2152,"children":2154},{"className":2153},[],[2155],{"type":56,"value":2156},"re_optimize(...)",{"type":56,"value":2158},"; it returns ",{"type":50,"tag":72,"props":2160,"children":2162},{"className":2161},[],[2163],{"type":56,"value":1683},{"type":56,"value":219},{"type":50,"tag":96,"props":2166,"children":2167},{},[2168,2170,2176,2177,2183,2184,2190,2191,2197,2198,2203,2204,2209],{"type":56,"value":2169},"Settings models: ",{"type":50,"tag":72,"props":2171,"children":2173},{"className":2172},[],[2174],{"type":56,"value":2175},"ReturnsComputeSettings",{"type":56,"value":593},{"type":50,"tag":72,"props":2178,"children":2180},{"className":2179},[],[2181],{"type":56,"value":2182},"ScenarioGenerationSettings",{"type":56,"value":593},{"type":50,"tag":72,"props":2185,"children":2187},{"className":2186},[],[2188],{"type":56,"value":2189},"KDESettings",{"type":56,"value":593},{"type":50,"tag":72,"props":2192,"children":2194},{"className":2193},[],[2195],{"type":56,"value":2196},"ApiSettings",{"type":56,"value":593},{"type":50,"tag":72,"props":2199,"children":2201},{"className":2200},[],[2202],{"type":56,"value":533},{"type":56,"value":600},{"type":50,"tag":72,"props":2205,"children":2207},{"className":2206},[],[2208],{"type":56,"value":577},{"type":56,"value":219},{"type":50,"tag":59,"props":2211,"children":2213},{"id":2212},"examples",[2214],{"type":56,"value":2215},"Examples",{"type":50,"tag":92,"props":2217,"children":2218},{},[2219,2231,2258,2278,2290,2302],{"type":50,"tag":96,"props":2220,"children":2221},{},[2222,2224,2229],{"type":56,"value":2223},"\"Build the optimal portfolio from the S&P 500\": load prices, compute LOG returns, generate GPU KDE scenarios, set long-only fully invested ",{"type":50,"tag":72,"props":2225,"children":2227},{"className":2226},[],[2228],{"type":56,"value":533},{"type":56,"value":2230},", solve with cuOpt, and report diversified weights plus return\u002FCVaR.",{"type":50,"tag":96,"props":2232,"children":2233},{},[2234,2236,2242,2244,2249,2251,2256],{"type":56,"value":2235},"\"Solve a variance-cap portfolio with SOCP\": load prices, compute LOG returns, set ",{"type":50,"tag":72,"props":2237,"children":2239},{"className":2238},[],[2240],{"type":56,"value":2241},"MeanVarianceParameters(var_limit=...)",{"type":56,"value":2243},", solve with direct ",{"type":50,"tag":72,"props":2245,"children":2247},{"className":2246},[],[2248],{"type":56,"value":676},{"type":56,"value":2250},", and report expected return, realized variance, ",{"type":50,"tag":72,"props":2252,"children":2254},{"className":2253},[],[2255],{"type":56,"value":584},{"type":56,"value":2257},", and weights.",{"type":50,"tag":96,"props":2259,"children":2260},{},[2261,2263,2269,2271,2276],{"type":56,"value":2262},"\"Plot the efficient frontier\": call ",{"type":50,"tag":72,"props":2264,"children":2266},{"className":2265},[],[2267],{"type":56,"value":2268},"create_efficient_frontier(...)",{"type":56,"value":2270},", return ",{"type":50,"tag":72,"props":2272,"children":2274},{"className":2273},[],[2275],{"type":56,"value":2058},{"type":56,"value":2277},", and show or save the figure as requested.",{"type":50,"tag":96,"props":2279,"children":2280},{},[2281,2283,2288],{"type":56,"value":2282},"\"Give me weights by risk aversion\": expand ",{"type":50,"tag":72,"props":2284,"children":2286},{"className":2285},[],[2287],{"type":56,"value":803},{"type":56,"value":2289}," into a per-asset table.",{"type":50,"tag":96,"props":2291,"children":2292},{},[2293,2295,2300],{"type":56,"value":2294},"\"Backtest against equal weight\": build the optimized and equal-weight ",{"type":50,"tag":72,"props":2296,"children":2298},{"className":2297},[],[2299],{"type":56,"value":1624},{"type":56,"value":2301}," objects, then use the package backtester and report Sharpe, Sortino, and max drawdown.",{"type":50,"tag":96,"props":2303,"children":2304},{},[2305,2307,2313,2315,2321],{"type":56,"value":2306},"\"Backtest monthly rebalancing\": configure ",{"type":50,"tag":72,"props":2308,"children":2310},{"className":2309},[],[2311],{"type":56,"value":2312},"rebalance_portfolio",{"type":56,"value":2314}," with the drift trigger above and run ",{"type":50,"tag":72,"props":2316,"children":2318},{"className":2317},[],[2319],{"type":56,"value":2320},"re_optimize(transaction_cost_factor=...)",{"type":56,"value":219},{"type":50,"tag":59,"props":2323,"children":2325},{"id":2324},"limitations",[2326],{"type":56,"value":2327},"Limitations",{"type":50,"tag":92,"props":2329,"children":2330},{},[2331,2336,2341,2360,2365,2370,2375],{"type":50,"tag":96,"props":2332,"children":2333},{},[2334],{"type":56,"value":2335},"Requires an NVIDIA GPU with cuOpt and cuML; CPU solvers are intentionally disallowed.",{"type":50,"tag":96,"props":2337,"children":2338},{},[2339],{"type":56,"value":2340},"Mean-Variance SOCP variance caps require cuOpt QCQP\u002FSOCP support. Use the 26.06 line or newer when installing CUDA extras.",{"type":50,"tag":96,"props":2342,"children":2343},{},[2344,2350,2352,2358],{"type":50,"tag":72,"props":2345,"children":2347},{"className":2346},[],[2348],{"type":56,"value":2349},"cuda13-socp",{"type":56,"value":2351}," intentionally installs cuOpt without cuML because ",{"type":50,"tag":72,"props":2353,"children":2355},{"className":2354},[],[2356],{"type":56,"value":2357},"cuml-cu13",{"type":56,"value":2359}," 26.06 is not published yet; use it for direct SOCP\u002FQCQP validation, not GPU KDE CVaR workflows.",{"type":50,"tag":96,"props":2361,"children":2362},{},[2363],{"type":56,"value":2364},"Cardinality plus SOCP is treated as unsupported unless the package exposes explicit mixed-integer conic support.",{"type":50,"tag":96,"props":2366,"children":2367},{},[2368],{"type":56,"value":2369},"CPU-only eval containers can still validate routing, data handling, and reporting behavior, but they cannot produce a valid cuOpt solve. In that case, report the missing GPU\u002FcuOpt runtime explicitly.",{"type":50,"tag":96,"props":2371,"children":2372},{},[2373],{"type":56,"value":2374},"Default price data is a historical snapshot and may omit current constituents.",{"type":50,"tag":96,"props":2376,"children":2377},{},[2378],{"type":56,"value":2379},"First-run dataset download depends on network access unless the user supplies a CSV.",{"type":50,"tag":59,"props":2381,"children":2383},{"id":2382},"troubleshooting",[2384],{"type":56,"value":2385},"Troubleshooting",{"type":50,"tag":92,"props":2387,"children":2388},{},[2389,2410,2435,2491,2510,2528,2533,2538],{"type":50,"tag":96,"props":2390,"children":2391},{},[2392,2394,2400,2402,2408],{"type":56,"value":2393},"Missing default CSV or ",{"type":50,"tag":72,"props":2395,"children":2397},{"className":2396},[],[2398],{"type":56,"value":2399},"FileNotFoundError",{"type":56,"value":2401},": explain that the package will fetch public market data with ",{"type":50,"tag":72,"props":2403,"children":2405},{"className":2404},[],[2406],{"type":56,"value":2407},"download_data(\"data\u002Fstock_data\", datasets=[\"sp500\"])",{"type":56,"value":2409},"; run it only after user confirmation.",{"type":50,"tag":96,"props":2411,"children":2412},{},[2413,2419,2421,2426,2428,2434],{"type":50,"tag":72,"props":2414,"children":2416},{"className":2415},[],[2417],{"type":56,"value":2418},"SolverError",{"type":56,"value":2420}," or missing ",{"type":50,"tag":72,"props":2422,"children":2424},{"className":2423},[],[2425],{"type":56,"value":217},{"type":56,"value":2427},": install the CUDA extra matching the host and verify with ",{"type":50,"tag":72,"props":2429,"children":2431},{"className":2430},[],[2432],{"type":56,"value":2433},"python -c \"import cvxpy as cp; print(hasattr(cp, 'CUOPT'), cp.installed_solvers())\"",{"type":56,"value":219},{"type":50,"tag":96,"props":2436,"children":2437},{},[2438,2444,2446,2452,2454,2460,2462,2467,2469,2474,2476,2482,2483,2489],{"type":50,"tag":72,"props":2439,"children":2441},{"className":2440},[],[2442],{"type":56,"value":2443},"ImportError",{"type":56,"value":2445}," for ",{"type":50,"tag":72,"props":2447,"children":2449},{"className":2448},[],[2450],{"type":56,"value":2451},"cuml",{"type":56,"value":2453}," or GPU KDE failures: confirm cuML is present with ",{"type":50,"tag":72,"props":2455,"children":2457},{"className":2456},[],[2458],{"type":56,"value":2459},"python -c \"import cuml\"",{"type":56,"value":2461}," and keep ",{"type":50,"tag":72,"props":2463,"children":2465},{"className":2464},[],[2466],{"type":56,"value":512},{"type":56,"value":2468},". If using ",{"type":50,"tag":72,"props":2470,"children":2472},{"className":2471},[],[2473],{"type":56,"value":2349},{"type":56,"value":2475},", this is expected for CVaR\u002FKDE; switch to ",{"type":50,"tag":72,"props":2477,"children":2479},{"className":2478},[],[2480],{"type":56,"value":2481},"cuda12",{"type":56,"value":1972},{"type":50,"tag":72,"props":2484,"children":2486},{"className":2485},[],[2487],{"type":56,"value":2488},"cuda13",{"type":56,"value":2490}," for cuML workflows.",{"type":50,"tag":96,"props":2492,"children":2493},{},[2494,2496,2501,2503,2508],{"type":56,"value":2495},"SOCP setup fails before solving: verify the installed ",{"type":50,"tag":72,"props":2497,"children":2499},{"className":2498},[],[2500],{"type":56,"value":43},{"type":56,"value":2502}," package is on the 26.06 line or newer and that ",{"type":50,"tag":72,"props":2504,"children":2506},{"className":2505},[],[2507],{"type":56,"value":696},{"type":56,"value":2509}," is positive.",{"type":50,"tag":96,"props":2511,"children":2512},{},[2513,2515,2520,2522,2527],{"type":56,"value":2514},"Ordinary optimization returns all cash: set ",{"type":50,"tag":72,"props":2516,"children":2518},{"className":2517},[],[2519],{"type":56,"value":564},{"type":56,"value":2521}," in ",{"type":50,"tag":72,"props":2523,"children":2525},{"className":2524},[],[2526],{"type":56,"value":533},{"type":56,"value":219},{"type":50,"tag":96,"props":2529,"children":2530},{},[2531],{"type":56,"value":2532},"Solver reports infeasible or no solution: check for contradictory bounds, too few tickers for the requested caps\u002Fcardinality, or a date filter that leaves too little data; report the smallest constraint change that would make the request feasible.",{"type":50,"tag":96,"props":2534,"children":2535},{},[2536],{"type":56,"value":2537},"Requested tickers are absent from the default CSV: report them and proceed with the remaining requested tickers.",{"type":50,"tag":96,"props":2539,"children":2540},{},[2541],{"type":56,"value":2542},"User CSV fails validation: ask for a date-indexed price table or a CSV whose first column is dates and remaining columns are numeric ticker prices; mention the minimum 60-row post-filter requirement.",{"type":50,"tag":2544,"props":2545,"children":2546},"style",{},[2547],{"type":56,"value":2548},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"items":2550,"total":2708},[2551,2569,2586,2597,2609,2623,2636,2650,2663,2674,2688,2697],{"slug":2552,"name":2552,"fn":2553,"description":2554,"org":2555,"tags":2556,"stars":2566,"repoUrl":2567,"updatedAt":2568},"nemoclaw-user-guide","retrieve NemoClaw documentation and configuration","Guides human users' AI agents to the NemoClaw docs MCP server and canonical Fern documentation in Markdown form. Use when users ask how to install, configure, operate, troubleshoot, secure, or learn NemoClaw with an AI coding assistant. Trigger keywords - nemoclaw docs, use nemoclaw with ai agent, nemoclaw mcp docs, nemoclaw install help, nemoclaw quickstart, nemoclaw markdown docs, llms.txt, agent skills.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2557,2560,2563],{"name":2558,"slug":2559,"type":15},"Documentation","documentation",{"name":2561,"slug":2562,"type":15},"MCP","mcp",{"name":2564,"slug":2565,"type":15},"Search","search",21777,"https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FNemoClaw","2026-07-20T06:00:01.461044",{"slug":2570,"name":2570,"fn":2571,"description":2572,"org":2573,"tags":2574,"stars":2583,"repoUrl":2584,"updatedAt":2585},"mcore-build-and-dependency","manage Megatron-LM development environments","Container-based dev environment setup and dependency management for Megatron-LM. Covers acquiring and launching the CI container, uv package management, and updating uv.lock.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2575,2578,2581],{"name":2576,"slug":2577,"type":15},"Containers","containers",{"name":2579,"slug":2580,"type":15},"Deployment","deployment",{"name":2582,"slug":318,"type":15},"Python",17049,"https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FMegatron-LM","2026-07-27T06:06:11.249662",{"slug":2587,"name":2587,"fn":2588,"description":2589,"org":2590,"tags":2591,"stars":2583,"repoUrl":2584,"updatedAt":2596},"mcore-bump-base-image","update NVIDIA PyTorch base images","Bump the NVIDIA PyTorch base image (`nvcr.io\u002Fnvidia\u002Fpytorch:YY.MM-py3`) used by Megatron-LM CI. Covers the two pin sites (GitHub CI in `docker\u002F.ngc_version.dev` and GitLab CI in `.gitlab\u002Fstages\u002F01.build.yml`), the post-bump CI loop (re-run functional tests, refresh golden values, mark broken tests), and the gotchas that bit PRs",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2592,2595],{"name":2593,"slug":2594,"type":15},"CI\u002FCD","ci-cd",{"name":2579,"slug":2580,"type":15},"2026-07-14T05:25:59.97109",{"slug":2598,"name":2598,"fn":2599,"description":2600,"org":2601,"tags":2602,"stars":2583,"repoUrl":2584,"updatedAt":2608},"mcore-cicd","manage CI\u002FCD pipelines for Megatron-LM","CI\u002FCD reference for Megatron-LM. Covers CI pipeline structure, PR scope labels, triggering internal GitLab CI (which force-pushes the current branch to a pull-request\u002FBRANCH ref — always dry-run and verify the destination first; never run against shared or protected branches), and CI failure investigation.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2603,2604,2605],{"name":2593,"slug":2594,"type":15},{"name":2579,"slug":2580,"type":15},{"name":2606,"slug":2607,"type":15},"GitHub","github","2026-07-27T06:06:12.278222",{"slug":2610,"name":2610,"fn":2611,"description":2612,"org":2613,"tags":2614,"stars":2583,"repoUrl":2584,"updatedAt":2622},"mcore-create-issue","investigate CI failures and create issues","Investigate a failing GitHub Actions run or job and create a GitHub issue for the failure.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2615,2618,2619],{"name":2616,"slug":2617,"type":15},"Debugging","debugging",{"name":2606,"slug":2607,"type":15},{"name":2620,"slug":2621,"type":15},"Triage","triage","2026-07-14T05:25:57.442089",{"slug":2624,"name":2624,"fn":2625,"description":2626,"org":2627,"tags":2628,"stars":2583,"repoUrl":2584,"updatedAt":2635},"mcore-linting-and-formatting","lint and format Megatron-LM code","Linting and formatting for Megatron-LM. Covers running autoformat.sh, tools (ruff, black, isort, pylint, mypy), and code style rules.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2629,2632],{"name":2630,"slug":2631,"type":15},"Best Practices","best-practices",{"name":2633,"slug":2634,"type":15},"Code Analysis","code-analysis","2026-07-14T05:25:56.18433",{"slug":2637,"name":2637,"fn":2638,"description":2639,"org":2640,"tags":2641,"stars":2583,"repoUrl":2584,"updatedAt":2649},"mcore-migrate-gpt-to-hybrid","migrate Megatron-LM models to HybridModel","Migration guide for moving Megatron Core GPTModel checkpoints, model providers, training commands, and layer mappings to HybridModel.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2642,2645,2648],{"name":2643,"slug":2644,"type":15},"Machine Learning","machine-learning",{"name":2646,"slug":2647,"type":15},"Migration","migration",{"name":9,"slug":8,"type":15},"2026-07-17T06:07:11.777011",{"slug":2651,"name":2651,"fn":2652,"description":2653,"org":2654,"tags":2655,"stars":2583,"repoUrl":2584,"updatedAt":2662},"mcore-onboard-gb200-1node-tests","onboard functional tests for GB200","Onboard 1-node GitHub MR functional tests for GB200 from existing mr-scoped 2-node tests.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2656,2659],{"name":2657,"slug":2658,"type":15},"QA","qa",{"name":2660,"slug":2661,"type":15},"Testing","testing","2026-07-14T05:25:53.673039",{"slug":2664,"name":2664,"fn":2665,"description":2666,"org":2667,"tags":2668,"stars":2583,"repoUrl":2584,"updatedAt":2673},"mcore-run-on-slurm","launch distributed training jobs on SLURM","How to launch distributed Megatron-LM training jobs on a SLURM cluster. Covers a minimal sbatch skeleton, environment-variable setup for torch.distributed.run, CUDA_DEVICE_MAX_CONNECTIONS rules across hardware and parallelism modes, container conventions, monitoring, and per-rank failure diagnosis.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2669,2670],{"name":2579,"slug":2580,"type":15},{"name":2671,"slug":2672,"type":15},"Infrastructure","infrastructure","2026-07-14T05:25:49.362534",{"slug":2675,"name":2675,"fn":2676,"description":2677,"org":2678,"tags":2679,"stars":2583,"repoUrl":2584,"updatedAt":2687},"mcore-split-pr","split pull requests to reduce review load","Split a PR into multiple PRs to reduce the number of required CODEOWNERS reviewer groups.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2680,2683,2684],{"name":2681,"slug":2682,"type":15},"Code Review","code-review",{"name":2606,"slug":2607,"type":15},{"name":2685,"slug":2686,"type":15},"Pull Requests","pull-requests","2026-07-14T05:26:01.226578",{"slug":2689,"name":2689,"fn":2690,"description":2691,"org":2692,"tags":2693,"stars":2583,"repoUrl":2584,"updatedAt":2696},"mcore-testing","run and manage Megatron-LM tests","Test system for Megatron-LM. Covers test layout, recipe YAML structure, adding and running unit and functional tests, golden values, marker filters, and CI parity.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2694,2695],{"name":2657,"slug":2658,"type":15},{"name":2660,"slug":2661,"type":15},"2026-07-14T05:25:54.928983",{"slug":2698,"name":2698,"fn":2699,"description":2700,"org":2701,"tags":2702,"stars":2583,"repoUrl":2584,"updatedAt":2707},"nightly-sync","manage nightly main-to-dev sync workflows","Domain knowledge for the nightly main-to-dev sync workflow. Covers merge strategy, CI architecture, failure investigation, and known issues.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2703,2706],{"name":2704,"slug":2705,"type":15},"Automation","automation",{"name":2593,"slug":2594,"type":15},"2026-07-30T05:29:03.275638",525,{"items":2710,"total":2806},[2711,2728,2738,2752,2762,2777,2792],{"slug":2712,"name":2712,"fn":2713,"description":2714,"org":2715,"tags":2716,"stars":26,"repoUrl":27,"updatedAt":2727},"accelerated-computing-cudf","accelerate data processing with cuDF","Official NVIDIA-authored guidance for NVIDIA cuDF GPU DataFrames, pandas acceleration, dask-cuDF, ETL, joins, groupby, CSV\u002FParquet I\u002FO, nullable semantics, and multi-GPU DataFrame workloads.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2717,2720,2723,2724],{"name":2718,"slug":2719,"type":15},"Data Analysis","data-analysis",{"name":2721,"slug":2722,"type":15},"Data Engineering","data-engineering",{"name":9,"slug":8,"type":15},{"name":2725,"slug":2726,"type":15},"Performance","performance","2026-07-14T05:28:43.176466",{"slug":2729,"name":2729,"fn":2730,"description":2731,"org":2732,"tags":2733,"stars":26,"repoUrl":27,"updatedAt":2737},"aiq-deploy","deploy and manage NVIDIA AI-Q infrastructure","Use when asked to install, deploy, run, validate, troubleshoot, or stop NVIDIA AI-Q Blueprint infrastructure.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2734,2735,2736],{"name":2579,"slug":2580,"type":15},{"name":2671,"slug":2672,"type":15},{"name":9,"slug":8,"type":15},"2026-07-14T05:29:06.667109",{"slug":2739,"name":2739,"fn":2740,"description":2741,"org":2742,"tags":2743,"stars":26,"repoUrl":27,"updatedAt":2751},"aiq-research","conduct deep research with AI-Q","Use when asked to run deep research or AI-Q research through a reachable NVIDIA AI-Q Blueprint backend.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2744,2747,2748],{"name":2745,"slug":2746,"type":15},"Agents","agents",{"name":9,"slug":8,"type":15},{"name":2749,"slug":2750,"type":15},"Research","research","2026-07-14T05:28:06.816956",{"slug":2753,"name":2753,"fn":2754,"description":2755,"org":2756,"tags":2757,"stars":26,"repoUrl":27,"updatedAt":2761},"amc-run-sample-calibration","run AMC sample dataset calibration","Run end-to-end calibration on the shipped sample dataset (sdg_08_2_sample_data_010926.zip) against a running AMC microservice. Use when user says 'test sample dataset', 'run sample calibration', 'verify AMC install', or 'launch and test'.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2758,2759,2760],{"name":2718,"slug":2719,"type":15},{"name":9,"slug":8,"type":15},{"name":2660,"slug":2661,"type":15},"2026-07-17T05:29:03.913266",{"slug":2763,"name":2763,"fn":2764,"description":2765,"org":2766,"tags":2767,"stars":26,"repoUrl":27,"updatedAt":2776},"amc-run-video-calibration","calibrate video datasets with AutoMagicCalib","Calibrate a new dataset from pre-recorded video files via the AutoMagicCalib REST API. Use when user has local MP4s and says 'calibrate my videos', 'run AMC on these videos', or similar. For RTSP\u002Flive streams, use amc-run-rtsp-calibration instead.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2768,2769,2772,2773],{"name":2704,"slug":2705,"type":15},{"name":2770,"slug":2771,"type":15},"Imaging","imaging",{"name":9,"slug":8,"type":15},{"name":2774,"slug":2775,"type":15},"Video","video","2026-07-17T05:28:53.905004",{"slug":2778,"name":2778,"fn":2779,"description":2780,"org":2781,"tags":2782,"stars":26,"repoUrl":27,"updatedAt":2791},"amc-setup-calibration-stack","deploy AutoMagicCalib microservice with Docker","Launch AutoMagicCalib microservice and web UI from NGC release images via Docker Compose. Use when user says 'deploy auto calibration', 'launch auto calibration', 'launch AMC', 'start MS+UI', or 'set up auto-magic-calib'. Requires NGC API key.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2783,2784,2787,2788],{"name":2579,"slug":2580,"type":15},{"name":2785,"slug":2786,"type":15},"Docker","docker",{"name":9,"slug":8,"type":15},{"name":2789,"slug":2790,"type":15},"Operations","operations","2026-07-17T05:28:56.913999",{"slug":2793,"name":2793,"fn":2794,"description":2795,"org":2796,"tags":2797,"stars":26,"repoUrl":27,"updatedAt":2805},"cudaq-guide","develop quantum applications with CUDA-Q","CUDA-Q onboarding guide for installation, test programs, GPU simulation, QPU hardware, and quantum applications.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[2798,2799,2802],{"name":9,"slug":8,"type":15},{"name":2800,"slug":2801,"type":15},"Quantum Computing","quantum-computing",{"name":2803,"slug":2804,"type":15},"Simulation","simulation","2026-07-14T05:26:58.898253",310]