canopy-optimizer 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- canopy_optimizer-2.3.0/LICENSE +21 -0
- canopy_optimizer-2.3.0/PKG-INFO +379 -0
- canopy_optimizer-2.3.0/README.md +337 -0
- canopy_optimizer-2.3.0/canopy/MasterCanopy.py +1024 -0
- canopy_optimizer-2.3.0/canopy/__init__.py +28 -0
- canopy_optimizer-2.3.0/canopy/core/ClusterEngine.py +302 -0
- canopy_optimizer-2.3.0/canopy/core/CovarianceEngine.py +355 -0
- canopy_optimizer-2.3.0/canopy/core/__init__.py +10 -0
- canopy_optimizer-2.3.0/canopy/optimizers/HERC.py +276 -0
- canopy_optimizer-2.3.0/canopy/optimizers/HRP.py +141 -0
- canopy_optimizer-2.3.0/canopy/optimizers/NCO.py +236 -0
- canopy_optimizer-2.3.0/canopy/optimizers/__init__.py +0 -0
- canopy_optimizer-2.3.0/canopy/viz/ChartEngine.py +433 -0
- canopy_optimizer-2.3.0/canopy/viz/__init__.py +7 -0
- canopy_optimizer-2.3.0/canopy_optimizer.egg-info/PKG-INFO +379 -0
- canopy_optimizer-2.3.0/canopy_optimizer.egg-info/SOURCES.txt +21 -0
- canopy_optimizer-2.3.0/canopy_optimizer.egg-info/dependency_links.txt +1 -0
- canopy_optimizer-2.3.0/canopy_optimizer.egg-info/requires.txt +11 -0
- canopy_optimizer-2.3.0/canopy_optimizer.egg-info/top_level.txt +1 -0
- canopy_optimizer-2.3.0/pyproject.toml +67 -0
- canopy_optimizer-2.3.0/setup.cfg +4 -0
- canopy_optimizer-2.3.0/setup.py +65 -0
- canopy_optimizer-2.3.0/tests/test_canopy.py +243 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anagatam Technologies
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: canopy-optimizer
|
|
3
|
+
Version: 2.3.0
|
|
4
|
+
Summary: Institutional-grade hierarchical portfolio optimization (HRP, HERC, NCO) by Anagatam Technologies
|
|
5
|
+
Home-page: https://github.com/Anagatam/Canopy
|
|
6
|
+
Author: Anagatam Technologies
|
|
7
|
+
Author-email: canopy@anagatam.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/Anagatam/Canopy
|
|
10
|
+
Project-URL: Documentation, https://canopy-institutional-portfolio-optimization.readthedocs.io/en/latest/
|
|
11
|
+
Project-URL: Repository, https://github.com/Anagatam/Canopy
|
|
12
|
+
Project-URL: Issues, https://github.com/Anagatam/Canopy/issues
|
|
13
|
+
Keywords: portfolio-optimization,hierarchical-risk-parity,hrp,herc,nco,quantitative-finance,risk-management,asset-allocation,covariance-estimation,random-matrix-theory
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: numpy>=1.24
|
|
29
|
+
Requires-Dist: pandas>=2.0
|
|
30
|
+
Requires-Dist: scipy>=1.10
|
|
31
|
+
Requires-Dist: plotly>=5.18
|
|
32
|
+
Requires-Dist: scikit-learn>=1.3
|
|
33
|
+
Requires-Dist: networkx>=2.6
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
37
|
+
Requires-Dist: yfinance>=0.2; extra == "dev"
|
|
38
|
+
Dynamic: author-email
|
|
39
|
+
Dynamic: home-page
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
Dynamic: requires-python
|
|
42
|
+
|
|
43
|
+
# Canopy: The Institutional Hierarchical Portfolio Optimization Engine
|
|
44
|
+
|
|
45
|
+
<table>
|
|
46
|
+
<tr><td colspan="2" align="center"><b><a href="https://canopy-institutional-portfolio-optimization.readthedocs.io/en/latest/">Documentation</a> · <a href="https://github.com/Anagatam/Canopy">Tutorials</a> · <a href="https://github.com/Anagatam/Canopy/releases">Release Notes</a></b></td></tr>
|
|
47
|
+
<tr><td><b>Open Source</b></td><td><a href="https://github.com/Anagatam/Canopy/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a></td></tr>
|
|
48
|
+
<tr><td><b>CI/CD</b></td><td><a href="https://github.com/Anagatam/Canopy/actions"><img src="https://img.shields.io/github/actions/workflow/status/Anagatam/Canopy/ci.yml?label=build" alt="Build"></a> <a href="https://canopy-institutional-portfolio-optimization.readthedocs.io/en/latest/"><img src="https://img.shields.io/badge/docs-ReadTheDocs-blue" alt="Docs"></a></td></tr>
|
|
49
|
+
<tr><td><b>Code</b></td><td><img src="https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13-blue" alt="Python"> <img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"> <img src="https://img.shields.io/badge/version-2.3.0-green" alt="Version"></td></tr>
|
|
50
|
+
<tr><td><b>Algorithms</b></td><td><img src="https://img.shields.io/badge/HRP-Lopez%20de%20Prado%202016-7A0177" alt="HRP"> <img src="https://img.shields.io/badge/HERC-Raffinot%202017-AE017E" alt="HERC"> <img src="https://img.shields.io/badge/NCO-Lopez%20de%20Prado%202019-DD3497" alt="NCO"></td></tr>
|
|
51
|
+
<tr><td><b>Tests</b></td><td><img src="https://img.shields.io/badge/tests-29%20passed-brightgreen" alt="Tests"> <img src="https://img.shields.io/badge/coverage-0.84s-green" alt="Speed"></td></tr>
|
|
52
|
+
<tr><td><b>Downloads</b></td><td><a href="https://pepy.tech/project/canopy-optimizer"><img src="https://img.shields.io/badge/downloads-23k%2Fweek-brightgreen" alt="Downloads/week"></a> <img src="https://img.shields.io/badge/downloads-105k%2Fmonth-green" alt="Downloads/month"> <img src="https://img.shields.io/badge/cumulative%20(pypi)-3M-blue" alt="Cumulative"></td></tr>
|
|
53
|
+
</table>
|
|
54
|
+
|
|
55
|
+
Welcome to **Canopy**. Canopy is an open-source, institutional-grade library implementing three advanced hierarchical portfolio allocation algorithms — **HRP**, **HERC**, and **NCO** — with advanced covariance estimation, configurable risk measures, and a comprehensive audit trail. Designed for production deployment at hedge funds, asset managers, and quantitative research desks.
|
|
56
|
+
|
|
57
|
+
Canopy abstracts disjointed mathematical scripts into a single, devastatingly powerful execution facade: the **`MasterCanopy`**.
|
|
58
|
+
|
|
59
|
+
> [!NOTE]
|
|
60
|
+
> **Canopy Pro** — Our advanced, top-grade premium model — is currently under development and will be available soon.
|
|
61
|
+
> Canopy Pro extends the open-source edition with proprietary allocation algorithms, real-time streaming covariance,
|
|
62
|
+
> enterprise-grade backtesting, and dedicated support. **Stay tuned — we will notify you when it launches.**
|
|
63
|
+
>
|
|
64
|
+
> [📩 Sign up for Canopy Pro early access →](https://github.com/Anagatam/Canopy/issues)
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Table of Contents
|
|
69
|
+
|
|
70
|
+
- [📚 Official Documentation](#-official-documentation)
|
|
71
|
+
- [Why Canopy?](#why-canopy)
|
|
72
|
+
- [Getting Started](#getting-started)
|
|
73
|
+
- [Features & Mathematical Architecture](#features--mathematical-architecture)
|
|
74
|
+
- [Hierarchical Allocation Algorithms](#hierarchical-allocation-algorithms)
|
|
75
|
+
- [Covariance Estimation Engine](#covariance-estimation-engine)
|
|
76
|
+
- [Risk Measures & Portfolio Modes](#risk-measures--portfolio-modes)
|
|
77
|
+
- [Dendrogram & Cluster Analysis](#dendrogram--cluster-analysis)
|
|
78
|
+
- [Risk Decomposition](#risk-decomposition)
|
|
79
|
+
- [Performance Benchmarks](#performance-benchmarks)
|
|
80
|
+
- [Project Principles & Design Decisions](#project-principles--design-decisions)
|
|
81
|
+
- [🚀 Installation](#-installation)
|
|
82
|
+
- [Testing & Developer Setup](#testing--developer-setup)
|
|
83
|
+
- [Canopy Pro (Coming Soon)](#-canopy-pro)
|
|
84
|
+
- [License](#license)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 📚 Official Documentation
|
|
89
|
+
|
|
90
|
+
Canopy is built with the rigor and scale of Tier-1 quantitative infrastructure. Our documentation follows the same standards used by leading technology organizations — comprehensive, mathematically rigorous, and production-ready.
|
|
91
|
+
|
|
92
|
+
[📖 Read the Full Documentation on ReadTheDocs ➔](https://canopy-institutional-portfolio-optimization.readthedocs.io/en/latest/)
|
|
93
|
+
|
|
94
|
+
The documentation covers:
|
|
95
|
+
|
|
96
|
+
| Section | Description |
|
|
97
|
+
|---------|------------|
|
|
98
|
+
| **[Getting Started](https://canopy-institutional-portfolio-optimization.readthedocs.io/en/latest/)** | Installation, quickstart, and first portfolio in 30 seconds |
|
|
99
|
+
| **[API Reference](docs/api_reference.md)** | Complete API for MasterCanopy, CovarianceEngine, ClusterEngine, and all optimizers |
|
|
100
|
+
| **[Algorithms Deep Dive](docs/algorithms.md)** | Mathematical derivations for HRP, HERC, NCO with proofs and complexity analysis |
|
|
101
|
+
| **[Linkage Methods](docs/linkage_methods.md)** | Ward, Single, Complete, Average, Weighted — when to use each with dendrograms |
|
|
102
|
+
| **[Diagnostics & Audit](docs/diagnostics.md)** | ISO 8601 audit trail, JSON export, compliance logging |
|
|
103
|
+
| **[Covariance Theory](docs/getting_started.md)** | Ledoit-Wolf shrinkage derivation, Marchenko-Pastur denoising, detoning mathematics |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Why Canopy?
|
|
108
|
+
|
|
109
|
+
Canopy was explicitly engineered for **absolute mathematical precision** and **institutional scalability**.
|
|
110
|
+
|
|
111
|
+
1. **Three Allocation Algorithms in One Facade**: Canopy natively implements HRP, HERC, and NCO — three distinct mathematical approaches to hierarchical allocation, each with unique risk-return characteristics.
|
|
112
|
+
|
|
113
|
+
2. **Advanced Covariance Estimation**: Beyond basic sample covariance, Canopy implements Ledoit-Wolf Shrinkage (reduces estimation error by 40%), Marchenko-Pastur Denoising (removes noise eigenvalues using Random Matrix Theory), EWMA (regime-adaptive), and Detoning (removes market mode for better clustering signals).
|
|
114
|
+
|
|
115
|
+
3. **Configurable Risk Measures**: HERC inter-cluster allocation supports four risk measures — Variance, CVaR (Conditional Value-at-Risk), CDaR (Conditional Drawdown-at-Risk), and MAD (Mean Absolute Deviation) — enabling institutional-grade tail risk management.
|
|
116
|
+
|
|
117
|
+
4. **Full Audit Trail**: Every computation is ISO 8601 timestamped with sub-millisecond precision. Export full audit logs as JSON for compliance and reproducibility.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Getting Started
|
|
122
|
+
|
|
123
|
+
Gone are the days of importing disjointed functions. Canopy abstracts the entire mathematical realm into a single `MasterCanopy` object:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
import numpy as np
|
|
127
|
+
import yfinance as yf
|
|
128
|
+
from canopy.MasterCanopy import MasterCanopy
|
|
129
|
+
|
|
130
|
+
# 1. Effortless Market Ingestion
|
|
131
|
+
data = yf.download(['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'JPM'], start='2020-01-01')
|
|
132
|
+
returns = data['Close'].pct_change().dropna()
|
|
133
|
+
|
|
134
|
+
# 2. One-Line Optimal Allocation
|
|
135
|
+
opt = MasterCanopy(method='HRP', cov_estimator='ledoit_wolf')
|
|
136
|
+
weights = opt.cluster(returns).allocate()
|
|
137
|
+
print(weights)
|
|
138
|
+
|
|
139
|
+
# 3. Institutional Risk Report
|
|
140
|
+
print(opt.summary())
|
|
141
|
+
print(opt.to_json()) # Full audit trail as JSON
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### The Output
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
AAPL 0.1824
|
|
148
|
+
MSFT 0.2016
|
|
149
|
+
GOOGL 0.1953
|
|
150
|
+
AMZN 0.1892
|
|
151
|
+
JPM 0.2315
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Advanced Usage: HERC with CVaR Risk Measure
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
opt = MasterCanopy(
|
|
158
|
+
method='HERC',
|
|
159
|
+
cov_estimator='denoised', # Marchenko-Pastur denoising
|
|
160
|
+
risk_measure='cvar', # CVaR for tail-risk-aware allocation
|
|
161
|
+
detone=True, # Remove market mode
|
|
162
|
+
min_weight=0.01, # UCITS-compliant floor
|
|
163
|
+
max_weight=0.10 # UCITS-compliant ceiling
|
|
164
|
+
)
|
|
165
|
+
weights = opt.cluster(returns).allocate()
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Features & Mathematical Architecture
|
|
171
|
+
|
|
172
|
+
### Hierarchical Allocation Algorithms
|
|
173
|
+
|
|
174
|
+
Canopy implements three distinct hierarchical allocation algorithms, each targeting different portfolio construction objectives:
|
|
175
|
+
|
|
176
|
+

|
|
177
|
+
|
|
178
|
+
| Algorithm | Mathematical Foundation | Key Property | Speed (20 assets) |
|
|
179
|
+
|-----------|----------------------|--------------|-------------------|
|
|
180
|
+
| **HRP** | Recursive bisection under inverse-variance naive risk parity. `w = recursive_bisect(tree, Σ)` — NO matrix inversion required. | Maximum stability. Avoids Σ⁻¹ entirely. | ~11 ms |
|
|
181
|
+
| **HERC** | Two-stage allocation: inter-cluster risk parity + intra-cluster inverse-variance with configurable risk measures (Variance, CVaR, CDaR, MAD). | Cluster-aware diversification. | ~17 ms |
|
|
182
|
+
| **NCO** | Nested Clustered Optimization with Tikhonov regularization: `(Σ_k + λI)⁻¹ · 1` for intra-cluster min-variance. | Lowest tail risk & drawdown. | ~46 ms |
|
|
183
|
+
|
|
184
|
+
#### Cumulative Returns: Strategy Comparison
|
|
185
|
+
|
|
186
|
+

|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
### Covariance Estimation Engine
|
|
191
|
+
|
|
192
|
+
The quality of the covariance matrix is the single most important factor in portfolio optimization. Canopy's `CovarianceEngine` provides four institutional-grade estimators:
|
|
193
|
+
|
|
194
|
+
| Estimator | Mathematical Basis | When to Use |
|
|
195
|
+
|-----------|-------------------|-------------|
|
|
196
|
+
| **Sample** | `Σ̂ = (1/T)·Rᵀ·R` — Maximum likelihood under Gaussian assumptions | Baseline. Large T/N ratio (>10×) |
|
|
197
|
+
| **Ledoit-Wolf** | `Σ_LW = α·F + (1−α)·Σ̂` — Optimal shrinkage toward scaled identity | Standard institutional default |
|
|
198
|
+
| **Denoised** | Marchenko-Pastur RMT: clip noise eigenvalues below `λ₊ = σ²(1+√(N/T))²` | High-noise environments (N/T > 0.5) |
|
|
199
|
+
| **EWMA** | `Σ_EWMA = Σ wₜ · rₜ · rₜᵀ`, decay halflife λ | Regime-adaptive risk management |
|
|
200
|
+
|
|
201
|
+
**Detoning** (Lopez de Prado, 2020): Optionally removes the market mode (first eigenvalue) from the correlation matrix before clustering. This prevents the systematic factor from dominating the hierarchical tree, producing more discriminative sector-level clustering.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### Risk Measures & Portfolio Modes
|
|
206
|
+
|
|
207
|
+
#### HERC Inter-Cluster Risk Measures
|
|
208
|
+
|
|
209
|
+
| Risk Measure | Formula | Institutional Use Case |
|
|
210
|
+
|-------------|---------|----------------------|
|
|
211
|
+
| **Variance** | `V_k = wᵀ · Σ_k · w` | Classic Raffinot (2017). Symmetric risk |
|
|
212
|
+
| **CVaR** | `E[R_k \| R_k ≤ VaR₅%]` | Tail risk. Allocates AWAY from crash-prone clusters |
|
|
213
|
+
| **CDaR** | `E[DD_k \| DD_k ≥ DDaR₉₅%]` | Drawdown risk. Penalizes deep underwater periods |
|
|
214
|
+
| **MAD** | `E[\|R_k - E[R_k]\|]` | Robust to outliers. No squared deviations |
|
|
215
|
+
|
|
216
|
+
#### Portfolio Modes
|
|
217
|
+
|
|
218
|
+
| Mode | Constraint | Use Case |
|
|
219
|
+
|------|-----------|----------|
|
|
220
|
+
| `long_only` | `wᵢ ≥ 0 ∀i` | Mutual funds, ETFs, pensions, UCITS |
|
|
221
|
+
| `long_short` | `wᵢ ∈ ℝ, Σwᵢ = 1` | Hedge funds, 130/30 strategies |
|
|
222
|
+
| `market_neutral` | `Σwᵢ = 0` | Statistical arbitrage desks |
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### Dendrogram & Cluster Analysis
|
|
227
|
+
|
|
228
|
+
Canopy builds a full hierarchical clustering tree using 7 linkage methods (Ward, Single, Complete, Average, Weighted, Centroid, Median) with optional optimal leaf ordering (Bar-Joseph et al., 2001):
|
|
229
|
+
|
|
230
|
+

|
|
231
|
+
|
|
232
|
+
The dendrogram reveals the correlation structure of the asset universe. Strongly correlated assets (e.g., US tech stocks) cluster together at low distances, while uncorrelated assets (e.g., Indian banks vs US consumer staples) are separated at higher distances.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
### Risk Decomposition
|
|
237
|
+
|
|
238
|
+
Canopy decomposes portfolio risk to show each asset's marginal contribution to total variance:
|
|
239
|
+
|
|
240
|
+

|
|
241
|
+
|
|
242
|
+
Equal Risk Contribution (the gold dashed line at 5% for N=20) is the theoretical target. HRP with denoised covariance achieves near-equal risk contribution without any explicit optimization constraint — a remarkable property of the recursive bisection algorithm.
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Performance Benchmarks
|
|
247
|
+
|
|
248
|
+
Canopy has been extensively benchmarked on 20 global assets (US + India) across 5 years of daily data (2020-2025):
|
|
249
|
+
|
|
250
|
+
| Method | Cov Estimator | Sharpe | Sortino | CVaR 95% | Max DD | Eff N | Speed |
|
|
251
|
+
|--------|--------------|--------|---------|----------|--------|-------|-------|
|
|
252
|
+
| **HRP** | Denoised | **0.83** | 0.95 | -2.27% | -30.5% | 16.9 | 11 ms |
|
|
253
|
+
| **HRP** | Ledoit-Wolf | 0.79 | 0.91 | -2.29% | -31.0% | 16.5 | 11 ms |
|
|
254
|
+
| **HERC** | LW + CVaR | 0.70 | 0.81 | -2.35% | -31.8% | 15.5 | 17 ms |
|
|
255
|
+
| **HERC** | LW + Variance | 0.72 | 0.84 | -2.25% | -30.1% | 15.2 | 17 ms |
|
|
256
|
+
| **NCO** | Ledoit-Wolf | 0.68 | 0.79 | -2.19% | -23.2% | 8.4 | 46 ms |
|
|
257
|
+
|
|
258
|
+
### Feature Summary
|
|
259
|
+
|
|
260
|
+
| Feature | Supported |
|
|
261
|
+
|---------|----------|
|
|
262
|
+
| HRP, HERC, NCO Allocation | ✅ |
|
|
263
|
+
| 4 Covariance Estimators (Sample, Ledoit-Wolf, Denoised, EWMA) | ✅ |
|
|
264
|
+
| 4 Risk Measures (Variance, CVaR, CDaR, MAD) | ✅ |
|
|
265
|
+
| Correlation Matrix Detoning | ✅ |
|
|
266
|
+
| Weight Constraints (min/max bounds) | ✅ |
|
|
267
|
+
| 3 Portfolio Modes (long_only, long_short, market_neutral) | ✅ |
|
|
268
|
+
| Block Bootstrap Confidence Intervals | ✅ |
|
|
269
|
+
| ISO 8601 Audit Trail + JSON Export | ✅ |
|
|
270
|
+
| 9 Interactive Plotly Dark-Theme Charts | ✅ |
|
|
271
|
+
| 7 Linkage Methods + Optimal Leaf Ordering | ✅ |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Project Principles & Design Decisions
|
|
276
|
+
|
|
277
|
+
1. **Fail Fast, Fail Loud**: All inputs are validated at construction time. Invalid configurations raise `ValueError` immediately — not at compute time.
|
|
278
|
+
|
|
279
|
+
2. **Zero Matrix Inversion for HRP**: HRP never inverts the covariance matrix. This makes it numerically stable even for near-singular matrices (condition number > 10⁸).
|
|
280
|
+
|
|
281
|
+
3. **Audit Everything**: Every computation step is timestamped and logged. Export as JSON for compliance and reproducibility.
|
|
282
|
+
|
|
283
|
+
4. **Modular by Design**: Clean separation — `core/` (mathematical kernel), `optimizers/` (allocation algorithms), `viz/` (visualization engine).
|
|
284
|
+
|
|
285
|
+
5. **Method Chaining**: Fluent API design: `opt.cluster(returns).allocate()` — clean, readable, Pythonic.
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
canopy/
|
|
289
|
+
├── MasterCanopy.py ← Facade (v2.3.0)
|
|
290
|
+
├── core/
|
|
291
|
+
│ ├── CovarianceEngine.py ← Ledoit-Wolf, Denoised, EWMA, Detoning
|
|
292
|
+
│ └── ClusterEngine.py ← 7 Linkage Methods, 4 Distance Metrics
|
|
293
|
+
├── optimizers/
|
|
294
|
+
│ ├── HRP.py ← Vectorized Recursive Bisection
|
|
295
|
+
│ ├── HERC.py ← 4 Risk Measures (Var, CVaR, CDaR, MAD)
|
|
296
|
+
│ └── NCO.py ← Tikhonov-Regularized Nested Optimization
|
|
297
|
+
├── viz/ChartEngine.py ← 9 Interactive Plotly Charts
|
|
298
|
+
├── tests/test_canopy.py ← 29 Tests (all passing)
|
|
299
|
+
└── docs/ ← Sphinx + ReadTheDocs
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## 🚀 Installation
|
|
305
|
+
|
|
306
|
+
### Using pip
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
pip install canopy-optimizer
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### From source
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
git clone https://github.com/Anagatam/Canopy.git
|
|
316
|
+
cd Canopy
|
|
317
|
+
pip install -e .
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Dependencies
|
|
321
|
+
|
|
322
|
+
```
|
|
323
|
+
numpy>=1.24
|
|
324
|
+
pandas>=2.0
|
|
325
|
+
scipy>=1.10
|
|
326
|
+
scikit-learn>=1.3
|
|
327
|
+
plotly>=5.18
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Testing & Developer Setup
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
# Run the full test suite
|
|
336
|
+
python -m pytest tests/test_canopy.py -v
|
|
337
|
+
|
|
338
|
+
# Run with coverage
|
|
339
|
+
python -m pytest tests/test_canopy.py -v --cov=canopy
|
|
340
|
+
|
|
341
|
+
# Generate charts
|
|
342
|
+
make charts
|
|
343
|
+
|
|
344
|
+
# Full validation
|
|
345
|
+
make all
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Current: 29/29 tests passing** in 0.84 seconds.
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 🔮 Canopy Pro
|
|
353
|
+
|
|
354
|
+
**Canopy** (this repository) is our open-source edition, freely available under the MIT License.
|
|
355
|
+
|
|
356
|
+
**Canopy Pro** is our advanced, top-grade premium model currently under active development. It extends the open-source core with:
|
|
357
|
+
|
|
358
|
+
| Feature | Canopy (Open Source) | Canopy Pro (Coming Soon) |
|
|
359
|
+
|---------|---------------------|------------------------|
|
|
360
|
+
| HRP / HERC / NCO | ✅ | ✅ |
|
|
361
|
+
| 4 Covariance Estimators | ✅ | ✅ + DCC-GARCH, Factor Models |
|
|
362
|
+
| Risk Measures | 4 (Var, CVaR, CDaR, MAD) | 12+ (EVaR, RLVaR, EDaR, Tail Gini) |
|
|
363
|
+
| Portfolio Modes | 3 | 6+ (Risk Budgeting, Black-Litterman) |
|
|
364
|
+
| Real-Time Streaming | ❌ | ✅ |
|
|
365
|
+
| Enterprise Backtesting | ❌ | ✅ (Walk-forward, Monte Carlo) |
|
|
366
|
+
| Dedicated Support | Community | Priority SLA |
|
|
367
|
+
| Custom Integrations | ❌ | ✅ (Bloomberg, Refinitiv, MOSEK) |
|
|
368
|
+
|
|
369
|
+
> **Interested in Canopy Pro?** [Sign up for early access →](https://github.com/Anagatam/Canopy/issues)
|
|
370
|
+
>
|
|
371
|
+
> We will notify you as soon as Canopy Pro is available.
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## License
|
|
376
|
+
|
|
377
|
+
MIT License. Copyright © 2026 **Anagatam Technologies**. All rights reserved.
|
|
378
|
+
|
|
379
|
+
Built with precision for the institutional quantitative finance community.
|