braverock / braverock/PortfolioAnalytics
CSM objective not available in metaheuristic solvers (constrained_objective)
- Dominant language
- PostScript
- Stars
- 106
- Forks
- 48
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
The `constrained_objective()` function has an empty switch arm for CSM (Coherent Second Moment) at `R/constrained_objective.R:606`:
```r
CSM = {}, ## xinran
```
When a metaheuristic solver (DEoptim, GenSA, pso, random) encounters a CSM risk objective, it silently skips the objective — CSM contributes nothing to the penalty function. The optimizer has no signal to minimize CSM.
## Root cause
CSM is defined as an optimization problem itself: `CSM(w) = min_zeta { zeta + (1/alpha) * ||max(0, -Rw - zeta)||_2 }`. Unlike variance or ES, it cannot be expressed as a closed-form function of moments — computing it requires solving an SOCP.
The `extract_risk()` function in `extractrisk.R` already implements this via CVXR. However, calling an SOCP solver for every `constrained_objective()` evaluation (thousands of times per metaheuristic run) raises performance concerns.
## Proposed approach
1. Extract the CSM SOCP computation from `extract_risk()` into a standalone `CSM()` function
2. Add `fun <- match.fun(CSM)` to the switch arm in `constrained_objective()`
3. Benchmark performance with metaheuristic solvers to assess viability
4. Consider caching/warm-starting strategies if performance is prohibitive
## Affected files
- `R/constrained_objective.R` — empty CSM block (line 606)
- `R/extractrisk.R` — existing CSM computation via CVXR (lines 44–49)
## References
Discovered during optimization solvers vignette work. See `plan.md` Tier 3 section.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the empty CSM arm at R/constrained_objective.R:606 and compare it with the existing CSM computation in R/extractrisk.R:44–49. Extract the CVXR-based computation into a standalone CSM() function, connect it to the switch, and benchmark DEoptim, GenSA, pso, and random. Done means CSM contributes to the penalty function without unacceptable performance; consider caching or warm-starting if benchmarks show a problem.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- fintech-quant
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100