volatility
$
npx mdskill add HKUDS/Vibe-Trading/volatilityTrades mean reversion by ranking historical volatility percentiles for OHLCV data.
- Helps capture volatility mean reversion in low- and high-volatility regimes.
- Integrates with OHLCV data and uses annualization factors like 252 or 365.
- Decides based on percentile thresholds for long, short, or hold positions.
- Presents results through signal generation for trading actions.
SKILL.md
.github/skills/volatilityView on GitHub ↗
--- name: volatility description: Volatility strategy. Trades mean reversion based on percentile ranking of historical volatility (HV). Suitable for any OHLCV data. category: strategy --- # Volatility Strategy ## Purpose Uses percentile ranking of historical volatility (HV) to capture volatility mean reversion: build positions in low-volatility regimes while waiting for volatility expansion, and exit or short in high-volatility regimes to capture contraction. ## Signal Logic 1. **Compute HV**: annualized standard deviation of returns over the past `hv_window` days 2. **Percentile ranking**: percentile position of HV within the past `lookback` days (0-100) 3. **Signal generation**: - Percentile < `low_pct` → go long (volatility is low, waiting for expansion) - Percentile > `high_pct` → exit / go short (volatility is high, waiting for contraction) - Middle region → keep the current position ## Key Implementation Details - HV = `returns.rolling(hv_window).std() * sqrt(252)` (annualized) - Percentile = `hv.rolling(lookback).rank(pct=True) * 100` - For cryptocurrencies, use 365 instead of 252 as the annualization factor ## Parameters | Parameter | Default | Description | |------|--------|------| | hv_window | 20 | Historical volatility calculation window | | lookback | 120 | Lookback period for percentile ranking | | low_pct | 20.0 | Low-volatility threshold (percentile) | | high_pct | 80.0 | High-volatility threshold (percentile) | | annualize | 252 | Annualization factor (252 for China A-shares, 365 for crypto) | ## Common Pitfalls - Before the lookback window is filled, there is not enough data to compute percentiles, so the signal should be 0 (`fillna`) - Volatility is not direction. Going long in low-volatility regimes does not guarantee price appreciation; it only means volatility expansion is statistically more likely - Cryptocurrencies trade 7x24, so `annualize` should be set to 365 ## Dependencies ```bash pip install pandas numpy ``` ## Signal Convention - `1` = long (low-volatility regime), `-1` = short (high-volatility regime), `0` = stand aside
More from HKUDS/Vibe-Trading
- adr-hshareADR/H-share/A-share cross-listing premium analysis — track pricing gaps between US-listed ADRs, HK-listed H-shares, and A-shares for arbitrage signals, dual-listing valuation, and delisting risk assessment.
- akshareAKShare financial data aggregator (18k+ stars). Free, no API key. Covers A-shares, US, HK, futures, macro, forex. Primary fallback for tushare and yfinance.
- asset-allocationAsset allocation theory and optimizer usage — MPT / Black-Litterman / risk budgeting / all-weather strategy, including guides for 4 optimizers and rebalancing rules.
- backtest-diagnoseDiagnose failed or underperforming backtests, locate the root cause, and fix the issue
- behavioral-financeBehavioral finance applications: theories of overreaction and underreaction, behavioral explanations for momentum and reversal, investor sentiment cycles, cognitive-bias checklists, and debiasing quantitative strategies.
- candlestickCandlestick pattern recognition engine, pure pandas vectorized implementation of 15 classic candlestick patterns (5 single-candle + 5 double-candle + 4 triple-candle + 1 trend confirmation), generating a composite signal from bullish/bearish pattern scores.
- ccxtCCXT unified crypto exchange library (100+ exchanges). Free public market data. Fallback when OKX is unavailable.
- chanlun基于缠论(缠中说禅)的形态识别引擎,使用czsc库自动检测K线分型、笔、中枢,并生成一买/一卖/二买/二卖/三买/三卖等买卖点信号。支持多周期分析和形态分类(3/5/7/9/11笔形态)。
- commodity-analysisCommodity analysis (oil supply-demand balance / gold pricing / copper as an economic predictor / inventory cycles / futures premium-discount structure / seasonality), generating directional commodity signals.
- convertible-bondA股可转债分析——转股/纯债/期权三维估值、下修/强赎/回售博弈、双低策略与转债轮动选债框架