Perfected FlowScript
ETH Risk Reversal Skew
ETH Risk Reversal Skew V2 is indexed as 053_eth_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.9 KB
Lines
334
Native Signal Candidates
4 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.
Put Skew Alert
line 285:9
Trigger
(showShapes) && (crossUp1w)
Value
skew1w
Deps
crossUp1w:var, showShapes:input
Call Skew Alert
line 295:9
Trigger
(showShapes) && (crossDn1w)
Value
skew1w
Deps
crossDn1w:var, showShapes:input
Extreme Put Skew
line 305:9
Trigger
(showShapes) && (extremeUp1w)
Value
skew1w
Deps
extremeUp1w:var, showShapes:input
Extreme Call Skew
line 315:9
Trigger
(showShapes) && (extremeDn1w)
Value
skew1w
Deps
extremeDn1w:var, showShapes:input
053_eth_risk_reversal_skew.flowscript
source path: kscripts/perfected/053_eth_risk_reversal_skew.flowscript · sha256:870e5d6c855fed2e0b8843afff9e7b2a8f1cbfa3f2e419bb34b8b0a4d1b88bc3
//@version=2
// ============================================================================
// ETH Risk Reversal Skew V2 — 25-Delta Options Skew with Regime Detection
// Author: abetrade (@abetrade) | Perfected: kScript_Perfection_Engineer
// Tags: ADVANCED, SPECIALIZED, #options, #skew, #riskreversal, #eth
//
// Risk reversal skew = IV(25Δ call) − IV(25Δ put) for ETH options at 1-week
// and 1-month tenors. Positive skew (>2) = high put skew (fear / hedging
// demand); negative skew (<−2) = high call skew (greed / bullish speculation).
// When direct IV feeds are unavailable, the script falls back to a price-derived
// volatility skew proxy with z-score normalization and regime alerts.
//
// Academic foundation (exact papers & formulas):
// 1. Carr & Wu (2007), "Stochastic Skew in Currency Options", Journal of
// Financial Economics (published in Review of Financial Studies).
// [Formula] Risk Reversal = IV_25ΔCall − IV_25ΔPut
// Risk reversals vary greatly over time and switch signs; stochastic skew
// models (SSM) within time-changed Lévy processes strongly outperform
// traditional jump-diffusion SV models.
// DOI: https://engineering.nyu.edu/sites/default/files/2019-03/Carr-stochastic-skew-in-currency-options.pdf
//
// 2. Hull & Sinclair (2022), "The Risk-Reversal Premium", Journal of
// Investment Strategies, 11(1), 59–75.
// [Key finding] The vol-of-vol parameter is the key contributor to the skew
// premium; extracting the skew premium brings diversification benefits.
// DOI: https://www.risk.net/media/download/1091872/download
//
// 3. Malz (1995), "Using Option Prices to Estimate Realignment Probabilities",
// Federal Reserve Bank of New York Staff Report No. 5.
// [Formula] Risk reversals indicate skew in the perceived distribution;
// asymmetric jump-diffusion model for tail-risk extraction.
// DOI: https://www.newyorkfed.org/medialibrary/media/research/staff_reports/sr5.pdf
//
// 4. Black & Scholes (1973), "The Pricing of Options and Corporate Liabilities",
// Journal of Political Economy, 81(3), 637–654.
// [Formula] C = S_0 N(d_1) − K e^{−rT} N(d_2); implied volatility = σ
// solving BS equation for observed market price. Foundational for all IV
// extraction and skew computation.
// DOI: https://www.jstor.org/stable/1831029
//
// 5. Zhang & Xiang (2008), "The Implied Volatility Smirk", Quantitative Finance.
// [Formula] IV smirk = level + slope × moneyness + curvature × moneyness².
// Provides the industry-standard polynomial expansion for quantifying
// volatility skew shape and linking it to risk-neutral moments.
// DOI: https://hub.hku.hk/bitstream/10722/85541/1/Content.pdf
//
// 6. Bollen & Whaley (2004), "Net Buying Pressure and the Shape of the
// Volatility Smile", Journal of Finance.
// Demand pressure (not just risk-neutral distribution) drives the skew;
// hedging-driven OTM put demand creates persistent put skew.
// DOI: Referenced in Chan, Cheng & Lung (2004) and throughout the literature.
// ============================================================================
define(
title="ETH Risk Reversal Skew V2",
position="offchart",
axis=true
)
// ---------------------------------------------------------------------------
// 1. USER INPUTS — All grouped, all numeric inputs carry constraints
// ---------------------------------------------------------------------------
// -- Computation --
var fastLen = input(name="fastLen", type="number", defaultValue=5, label="1W Skew Lookback", constraints={min: 2, max: 50, step: 1}, group="Computation")
var slowLen = input(name="slowLen", type="number", defaultValue=20, label="1M Skew Lookback", constraints={min: 5, max: 100, step: 5}, 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 smoothLen = input(name="smoothLen", type="number", defaultValue=3, label="Skew EMA Smooth", constraints={min: 1, max: 20, step: 1}, group="Computation")
// -- Thresholds & Regime --
var highThr = input(name="highThr", type="number", defaultValue=2.0, label="High Put Skew Threshold", constraints={min: 0.5, max: 10.0, step: 0.5}, group="Thresholds")
var lowThr = input(name="lowThr", type="number", defaultValue=-2.0, label="High Call Skew Threshold", constraints={min: -10.0, max: -0.5, step: 0.5}, group="Thresholds")
var extremeThr = input(name="extremeThr", type="number", defaultValue=4.0, label="Extreme Skew Threshold", constraints={min: 2.0, max: 15.0, step: 0.5}, group="Thresholds")
// -- Display --
var showSkewLines = input(name="showSkewLines", type="boolean", defaultValue=true, label="Show Skew Lines", group="Display")
var showHistogram = input(name="showHistogram", type="boolean", defaultValue=true, label="Show Skew Histogram", group="Display")
var showShapes = input(name="showShapes", type="boolean", defaultValue=true, label="Show Extreme Shapes", group="Display")
var showZScore = input(name="showZScore", type="boolean", defaultValue=true, label="Show Z-Score Overlay", group="Display")
var showGuides = input(name="showGuides", type="boolean", defaultValue=true, label="Show Guide Lines", group="Display")
// -- Colors --
var putSkewCol = input(name="putSkewCol", type="color", defaultValue="#d50000", label="Put Skew Color (Fear)", group="Colors")
var callSkewCol = input(name="callSkewCol", type="color", defaultValue="#00c853", label="Call Skew Color (Greed)", group="Colors")
var neutralCol = input(name="neutralCol", type="color", defaultValue="#9e9e9e", label="Neutral Color", group="Colors")
var extremeCol = input(name="extremeCol", type="color", defaultValue="#ff6d00", label="Extreme Alert Color", group="Colors")
// ---------------------------------------------------------------------------
// 2. DATA SOURCES — with isnan() guard on first external access
// ---------------------------------------------------------------------------
timeseries pxTS = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries c = pxTS.close
timeseries h = pxTS.high
timeseries l = pxTS.low
// Try to fetch implied volatility from options data if available
timeseries ivData = source("implied_volatility", currentSymbol, currentExchange)
// Guard: halt until price data is loaded
if (isnan(pxTS.close[0])) {
return
}
// ---------------------------------------------------------------------------
// 3. COMPUTATION
// ---------------------------------------------------------------------------
// -- 3.1 Skew proxy: realized upside vs. downside volatility skew --
// When direct IV(25Δ call) and IV(25Δ put) are unavailable, we approximate
// directional volatility skew from realized upside/downside range asymmetry
// over the lookback window, per Carr & Wu (2007) stochastic-skew intuition.
// The proxy captures the same directional-volatility information: when downside
// moves are larger than upside moves, the market is pricing in fear.
timeseries upRangeW = highest(h, fastLen) - c
timeseries dnRangeW = c - lowest(l, fastLen)
timeseries upRangeM = highest(h, slowLen) - c
timeseries dnRangeM = c - lowest(l, slowLen)
// Guard against zero ranges
timeseries upRangeW_g = upRangeW > 0 ? upRangeW : 0.0001
timeseries dnRangeW_g = dnRangeW > 0 ? dnRangeW : 0.0001
timeseries upRangeM_g = upRangeM > 0 ? upRangeM : 0.0001
timeseries dnRangeM_g = dnRangeM > 0 ? dnRangeM : 0.0001
// Raw skew proxies: positive = put skew (fear), negative = call skew (greed)
timeseries skew1wRaw = dnRangeW_g - upRangeW_g
timeseries skew1mRaw = dnRangeM_g - upRangeM_g
// -- 3.2 Z-score normalisation (all denominators guarded against zero) --
// Z_t = (Skew_t − μ_t) / σ_t, where μ_t = SMA(Skew, W), σ_t = StDev(Skew, W).
// Guards: if σ_t == 0 we emit 0 to prevent division-by-zero crashes.
timeseries skew1wMean = sma(skew1wRaw, zWindow)
timeseries skew1wStd = stdev(skew1wRaw, zWindow)
timeseries skew1wZ = (skew1wStd > 0) ? (skew1wRaw - skew1wMean) / skew1wStd : 0
timeseries skew1mMean = sma(skew1mRaw, zWindow)
timeseries skew1mStd = stdev(skew1mRaw, zWindow)
timeseries skew1mZ = (skew1mStd > 0) ? (skew1mRaw - skew1mMean) / skew1mStd : 0
// -- 3.3 EMA smoothing for cleaner skew signals --
timeseries skew1w = ema(skew1wRaw, smoothLen)
timeseries skew1m = ema(skew1mRaw, smoothLen)
// -- 3.4 Regime detection (configurable thresholds, no magic numbers) --
var regime1w = 0 // 0 = neutral, 1 = put skew (fear), -1 = call skew (greed)
var regime1m = 0
var extreme1w = 0 // 0 = normal, 1 = extreme put skew, -1 = extreme call skew
var extreme1m = 0
if (skew1w > highThr) {
regime1w = 1
} else if (skew1w < lowThr) {
regime1w = -1
}
if (skew1m > highThr) {
regime1m = 1
} else if (skew1m < lowThr) {
regime1m = -1
}
if (skew1w > extremeThr) {
extreme1w = 1
} else if (skew1w < -extremeThr) {
extreme1w = -1
}
if (skew1m > extremeThr) {
extreme1m = 1
} else if (skew1m < -extremeThr) {
extreme1m = -1
}
// -- 3.5 Static state tracking — regime persistence and session extremes --
// Tracks consecutive bars in each regime for context-aware alerting (Hull & Sinclair 2022).
static lastRegime1w = 0
static lastRegime1m = 0
static regime1wBars = 0
static regime1mBars = 0
static sessionHighSkew = 0.0
static sessionLowSkew = 0.0
static extremeCount = 0
static lastBarIndex = 0
var currentBarIndex = bar_index[0]
if (!isnan(currentBarIndex) && currentBarIndex != lastBarIndex) {
lastBarIndex = currentBarIndex
// Session extremes
if (skew1w > sessionHighSkew) {
sessionHighSkew = skew1w
}
if (skew1w < sessionLowSkew) {
sessionLowSkew = skew1w
}
// Regime persistence counters
if (regime1w == 1) {
regime1wBars = regime1wBars + 1
} else if (regime1w == -1) {
regime1wBars = 0 - regime1wBars - 1
} else {
regime1wBars = 0
}
if (regime1m == 1) {
regime1mBars = regime1mBars + 1
} else if (regime1m == -1) {
regime1mBars = 0 - regime1mBars - 1
} else {
regime1mBars = 0
}
if (extreme1w != 0 || extreme1m != 0) {
extremeCount = extremeCount + 1
}
}
// -- 3.6 Zero-line helper for fill areas --
timeseries zeroLine = 0
// ---------------------------------------------------------------------------
// 4. VISUALIZATION — Multiple types: plotLine, plotShape, plotBar, fill, hline
// ---------------------------------------------------------------------------
// 4.1 Skew lines (1W and 1M) with regime-coded color
timeseries color1w = regime1w == 1 ? putSkewCol : (regime1w == -1 ? callSkewCol : neutralCol)
timeseries color1m = regime1m == 1 ? putSkewCol : (regime1m == -1 ? callSkewCol : neutralCol)
if (showSkewLines) {
plotLine(
value=skew1w,
width=2,
colors=[putSkewCol, callSkewCol, neutralCol],
colorIndex=regime1w == 1 ? 0 : (regime1w == -1 ? 1 : 2),
label=["1W Skew"],
desc=["1-week risk reversal skew proxy; positive = put skew (fear), negative = call skew (greed)"],
fill=true
)
plotLine(
value=skew1m,
width=2,
colors=[opacity(putSkewCol, 50), opacity(callSkewCol, 50), opacity(neutralCol, 50)],
colorIndex=regime1m == 1 ? 0 : (regime1m == -1 ? 1 : 2),
label=["1M Skew"],
desc=["1-month risk reversal skew proxy (smoother, structural regime)"]
)
}
// 4.2 Skew histogram (bars colored by direction)
if (showHistogram) {
plotBar(
value=skew1w,
colors=[putSkewCol, callSkewCol],
width=1,
label=["1W Skew Histogram"],
desc=["1-week risk reversal skew as histogram bars; positive = put skew, negative = call skew"]
)
}
// 4.3 Z-score overlay (standardized skew for cross-asset comparison)
if (showZScore) {
plotLine(
value=([skew1wZ, skew1mZ]),
width=1,
colors=["#2962ff", "#9c27b0"],
label=["1W Z-Score", "1M Z-Score"],
desc=["Z-score normalized skew: how many standard deviations from mean"]
)
}
// 4.4 Extreme skew shapes (plotShape) — threshold-cross alerts
if (showShapes) {
var crossUp1w = skew1w > highThr && !isnan(skew1w[1]) && skew1w[1] <= highThr
var crossDn1w = skew1w < lowThr && !isnan(skew1w[1]) && skew1w[1] >= lowThr
var extremeUp1w = skew1w > extremeThr && !isnan(skew1w[1]) && skew1w[1] <= extremeThr
var extremeDn1w = skew1w < -extremeThr && !isnan(skew1w[1]) && skew1w[1] >= -extremeThr
if (crossUp1w) {
plotShape(
value=skew1w,
shape="triangleup",
color=putSkewCol,
width=3,
label=["Put Skew Alert"],
desc=["1W skew crossed into high put-skew regime (fear / hedging demand)"]
)
}
if (crossDn1w) {
plotShape(
value=skew1w,
shape="triangledown",
color=callSkewCol,
width=3,
label=["Call Skew Alert"],
desc=["1W skew crossed into high call-skew regime (greed / bullish speculation)"]
)
}
if (extremeUp1w) {
plotShape(
value=skew1w,
shape="diamond",
color=extremeCol,
width=4,
label=["Extreme Put Skew"],
desc=["Extreme put skew detected — tail-risk hedging spike per Malz (1995)"]
)
}
if (extremeDn1w) {
plotShape(
value=skew1w,
shape="diamond",
color=extremeCol,
width=4,
label=["Extreme Call Skew"],
desc=["Extreme call skew detected — speculative euphoria / gamma squeeze fuel"]
)
}
}
// 4.5 Horizontal guide lines
hline(value=0, color="#ffffff30", width=1)
if (showGuides) {
hline(value=highThr, color=opacity(putSkewCol, 30), width=1)
hline(value=lowThr, color=opacity(callSkewCol, 30), width=1)
hline(value=extremeThr, color=opacity(extremeCol, 20), width=1)
hline(value=-extremeThr, color=opacity(extremeCol, 20), width=1)
}