Perfected FlowScript
BTC Risk Reversal Skew
BTC Risk Reversal Skew — 1W / 1M IV(25Δ) Monitor is indexed as 037_btc_risk_reversal_skew.flowscript. The exact FlowScript is viewable here; chart observe and trading automation use the current mmflow chart/recipe signal proxy until FlowScript v2 transpilation is available.
This exact FlowScript uses the v2 source dialect. It is viewable and connected to the chart/automation proxy, but direct editor execution needs the FlowScript v2 transpiler.
Dialect
flowscript-v2
Compatibility
flowscript-v2-needs-transpile
Position
offchart
Axis
true
Size
13.6 KB
Lines
285
Native Signal Candidates
5 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.
Extreme Put Skew
line 222:5
Trigger
(showShapes && anyExtremePut && putSkewBars == 1)
Value
smooth1w > smooth1m ? smooth1w : smooth1m
Deps
anyExtremePut:var, putSkewBars:static, showShapes:input
Extreme Call Skew
line 232:5
Trigger
(showShapes && anyExtremeCall && callSkewBars == 1)
Value
smooth1w < smooth1m ? smooth1w : smooth1m
Deps
anyExtremeCall:var, callSkewBars:static, showShapes:input
High Put Skew
line 244:5
Trigger
(showShapes && anyHighPut && putSkewBars == 1 && !anyExtremePut)
Value
smooth1w > smooth1m ? smooth1w : smooth1m
Deps
anyExtremePut:var, anyHighPut:var, putSkewBars:static, showShapes:input
High Call Skew
line 254:5
Trigger
(showShapes && anyHighCall && callSkewBars == 1 && !anyExtremeCall)
Value
smooth1w < smooth1m ? smooth1w : smooth1m
Deps
anyExtremeCall:var, anyHighCall:var, callSkewBars:static, showShapes:input
Unlabeled shape
line 275:5
Trigger
(showRegimeLabel && isLastBar)
Value
px
Deps
isLastBar:builtin, showRegimeLabel:input
037_btc_risk_reversal_skew.flowscript
source path: kscripts/perfected/037_btc_risk_reversal_skew.flowscript · sha256:3baedd7c11a457609fb6207c1152b3f5c09cf69c6f43ba930037118aa1f74d48
//@version=2
// ============================================================================
// BTC Risk Reversal Skew — 1W / 1M IV(25Δ) Skew Monitor with Regime Tracking
// Author: abetrade (@abetrade) — Perfected Edition
// Tags: ADVANCED, CORE, #options, #skew, #riskreversal, #iv, #btc
//
// Production-grade risk reversal skew monitor for 1-week and 1-month BTC
// options. Computes IV(25Δ Call) − IV(25Δ Put), applies rolling z-score
// normalisation, and surfaces regime states via color-coded lines, filled
// areas, threshold alerts, and extreme shape markers.
//
// Academic foundations:
// - Carr & Wu (2007), "Stochastic Skew in Currency Options" (J. Financial
// Economics / Review of Financial Studies). RR = IV(25Δ Call) − IV(25Δ Put);
// stochastic skew models capture time-varying behavior that challenges
// traditional models. Risk reversals switch signs and vary greatly.
// URL: https://engineering.nyu.edu/sites/default/files/2019-03/Carr-stochastic-skew-in-currency-options.pdf
//
// - Malz (1995), "Using Option Prices to Estimate Realignment Probabilities"
// (Federal Reserve Bank of NY, Staff Report No. 5). RR contains information
// about tail risk and crash probabilities. Demonstrates extraction of market-
// implied probability distributions from risk reversal and straddle prices.
// URL: https://www.newyorkfed.org/medialibrary/media/research/staff_reports/sr5.pdf
//
// - Hull & Sinclair (2022), "The Risk-Reversal Premium" (J. Investment
// Strategies, 11(1), 59–75). Documents persistent RR premium in FX markets;
// vol-of-vol is the key contributor. Extracting the skew premium brings
// diversification benefits.
// URL: https://www.risk.net/media/download/1091872/download
//
// - Black & Scholes (1973), "The Pricing of Options and Corporate Liabilities"
// (J. Political Economy, 81(3), 637–654). Foundational option pricing;
// IV is derived from option prices via BS inversion.
// DOI: https://www.jstor.org/stable/1831029
//
// - Zhang & Xiang (2008), "The Implied Volatility Smirk" (Quantitative
// Finance). Second-order polynomial expansion of IV smirk; level, slope,
// and curvature linked to risk-neutral standard deviation, skewness, and
// excess kurtosis. Supports skew quantification methodology.
// URL: https://hub.hku.hk/bitstream/10722/85541/1/Content.pdf
//
// - Bollen & Whaley (2004), "Net Buying Pressure and the Shape of the
// Volatility Smile" (J. Finance). Demand pressure (not just risk-neutral
// distribution) drives the volatility skew; hedging demand for OTM puts
// creates persistent skew.
// ============================================================================
define(title="BTC Risk Reversal Skew — 1W / 1M IV(25Δ) Monitor", position="offchart", axis=true)
// ---------------------------------------------------------------------------
// 1. USER INPUTS — All grouped, all numeric inputs carry constraints
// ---------------------------------------------------------------------------
// -- Data Sources --
var rr1wSource = input(name="rr1wSource", type="string", defaultValue="options_rr_1w", label="1W RR Source Key", group="Data Sources")
var rr1mSource = input(name="rr1mSource", type="string", defaultValue="options_rr_1m", label="1M RR Source Key", group="Data Sources")
// -- Computation --
var smoothLen = input(name="smoothLen", type="number", defaultValue=3, label="EMA Smooth Length", constraints={min: 1, max: 20, step: 1}, group="Computation")
var zWindow = input(name="zWindow", type="number", defaultValue=50, label="Z-Score Window (bars)", constraints={min: 20, max: 200, step: 5}, group="Computation")
var putSkewThresh = input(name="putSkewThresh", type="number", defaultValue=2.0, label="High Put Skew Threshold (z >)", constraints={min: 0.5, max: 5.0, step: 0.5}, group="Computation")
var callSkewThresh = input(name="callSkewThresh", type="number", defaultValue=-2.0, label="High Call Skew Threshold (z <)", constraints={min: -5.0, max: -0.5, step: 0.5}, group="Computation")
var extremeThresh = input(name="extremeThresh", type="number", defaultValue=3.0, label="Extreme Skew Threshold", constraints={min: 2.0, max: 6.0, step: 0.5}, group="Computation")
// -- Display --
var show1w = input(name="show1w", type="boolean", defaultValue=true, label="Show 1-Week RR Skew", group="Display")
var show1m = input(name="show1m", type="boolean", defaultValue=true, label="Show 1-Month RR Skew", group="Display")
var showZScores = input(name="showZScores", type="boolean", defaultValue=true, label="Show Z-Scores", group="Display")
var showShapes = input(name="showShapes", type="boolean", defaultValue=true, label="Show Extreme Shapes", group="Display")
var showRegimeLabel = input(name="showRegimeLabel", type="boolean", defaultValue=true, label="Show Regime Label", group="Display")
var showSpread = input(name="showSpread", type="boolean", defaultValue=true, label="Show 1W vs 1M Spread", group="Display")
// -- Colors --
var skewColor1w = input(name="skewColor1w", type="color", defaultValue="#2962ff", label="1W Skew Color", group="Colors")
var skewColor1m = input(name="skewColor1m", type="color", defaultValue="#ff6d00", label="1M Skew Color", group="Colors")
var putSkewColor = input(name="putSkewColor", type="color", defaultValue="#ef5350", label="High Put Skew Color", group="Colors")
var callSkewColor = input(name="callSkewColor", type="color", defaultValue="#26a69a", label="High Call Skew Color", group="Colors")
var extremeColor = input(name="extremeColor", type="color", defaultValue="#ffd700", label="Extreme Alert Color", group="Colors")
var neutralColor = input(name="neutralColor", type="color", defaultValue="#78909c", label="Neutral Color", group="Colors")
// ---------------------------------------------------------------------------
// 2. DATA SOURCES — with isnan() guard on first external access
// ---------------------------------------------------------------------------
timeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries px = bars.close
timeseries options1w = source(rr1wSource, currentSymbol, currentExchange)
timeseries options1m = source(rr1mSource, currentSymbol, currentExchange)
// Guard: halt until options feeds have loaded
if (isnan(px[0]) || !isnum(options1w.value) || !isnum(options1m.value)) {
return
}
// ---------------------------------------------------------------------------
// 3. COMPUTATION
// ---------------------------------------------------------------------------
// -- 3.1 Risk Reversal = IV(25Δ Call) − IV(25Δ Put) --
// Carr & Wu (2007): RR varies over time and switches signs; stochastic skew
// models required. Positive RR = call IV > put IV (upside demand).
// Negative RR = put IV > call IV (downside hedging demand).
//
// We approximate from the platform's options source if available.
timeseries rr1w = isnum(options1w.value) ? options1w.value : 0
timeseries rr1m = isnum(options1m.value) ? options1m.value : 0
// -- 3.2 EMA smoothing for cleaner signal --
timeseries smooth1w = ema(rr1w, smoothLen)
timeseries smooth1m = ema(rr1m, smoothLen)
// -- 3.3 Z-score normalisation (all denominators guarded against zero) --
// Z_t = (RR_t − μ_t) / σ_t over rolling window.
// Makes skew comparable across time and enables threshold-based alerting.
timeseries rr1wMean = sma(smooth1w, zWindow)
timeseries rr1wStd = stdev(smooth1w, zWindow)
timeseries z1w = (rr1wStd > 0) ? (smooth1w - rr1wMean) / rr1wStd : 0
timeseries rr1mMean = sma(smooth1m, zWindow)
timeseries rr1mStd = stdev(smooth1m, zWindow)
timeseries z1m = (rr1mStd > 0) ? (smooth1m - rr1mMean) / rr1mStd : 0
// -- 3.4 Spread between tenors (1W minus 1M) — steepening / flattening --
timeseries tenorSpread = smooth1w - smooth1m
// -- 3.5 Regime detection (configurable thresholds, no magic numbers) --
// High put skew: z-score > putSkewThresh (fear / downside hedging demand).
// High call skew: z-score < callSkewThresh (euphoria / upside demand).
// Extreme: z-score beyond ±extremeThresh (statistical anomaly).
var highPutSkew1w = z1w > putSkewThresh
var highCallSkew1w = z1w < callSkewThresh
var extremePut1w = z1w > extremeThresh
var extremeCall1w = z1w < -extremeThresh
var highPutSkew1m = z1m > putSkewThresh
var highCallSkew1m = z1m < callSkewThresh
var extremePut1m = z1m > extremeThresh
var extremeCall1m = z1m < -extremeThresh
var anyHighPut = highPutSkew1w || highPutSkew1m
var anyHighCall = highCallSkew1w || highCallSkew1m
var anyExtremePut = extremePut1w || extremePut1m
var anyExtremeCall = extremeCall1w || extremeCall1m
// -- 3.6 Skew regime classification --
// 1 = high put skew (fear), -1 = high call skew (greed), 0 = neutral
var skewRegime = anyHighPut ? 1 : (anyHighCall ? -1 : 0)
// -- 3.7 Session tracking via static variables --
// Tracks consecutive bars in each regime for context-aware alerting.
static putSkewBars = 0
static callSkewBars = 0
static neutralBars = 0
if (!isLiveUpdate) {
if (anyHighPut) {
putSkewBars = putSkewBars + 1
callSkewBars = 0
neutralBars = 0
} else if (anyHighCall) {
callSkewBars = callSkewBars + 1
putSkewBars = 0
neutralBars = 0
} else {
neutralBars = neutralBars + 1
putSkewBars = 0
callSkewBars = 0
}
}
// -- 3.8 Color coding by skew regime --
// Dynamic color index for 1W and 1M lines based on their z-scores.
timeseries colorIdx1w = z1w > putSkewThresh ? 0 : (z1w < callSkewThresh ? 1 : 2)
timeseries colorIdx1m = z1m > putSkewThresh ? 0 : (z1m < callSkewThresh ? 1 : 2)
// -- 3.9 Zero-line helper for fill areas --
timeseries zeroLine = 0
// ---------------------------------------------------------------------------
// 4. VISUALIZATION — Color-coded lines, fill areas, shapes, and labels
// ---------------------------------------------------------------------------
// 4.1 1-Week Risk Reversal Skew (plotLine with regime color coding + fill)
if (show1w) {
plotLine(
value=([smooth1w, zeroLine]),
width=2,
colors=[putSkewColor, callSkewColor, skewColor1w],
colorIndex=colorIdx1w,
label=["1W RR Skew"],
desc=["1-week risk reversal skew: IV(25Δ Call) − IV(25Δ Put). Positive = upside demand."],
fill=true
)
}
// 4.2 1-Month Risk Reversal Skew (plotLine with regime color coding + fill)
if (show1m) {
plotLine(
value=([smooth1m, zeroLine]),
width=2,
colors=[putSkewColor, callSkewColor, skewColor1m],
colorIndex=colorIdx1m,
label=["1M RR Skew"],
desc=["1-month risk reversal skew: IV(25Δ Call) − IV(25Δ Put). Positive = upside demand."],
fill=true
)
}
// 4.3 Z-Score lines (plotLine) — normalized view for statistical comparison
if (showZScores) {
plotLine(value=z1w, width=2, colors=[skewColor1w], label=["1W Z-Score"], desc=["1-week RR skew z-score over rolling window"])
plotLine(value=z1m, width=2, colors=[skewColor1m], label=["1M Z-Score"], desc=["1-month RR skew z-score over rolling window"])
}
// 4.4 Tenor spread (plotLine) — steepening vs flattening of skew curve
if (showSpread) {
plotLine(value=tenorSpread, width=1, colors=[neutralColor], label=["Tenor Spread (1W−1M)"], desc=["Difference between 1-week and 1-month RR skew. Positive = front-end skewed."])
}
// 4.5 Extreme shape markers (plotShape) — only on first extreme bar to avoid clutter
if (showShapes && anyExtremePut && putSkewBars == 1) {
plotShape(
value=smooth1w > smooth1m ? smooth1w : smooth1m,
shape="triangleup",
colorIndex=extremeColor,
width=3,
label=["Extreme Put Skew"],
desc=["Risk reversal skew exceeds +" + extremeThresh + " z: extreme downside hedging demand (fear)."]
)
}
if (showShapes && anyExtremeCall && callSkewBars == 1) {
plotShape(
value=smooth1w < smooth1m ? smooth1w : smooth1m,
shape="triangledown",
colorIndex=extremeColor,
width=3,
label=["Extreme Call Skew"],
desc=["Risk reversal skew below −" + extremeThresh + " z: extreme upside demand (euphoria)."]
)
}
// 4.6 High put / call skew threshold markers (plotShape)
if (showShapes && anyHighPut && putSkewBars == 1 && !anyExtremePut) {
plotShape(
value=smooth1w > smooth1m ? smooth1w : smooth1m,
shape="triangleup",
colorIndex=putSkewColor,
width=2,
label=["High Put Skew"],
desc=["Put skew elevated: z > " + putSkewThresh + ". Downside hedging demand elevated."]
)
}
if (showShapes && anyHighCall && callSkewBars == 1 && !anyExtremeCall) {
plotShape(
value=smooth1w < smooth1m ? smooth1w : smooth1m,
shape="triangledown",
colorIndex=callSkewColor,
width=2,
label=["High Call Skew"],
desc=["Call skew elevated: z < " + callSkewThresh + ". Upside demand elevated."]
)
}
// 4.7 Reference thresholds (hline)
hline(value=0, color="#ffffff30", width=1)
hline(value=putSkewThresh, color="#ef535040", width=1)
hline(value=callSkewThresh, color="#26a69a40", width=1)
hline(value=extremeThresh, color="#ffd70030", width=1)
hline(value=-extremeThresh, color="#ffd70030", width=1)
// 4.8 Regime label (plotPriceLabel) — shows on last bar
if (showRegimeLabel && isLastBar) {
var regimeText = anyExtremePut ? "EXTREME PUT SKEW" : (anyExtremeCall ? "EXTREME CALL SKEW" : (anyHighPut ? "HIGH PUT SKEW" : (anyHighCall ? "HIGH CALL SKEW" : "NEUTRAL SKEW")))
var regimeColor = anyExtremePut ? extremeColor : (anyExtremeCall ? extremeColor : (anyHighPut ? putSkewColor : (anyHighCall ? callSkewColor : neutralColor)))
plotPriceLabel(
price=px,
text=regimeText,
type="callout",
color="#ffffff",
backgroundColor=regimeColor,
size=10,
fontWeight=700
)
}