# rohitkhadka314/cvxmarkowitz architecture

> Architecture diagram of the GitHub repository rohitkhadka314/cvxmarkowitz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohitkhadka314/cvxmarkowitz
- Repository: https://github.com/rohitkhadka314/cvxmarkowitz

## Overview

cvxmarkowitz is a CVXPY-based Markowitz portfolio optimization library. A caller configures a portfolio builder and optional constraints, builds a parameterized problem, supplies market/model data, then solves for an objective value and portfolio weights. The main design separates portfolio objectives, risk and constraint models, and the builder/problem lifecycle. README and sampled source establish this workflow; several portfolio and model modules are present in the tree but their detailed wiring was not sampled, so uncertain connections are omitted.

Main entry points: [`src/cvxmarkowitz/builder.py`](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/builder.py) (Builder), [`src/cvxmarkowitz/portfolios/soft_risk.py`](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/soft_risk.py) (Soft risk), [`src/cvxmarkowitz/portfolios/min_var.py`](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/min_var.py) (Minimum variance), [`src/cvxmarkowitz/portfolios/max_sharpe.py`](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/max_sharpe.py) (Maximum Sharpe)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_portfolio["Portfolio objectives"]
  node_minvar["Minimum variance<br/>[min_var.py]"]
  node_maxsharpe["Maximum Sharpe<br/>[max_sharpe.py]"]
  node_softrisk["Soft risk<br/>[soft_risk.py]"]
end

subgraph group_construction["Problem construction"]
  node_builder["Builder<br/>[builder.py]"]
  node_problem["Built problem<br/>[builder.py]"]
end

subgraph group_models["Risk and constraints"]
  node_sample["Sample covariance<br/>[sample.py]"]
  node_factor["Factor risk<br/>[factor.py]"]
  node_cvar["CVaR risk<br/>[cvar.py]"]
  node_bounds["Variable bounds<br/>[bounds.py]"]
  node_returns["Expected returns"]
  node_holding["Holding costs<br/>[holding_costs.py]"]
  node_trading["Trading costs<br/>[trading_costs.py]"]
end

subgraph group_execution["Solve and result"]
  node_cvxpy{{"CVXPY solver"}}
  node_result["Portfolio solution"]
end

node_caller(("Library caller"))

node_caller -->|"configures"| node_minvar
node_caller -->|"configures"| node_maxsharpe
node_caller -->|"configures"| node_softrisk
node_minvar -->|"inherits"| node_builder
node_maxsharpe -->|"inherits"| node_builder
node_softrisk -->|"inherits"| node_builder
node_builder -->|"selects by default"| node_sample
node_builder -->|"selects with factors"| node_factor
node_builder -->|"registers"| node_bounds
node_builder -->|"builds"| node_problem
node_problem -->|"updates model data"| node_sample
node_problem -->|"updates model data"| node_factor
node_problem -->|"updates model data"| node_bounds
node_softrisk -->|"estimates returns"| node_returns
node_softrisk -->|"extends construction"| node_builder
node_caller -->|"supplies data"| node_problem
node_problem -->|"solves problem"| node_cvxpy
node_cvxpy -->|"returns solution"| node_result

click node_minvar "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/min_var.py"
click node_maxsharpe "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/max_sharpe.py"
click node_softrisk "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/soft_risk.py"
click node_builder "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/builder.py"
click node_problem "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/builder.py"
click node_sample "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/risk/sample/sample.py"
click node_factor "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/risk/factor/factor.py"
click node_cvar "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/risk/cvar/cvar.py"
click node_bounds "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/bounds.py"
click node_returns "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/expected_returns.py"
click node_holding "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/holding_costs.py"
click node_trading "https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/trading_costs.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_minvar,node_maxsharpe,node_softrisk toneBlue
class node_builder,node_problem toneAmber
class node_sample,node_factor,node_cvar,node_bounds,node_returns,node_holding,node_trading toneMint
class node_cvxpy,node_result toneRose
class node_caller toneIndigo
```

## Components

### Portfolio objectives

- [Minimum variance](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/min_var.py): `src/cvxmarkowitz/portfolios/min_var.py`
- [Maximum Sharpe](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/max_sharpe.py): `src/cvxmarkowitz/portfolios/max_sharpe.py`
- [Soft risk](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/portfolios/soft_risk.py): `src/cvxmarkowitz/portfolios/soft_risk.py`

### Problem construction

- [Builder](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/builder.py): `src/cvxmarkowitz/builder.py`
- [Built problem](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/builder.py): `src/cvxmarkowitz/builder.py`

### Risk and constraints

- [Sample covariance](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/risk/sample/sample.py): `src/cvxmarkowitz/risk/sample/sample.py`
- [Factor risk](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/risk/factor/factor.py): `src/cvxmarkowitz/risk/factor/factor.py`
- [CVaR risk](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/risk/cvar/cvar.py): `src/cvxmarkowitz/risk/cvar/cvar.py`
- [Variable bounds](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/bounds.py): `src/cvxmarkowitz/models/bounds.py`
- [Expected returns](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/expected_returns.py): `src/cvxmarkowitz/models/expected_returns.py`
- [Holding costs](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/holding_costs.py): `src/cvxmarkowitz/models/holding_costs.py`
- [Trading costs](https://github.com/rohitkhadka314/cvxmarkowitz/blob/main/src/cvxmarkowitz/models/trading_costs.py): `src/cvxmarkowitz/models/trading_costs.py`

### Solve and result

- **CVXPY solver**
- **Portfolio solution**

### Other components

- **Library caller**

## Connections

- Library caller → Minimum variance: configures
- Library caller → Maximum Sharpe: configures
- Library caller → Soft risk: configures
- Minimum variance → Builder: inherits
- Maximum Sharpe → Builder: inherits
- Soft risk → Builder: inherits
- Builder → Sample covariance: selects by default
- Builder → Factor risk: selects with factors
- Builder → Variable bounds: registers
- Builder → Built problem: builds
- Built problem → Sample covariance: updates model data
- Built problem → Factor risk: updates model data
- Built problem → Variable bounds: updates model data
- Soft risk → Expected returns: estimates returns
- Soft risk → Builder: extends construction
- Library caller → Built problem: supplies data
- Built problem → CVXPY solver: solves problem
- CVXPY solver → Portfolio solution: returns solution
