# theisij/ml-and-the-implementable-efficient-frontier architecture

> Architecture diagram of the GitHub repository theisij/ml-and-the-implementable-efficient-frontier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/theisij/ml-and-the-implementable-efficient-frontier
- Repository: https://github.com/theisij/ml-and-the-implementable-efficient-frontier

## Overview

This repository is research code for reproducing the paper’s machine-learning return forecasts, portfolio-choice results, simulations, figures, and tables. The documented workflow uses supplied financial datasets, fits return-prediction models, builds portfolios for several analyses, then analyzes generated outputs. The README documents the scripts and broad stage ordering, but the R sources were not excerpted, so detailed calls between implementation modules are not asserted; the two sampled C++ utilities are shown without guessed callers.

Main entry points: [`slurm_build_portfolios.R`](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/slurm_build_portfolios.R) (Portfolio job runner), [`6 - Base analysis.R`](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Base%20analysis.R) (Base analysis), [`simulations/simulations.R`](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/simulations/simulations.R) (Simulation runner), [`2 - Fit Models.R`](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/2%20-%20Fit%20Models.R) (Fit prediction models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_forecast["Return forecasting"]
  node_model_job["Model job runner<br/>[slurm_fit_models.R]"]
  node_prepare_data["Prepare data<br/>[1 - Prepare Data.R]"]
  node_fit_models["Fit prediction models<br/>[2 - Fit Models.R]"]
  node_model_artifacts["Fitted models"]
end

subgraph group_portfolio["Portfolio research"]
  node_portfolio_jobs["Portfolio job runner"]
  node_portfolio_data["Prepare portfolio data"]
  node_portfolio_choice["Portfolio choice"]
  node_base_case["Base case<br/>[5 - Base case.R]"]
  node_ief["Efficient frontier"]
  node_feature_importance["Feature importance"]
  node_size_analysis["Size groups"]
  node_short_fees["Short-selling fees"]
end

subgraph group_simulation["Simulations"]
  node_simulation_run["Simulation runner<br/>[simulations.R]"]
  node_simulation_functions["Simulation methods<br/>[sim_functions.R]"]
  node_simulation_results["Simulation results<br/>[sim_results.R]"]
end

subgraph group_reporting["Analysis and reporting"]
  node_base_analysis["Base analysis"]
  node_economic_intuition["Economic intuition"]
  node_figures["Figures<br/>[7 - Figures.R]"]
  node_tables["Tables and numbers<br/>[7 - Tables.R]"]
end

subgraph group_utilities["Numerical utilities"]
  node_ewma["EWMA volatility<br/>[ewma.cpp]"]
  node_sqrtm["Matrix square root<br/>[sqrtm_cpp.cpp]"]
end

node_researcher(("Researcher"))
node_input_data["Financial datasets"]

node_researcher -->|"provides"| node_input_data
node_researcher -->|"runs"| node_model_job
node_model_job -->|"runs"| node_fit_models
node_input_data -->|"supplies"| node_prepare_data
node_prepare_data -.->|"prepares inputs"| node_fit_models
node_fit_models -->|"generates"| node_model_artifacts
node_researcher -->|"runs"| node_portfolio_jobs
node_model_artifacts -.->|"uses"| node_portfolio_jobs
node_portfolio_jobs -.->|"runs"| node_portfolio_data
node_portfolio_jobs -->|"implements"| node_portfolio_choice
node_portfolio_jobs -->|"generates"| node_base_case
node_portfolio_jobs -->|"generates"| node_ief
node_portfolio_jobs -->|"generates"| node_feature_importance
node_portfolio_jobs -->|"generates"| node_size_analysis
node_portfolio_jobs -->|"supports"| node_short_fees
node_researcher -->|"runs"| node_simulation_run
node_simulation_run -.->|"uses"| node_simulation_functions
node_simulation_run -->|"produces"| node_simulation_results
node_portfolio_jobs -->|"generates inputs"| node_base_analysis
node_base_analysis -.->|"analyzes"| node_economic_intuition
node_base_analysis -->|"supports"| node_figures
node_base_analysis -->|"supports"| node_tables

click node_model_job "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/slurm_fit_models.R"
click node_prepare_data "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/1%20-%20Prepare%20Data.R"
click node_fit_models "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/2%20-%20Fit%20Models.R"
click node_portfolio_jobs "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/slurm_build_portfolios.R"
click node_portfolio_data "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/4%20-%20Prepare%20Portfolio%20Data.R"
click node_portfolio_choice "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/0%20-%20Portfolio%20choice%20functions.R"
click node_base_case "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/5%20-%20Base%20case.R"
click node_ief "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Implementable%20efficient%20frontier.R"
click node_feature_importance "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Feature%20importance.R"
click node_size_analysis "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Performance%20across%20size%20distribution.R"
click node_short_fees "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Short%20selling%20fees.R"
click node_simulation_run "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/simulations/simulations.R"
click node_simulation_functions "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/simulations/sim_functions.R"
click node_simulation_results "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/simulations/sim_results.R"
click node_base_analysis "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Base%20analysis.R"
click node_economic_intuition "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Economic%20intuition.R"
click node_figures "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/7%20-%20Figures.R"
click node_tables "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/7%20-%20Tables.R"
click node_ewma "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/ewma.cpp"
click node_sqrtm "https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/sqrtm_cpp.cpp"

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_model_job,node_prepare_data,node_fit_models,node_model_artifacts toneBlue
class node_portfolio_jobs,node_portfolio_data,node_portfolio_choice,node_base_case,node_ief,node_feature_importance,node_size_analysis,node_short_fees toneAmber
class node_simulation_run,node_simulation_functions,node_simulation_results toneMint
class node_base_analysis,node_economic_intuition,node_figures,node_tables toneRose
class node_ewma,node_sqrtm,node_researcher,node_input_data toneIndigo
```

## Components

### Return forecasting

- [Model job runner](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/slurm_fit_models.R): `slurm_fit_models.R`
- [Prepare data](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/1%20-%20Prepare%20Data.R): `1 - Prepare Data.R`
- [Fit prediction models](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/2%20-%20Fit%20Models.R): `2 - Fit Models.R`
- **Fitted models**

### Portfolio research

- [Portfolio job runner](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/slurm_build_portfolios.R): `slurm_build_portfolios.R`
- [Prepare portfolio data](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/4%20-%20Prepare%20Portfolio%20Data.R): `4 - Prepare Portfolio Data.R`
- [Portfolio choice](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/0%20-%20Portfolio%20choice%20functions.R): `0 - Portfolio choice functions.R`
- [Base case](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/5%20-%20Base%20case.R): `5 - Base case.R`
- [Efficient frontier](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Implementable%20efficient%20frontier.R): `6 - Implementable efficient frontier.R`
- [Feature importance](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Feature%20importance.R): `6 - Feature importance.R`
- [Size groups](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Performance%20across%20size%20distribution.R): `6 - Performance across size distribution.R`
- [Short-selling fees](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Short%20selling%20fees.R): `6 - Short selling fees.R`

### Simulations

- [Simulation runner](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/simulations/simulations.R): `simulations/simulations.R`
- [Simulation methods](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/simulations/sim_functions.R): `simulations/sim_functions.R`
- [Simulation results](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/simulations/sim_results.R): `simulations/sim_results.R`

### Analysis and reporting

- [Base analysis](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Base%20analysis.R): `6 - Base analysis.R`
- [Economic intuition](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/6%20-%20Economic%20intuition.R): `6 - Economic intuition.R`
- [Figures](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/7%20-%20Figures.R): `7 - Figures.R`
- [Tables and numbers](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/7%20-%20Tables.R): `7 - Tables.R`

### Numerical utilities

- [EWMA volatility](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/ewma.cpp): `ewma.cpp`
- [Matrix square root](https://github.com/theisij/ml-and-the-implementable-efficient-frontier/blob/main/sqrtm_cpp.cpp): `sqrtm_cpp.cpp`

### Other components

- **Researcher**
- **Financial datasets**

## Connections

- Researcher → Financial datasets: provides (evidence: `README.md`)
- Researcher → Model job runner: runs (evidence: `README.md`)
- Model job runner → Fit prediction models: runs (evidence: `README.md`)
- Financial datasets → Prepare data: supplies (evidence: `README.md`)
- Prepare data → Fit prediction models: prepares inputs
- Fit prediction models → Fitted models: generates (evidence: `README.md`)
- Researcher → Portfolio job runner: runs (evidence: `README.md`)
- Fitted models → Portfolio job runner: uses
- Portfolio job runner → Prepare portfolio data: runs
- Portfolio job runner → Portfolio choice: implements (evidence: `README.md`)
- Portfolio job runner → Base case: generates (evidence: `README.md`)
- Portfolio job runner → Efficient frontier: generates (evidence: `README.md`)
- Portfolio job runner → Feature importance: generates (evidence: `README.md`)
- Portfolio job runner → Size groups: generates (evidence: `README.md`)
- Portfolio job runner → Short-selling fees: supports (evidence: `README.md`)
- Researcher → Simulation runner: runs (evidence: `README.md`)
- Simulation runner → Simulation methods: uses
- Simulation runner → Simulation results: produces (evidence: `README.md`)
- Portfolio job runner → Base analysis: generates inputs (evidence: `README.md`)
- Base analysis → Economic intuition: analyzes
- Base analysis → Figures: supports (evidence: `README.md`)
- Base analysis → Tables and numbers: supports (evidence: `README.md`)
