ワンクリックで
riskfolio-lib
Skill for using the Riskfolio-Lib Python library for portfolio optimization and quantitative strategic asset allocation.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Skill for using the Riskfolio-Lib Python library for portfolio optimization and quantitative strategic asset allocation.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
使用 akshare 获取中国金融市场实时数据和历史数据。当需要查询 A 股、港股、美股、指数、基金、期货等金融产品的实时行情、历史数据、财务报表时使用该技能。
Senior high-frequency factor construction workflow for turning a market mechanism into a causally valid, measurable, normalized, and implementable factor design. Trigger when the user asks to construct, formalize, document, or pseudo-implement microstructure / order flow / orderbook / event-time alpha factors, maker toxic-flow filters, liquidation cascade factors, OFI / imbalance signals, Hawkes smoothing design, or binary-mask factor decomposition. Do NOT use for pure backtest optimization, factor mining/search, label design, model selection, feature importance, or full strategy validation. Core output is a fixed research contract: mechanism, data contract, temporal contract, dimensions, mask semantics, aggregation, normalization, smoothing, observability risk, must-fail scenarios, and minimal sanity checks.
交易系统开发知识库,基于《Trading Systems》(Tomasini & Jaekle 2009)。支持:(1) 趋势跟踪/均值回归策略设计;(2) Walk Forward Analysis 参数优化;(3) 仓位管理(固定分数、固定比率);(4) 组合构建(权益线交叉、相关性管理)。触发于:开发交易系统、设计量化策略、参数优化验证、回测评估、仓位管理方法、多策略组合。
Industrial-grade workflow for developing, testing, and verifying financial ML strategies based on "Advances in Financial Machine Learning" (AFML) and "Machine Learning for Asset Managers" (MLAM) by Marcos López de Prado. Use when: (1) Building Dollar/Volume/Imbalance bars, (2) Triple-barrier or meta-labeling, (3) Sample weights and uniqueness, (4) Purged/embargoed cross-validation, (5) Feature importance (MDI/MDA/Clustered MDA), (6) Trend scanning, (7) Backtest verification (DSR/PSR/CPCV), (8) HRP portfolios, (9) Fractional differentiation, (10) CUSUM filtering, (11) Market microstructure analysis. Includes causal verification framework with validation metrics and book references. For code-level implementation, see afmlkit skill.
Evaluate whether a design pattern is warranted during feature design, refactoring, architecture changes, or code review, then choose a fitting pattern and a Python-idiomatic implementation. Use when code shows change pressure such as repeated if/elif branching, tangled object creation, oversized classes, mixed responsibilities, unstable dependencies, event fan-out, or requests to "apply a design pattern", "improve extensibility", "decouple modules", or "make this easier to evolve".
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of "Word doc", "word document", ".docx", or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a "report", "memo", "letter", "template", or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.
| name | riskfolio-lib |
| description | Skill for using the Riskfolio-Lib Python library for portfolio optimization and quantitative strategic asset allocation. |
| version | 0.1 |
| author | Hermes Agent |
| tags | ["finance","portfolio","optimization","python"] |
| category | data-science |
Riskfolio‑Lib is a Python package that provides advanced tools for portfolio construction, risk measurement, and optimization. It implements classical mean‑variance models, Black‑Litterman, risk‑parity, hierarchical risk parity, and many modern approaches.
pip install riskfolio-lib
Requires Python ≥3.7 and the libraries
numpy,pandas,scipy,matplotlib.
import pandas as pd
import riskfolio as rp
# 1️⃣ Load price data (e.g., daily close prices)
prices = pd.read_csv('prices.csv', index_col='Date', parse_dates=True)
# 2️⃣ Compute returns
returns = prices.pct_change().dropna()
# 3️⃣ Create a Portfolio object
port = rp.Portfolio(returns)
# 4️⃣ Estimate the risk‑return moments
port.assets_stats(method_mu='historical', method_cov='ledoit-wolf')
# 5️⃣ Choose an objective – here Minimum Variance (MV) with a risk‑budget constraint
def objective(w):
return port.portfolio_performance(w)
# 6️⃣ Run the optimizer (different solvers are available)
weights = port.optimization(model='MV', rm='MV', obj='MinRisk', l=0, hist=True)
print('Optimized weights:', weights)
# 7️⃣ Plot the efficient frontier (optional)
port.plot_frontier()
rm) – MV (variance), CVaR, MAD, SemiStd, EVaR, etc.obj) – MinRisk, MaxSharpe, Utility, ERC (risk parity), HRP (hierarchical), etc.port.set_bounds(), port.set_cardinality(), port.set_sector_constraints().SLSQP; alternatives include ECOS, CVXOPT, MOSEK (if installed).port = rp.Portfolio(returns)
port.assets_stats(method_mu='mean', method_cov='ledoit-wolf')
weights = port.optimization(model='MV', rm='MV', obj='Sharpe', l=0.5)
weights = port.optimization(model='ERC', rm='MV')
weights = port.optimization(model='HRP', rm='MV')
port = rp.Portfolio(returns)
port.black_litterman(tau=0.025, P=None, Q=None, pi='market')
weights = port.optimization(model='BL', rm='MV', obj='Sharpe')
| Function | Purpose |
|---|---|
rp.Portfolio(returns) | Initialise with a DataFrame of asset returns |
assets_stats() | Estimate mean, covariance, higher‑order moments |
set_bounds(lower, upper) | Impose weight limits |
set_constraints() | Add linear constraints (e.g., sector, turnover) |
optimization(model, rm, obj, **kwargs) | Run the optimizer – choose model (MV, ERC, HRP, BL, …) and risk measure |
plot_frontier() | Visualise efficient frontier |
plot_risk_contributions() | Show each asset’s contribution to portfolio risk |
When a downstream LLM needs to call a Riskfolio function, reference this skill and request the specific snippet. Example prompt to the model:
Use the `riskfolio-lib` skill to construct a minimum‑variance portfolio for the assets `AAPL`, `MSFT`, `GOOG` based on the CSV file `prices.csv`.
The skill will provide the exact code block and explain any required parameters.