TCTyler Cheng 鄭迪珉

In development · 開發中

Portfolio Optimization Lab

投資組合優化實驗室

An open-source Python toolkit for mean-variance and risk-parity portfolio optimization built on CVXPY — plus a fixed-iteration ADMM reference kernel for research into hardware acceleration (FPGA / ASIC) of convex optimization for low-latency rebalancing.

以 CVXPY 實現均值-方差及風險平價投資組合優化的開源 Python 工具庫,並附固定迭代次數的 ADMM 參考核心,用於研究以硬件加速(FPGA / ASIC)凸優化、實現低延遲再平衡。

CVXPYNumPyMean-varianceRisk parityLedoit–WolfADMMFixed-point emulation

All charts on this page run on a synthetic market generated by the library. They show what the algorithms do, not any real-world result. Research and education only — not investment advice.
本頁所有圖表均使用程式隨機生成的模擬數據,只用於展示演算法運作,並非任何真實結果。僅供研究及教育用途,不構成投資建議。

01 · Mean-variance

Efficient frontier, live 效率前緣互動圖

Each grey dot is a random long-only portfolio. The gold curve is traced by CVXPY: for each target return, the minimum-variance portfolio. Drag the risk-aversion slider to move along it and watch the weights change.
灰點為隨機的純多頭組合;金色曲線由 CVXPY 逐點求解(在目標回報下的最小方差組合)。拖動風險厭惡滑桿,觀察權重變化。

aggressive · 進取γ = 3.0defensive · 保守
Model volatility · 模型波幅–
Model return · 模型回報–

Weights · 權重

02 · Risk parity

Equalising risk, sweep by sweep 逐步平衡風險貢獻

Starting from equal weights, coordinate descent adjusts one asset at a time until every asset contributes the same share of total risk. Each update is a closed-form root — only multiply-adds and one square root.
由等權重出發,坐標下降法逐一調整資產,直至每項資產對總風險的貢獻相同。每步更新都有解析解,只需乘加運算及一次開方。

Risk contribution · 風險貢獻 — dashed line: equal share 1/N · 虛線為平均目標

Weights · 權重

Start: equal weights

03 · Research direction

Toward hardware-accelerated rebalancing 硬件加速再平衡(研究方向)

Low-latency rebalancing needs a solver with predictable run time. An ADMM iteration with a pre-factorised KKT matrix uses only matrix-vector products, additions and clamps for a fixed number of iterations — a structure that maps naturally onto pipelined FPGA / ASIC logic. This repository contains the software reference model only; no hardware has been built.
低延遲再平衡需要運行時間可預測的求解器。預先分解 KKT 矩陣後,每次 ADMM 迭代只涉及矩陣向量乘法、加法及截斷,迭代次數固定,適合映射到流水線式 FPGA / ASIC 電路。本代碼庫只包含軟件參考模型,尚未製作任何硬件。

Market datasynthetic · 模擬數據 Estimate μ, ΣLedoit–Wolf · 估計 Factorise KKTonce, offline預先分解(一次) ADMM × K iterations固定迭代次數 M·v clamp dual += pipelined · 流水線 Target weights→ trades · 交易

Concept diagram of the solver data path · 求解器數據通路概念圖(研究方向,非已實現硬件)

Does reduced precision still converge? 降低精度仍能收斂嗎?

The same 200-iteration ADMM run in float64, float32 and emulated 12-bit fixed-point. Lower precision converges at first, then stalls at a noise floor — the kind of trade-off (word length vs. accuracy vs. chip area) the hardware research studies.
同一個 200 次迭代的 ADMM 分別以 float64、float32 及模擬 12 位定點數運行。低精度起初同樣收斂,之後停在噪聲底線——這正是硬件研究要權衡的問題(字長、精度與晶片面積)。

04 · Use it

Five lines to a portfolio 快速上手

# pip install -e .   (from the cloned repository)
import portfolio_lab as pl

market = pl.synthetic_market(n_assets=8, seed=0)        # synthetic data only
mu     = pl.mean_returns(market.returns)
cov, _ = pl.ledoit_wolf_covariance(market.returns)

pl.max_sharpe(mu, cov).weights                 # mean-variance (CVXPY)
pl.risk_parity(cov)                            # equal risk contributions
pl.rebalance(current, mu, cov, gamma=3, cost=0.002)  # with transaction costs
pl.mean_variance_admm(mu, cov, gamma=3, precision="float32")  # hardware reference kernel