This repo is for demonstration purposes only. It’s a stripped-down snapshot from a private repository, so some proprietary or more advanced techniques have been omitted or replaced with simpler stubs. Please note that this is not meant to be a fully advanced or production-ready codebase.
├── plotting # Plotting helpers
│ ├── factors_modelval.py
│ ├── factors.py
│ ├── portfolio_opt.py
│ └── regime_clustering.py
│
├── factor_model # Proprietary (intro samples only)
│ ├── fundamental
│ │ ├── exposure_builder.py
│ │ ├── factor_definitions.py
│ │ └── fundamental_fitter.py
│ ├── statistical_fitter.py
│ └── factor_model.py
│
├── portfolio_opt # Proprietary (intro samples only)
│ ├── constraints
│ │ ├── notional
│ │ │ ├── basket_notional_constraint.py
│ │ │ └── turnover_constraint.py
│ │ ├── base.py
│ │ ├── setup_constraint.py
│ │ └── structured_constraint.py
│ ├── objectives
│ │ ├── base.py
│ │ ├── factor_risk_objective.py
│ │ └── linear_objective.py
│ ├── settings.py
│ └── cvxpy_wrapper.py
│
├── regimes # Proprietary (backend code not included, more on https://github.com/andreab0/demo-tsrd)
│ ├── helpers
│ │ └── windowing.py
│ └── utils.py
│
├── signals # A sample momentum signal
│ └── momentum.py
│
├── Sample 1 - Factor Models.ipynb
├── Sample 2 - Regime Clustering.ipynb
│
└── README.md
-
Factor Model
Demonstrates how to build both fundamental and statistical factor risk models.- Fundamental approach: uses categorical or numeric exposures, then fits factor returns via simple OLS or Huber regression.
- Statistical approach: a basic iterative SVD-based model to estimate factors.
-
Portfolio Optimization
Includes a lightweight CVXPY wrapper and sample constraints/objectives (e.g., turnover constraints, factor risk minimization).- This is only a demo—actual advanced constraints or solvers are omitted or stubbed.
-
Regime Detection
Illustrates clustering-based regime identification using placeholders for Earth Mover’s Distance (EMD) and K-means.
An additional demo-repo with a collection of sophisticated regime detection models is available here . Please message me for access.- For background, see Earth Mover's Distance and K-means clustering.
More literature on the subject can be found here.
- For background, see Earth Mover's Distance and K-means clustering.
-
Signals
A toy momentum signal generator (momentum.py).
- Not Advanced: This code is deliberately simplified and is not intended as a robust, production-grade system.
- Partial Extraction: Certain proprietary algorithms and advanced logic are not included (using serialized files instead).
- For Demo Only: Provided as a reference for exploring basic factor modeling, optimization, and clustering concepts.
- CVXPY Documentation – For modeling and solving convex optimization problems.
- Convex Optimization by Boyd & Vandenberghe – Foundational text on convex optimization techniques.
- Fama-French Factor Models – Introduction to popular fundamental factor models.
- Principal Component Analysis – Basis for the statistical factor model fitter using SVD.
- Robust Regression (HuberRegressor) – Technique for robust regression used in factor model fitting.
- Earth Mover’s Distance – Measure used in regime clustering to compare distributions.
- K-means Clustering – Standard algorithm for partitioning data into clusters.