# apurvshah007/portfolio-optimizer architecture

> Architecture diagram of the GitHub repository apurvshah007/portfolio-optimizer, 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/apurvshah007/portfolio-optimizer
- Repository: https://github.com/apurvshah007/portfolio-optimizer

## Overview

This repository is a Python portfolio-analysis and optimization library centered on Modern Portfolio Theory. A caller supplies assets, weights, and a start date to either optimizer; the optimizer retrieves price history, optionally reports portfolio statistics, computes annualized returns and covariance, and delegates to an optimization method. Results can be reported as weights and performance, converted to a discrete share allocation, and plotted. The README highlights efficient-frontier and asset-weight plots; the CLA module implements a frontier plot as well. The empty Markowitz file has no evidenced runtime role. Wiring reflects sampled source; no runtime behavior is inferred for the empty file.

Main entry points: [`basic_portfolio_functions.py`](https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py) (Portfolio helpers), [`efficient_frontier_portfolio_optimizer.py`](https://github.com/apurvshah007/portfolio-optimizer/blob/master/efficient_frontier_portfolio_optimizer.py) (Efficient optimizer), [`critical_line_algorithm_optimizer.py`](https://github.com/apurvshah007/portfolio-optimizer/blob/master/critical_line_algorithm_optimizer.py) (CLA optimizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Optimization APIs"]
  node_efficient["Efficient optimizer"]
  node_cla["CLA optimizer"]
end

subgraph group_analysis["Portfolio Analysis"]
  node_helpers["Portfolio helpers"]
  node_stats["Portfolio statistics"]
  node_risk["Historical VaR"]
end

subgraph group_outputs["Results and Plots"]
  node_allocation["Discrete allocation"]
  node_efficientplot["Efficient plots"]
  node_claplot["CLA frontier plot"]
  node_weightplot["Weight plots"]
end

node_caller(("Python caller"))
node_market[("Yahoo price data")]
node_pypfopt["PyPortfolioOpt"]

node_caller -->|"calls API"| node_efficient
node_caller -->|"calls API"| node_cla
node_efficient -->|"fetches prices"| node_helpers
node_cla -->|"fetches prices"| node_helpers
node_helpers -->|"reads history"| node_market
node_efficient -->|"requests stats"| node_helpers
node_cla -->|"requests stats"| node_helpers
node_efficient -->|"optimizes portfolio"| node_pypfopt
node_cla -->|"optimizes portfolio"| node_pypfopt
node_efficient -->|"requests allocation"| node_helpers
node_cla -->|"requests allocation"| node_helpers
node_helpers -->|"calculates shares"| node_allocation
node_efficient -->|"plots weights"| node_efficientplot
node_cla -->|"plots frontier"| node_claplot
node_cla -->|"plots weights"| node_weightplot
node_efficient -->|"plots weights"| node_weightplot
node_helpers -.->|"reads ticker history"| node_market

click node_efficient "https://github.com/apurvshah007/portfolio-optimizer/blob/master/efficient_frontier_portfolio_optimizer.py"
click node_cla "https://github.com/apurvshah007/portfolio-optimizer/blob/master/critical_line_algorithm_optimizer.py"
click node_helpers "https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py"
click node_stats "https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py"
click node_allocation "https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py"
click node_efficientplot "https://github.com/apurvshah007/portfolio-optimizer/blob/master/efficient_frontier_portfolio_optimizer.py"
click node_claplot "https://github.com/apurvshah007/portfolio-optimizer/blob/master/critical_line_algorithm_optimizer.py"
click node_weightplot "https://github.com/apurvshah007/portfolio-optimizer/blob/master/efficient_frontier_portfolio_optimizer.py"
click node_risk "https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.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_efficient,node_cla toneBlue
class node_helpers,node_stats,node_risk,node_market toneAmber
class node_allocation,node_efficientplot,node_claplot,node_weightplot toneMint
class node_caller,node_pypfopt toneIndigo
```

## Components

### Optimization APIs

- [Efficient optimizer](https://github.com/apurvshah007/portfolio-optimizer/blob/master/efficient_frontier_portfolio_optimizer.py): `efficient_frontier_portfolio_optimizer.py`
- [CLA optimizer](https://github.com/apurvshah007/portfolio-optimizer/blob/master/critical_line_algorithm_optimizer.py): `critical_line_algorithm_optimizer.py`

### Portfolio Analysis

- [Portfolio helpers](https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py): `basic_portfolio_functions.py`
- [Portfolio statistics](https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py): `basic_portfolio_functions.py`
- [Historical VaR](https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py): `basic_portfolio_functions.py`

### Results and Plots

- [Discrete allocation](https://github.com/apurvshah007/portfolio-optimizer/blob/master/basic_portfolio_functions.py): `basic_portfolio_functions.py`
- [Efficient plots](https://github.com/apurvshah007/portfolio-optimizer/blob/master/efficient_frontier_portfolio_optimizer.py): `efficient_frontier_portfolio_optimizer.py`
- [CLA frontier plot](https://github.com/apurvshah007/portfolio-optimizer/blob/master/critical_line_algorithm_optimizer.py): `critical_line_algorithm_optimizer.py`
- [Weight plots](https://github.com/apurvshah007/portfolio-optimizer/blob/master/efficient_frontier_portfolio_optimizer.py): `efficient_frontier_portfolio_optimizer.py`

### Other components

- **Python caller**
- **Yahoo price data**
- **PyPortfolioOpt**

## Connections

- Python caller → Efficient optimizer: calls API
- Python caller → CLA optimizer: calls API
- Efficient optimizer → Portfolio helpers: fetches prices
- CLA optimizer → Portfolio helpers: fetches prices
- Portfolio helpers → Yahoo price data: reads history
- Efficient optimizer → Portfolio helpers: requests stats
- CLA optimizer → Portfolio helpers: requests stats
- Efficient optimizer → PyPortfolioOpt: optimizes portfolio
- CLA optimizer → PyPortfolioOpt: optimizes portfolio
- Efficient optimizer → Portfolio helpers: requests allocation
- CLA optimizer → Portfolio helpers: requests allocation
- Portfolio helpers → Discrete allocation: calculates shares
- Efficient optimizer → Efficient plots: plots weights
- CLA optimizer → CLA frontier plot: plots frontier
- CLA optimizer → Weight plots: plots weights
- Efficient optimizer → Weight plots: plots weights
- Portfolio helpers → Yahoo price data: reads ticker history
