You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This recipe uses standard EMA smoothing via `avg(value, 'period', 14)` where α = 2/(N+1). Wilder's original ATR uses α = 1/N, which is more gradual. For exact Wilder smoothing with a 14-period lookback, use `avg(value, 'period', 27)`. Most modern platforms offer both variants.
2. Computes rolling standard deviation using variance formula
62
-
3. Annualizes by multiplying by `sqrt(trading_periods_per_year)` (252 days × 96 fifteen-minute periods = 24,192)
62
+
3. Annualizes by multiplying by `sqrt(periods_per_year)` (365 days × 96 fifteen-minute periods = 35,040 for the 24/7 simulated data)
63
63
64
64
## Interpreting results
65
65
@@ -69,8 +69,7 @@ The query:
69
69
-**Realized < Implied**: Options may be expensive
70
70
71
71
:::note Annualization factor
72
-
For 15-minute data with 24/7 trading: `sqrt(365 * 96) ≈ 187`
73
-
For daily data with ~252 trading days: `sqrt(252) ≈ 15.87`
72
+
The demo FX data is simulated continuously (24/7, including weekends), so the annualization factor uses `365 * 96` (365 days × 96 fifteen-minute periods per day). For real FX markets (24/5), use `252 * 96`. For daily data, use `sqrt(252) ≈ 15.87`.
Copy file name to clipboardExpand all lines: documentation/cookbook/sql/finance/rsi.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ You want to identify when an asset may be overbought or oversold based on recent
15
15
```questdb-sql demo title="Calculate 14-period RSI with EMA smoothing"
16
16
DECLARE
17
17
@symbol := 'EURUSD',
18
-
@lookback := dateadd('M', -1, now())
18
+
@lookback := '$now - 1M..$now'
19
19
20
20
WITH changes AS (
21
21
SELECT
@@ -25,7 +25,7 @@ WITH changes AS (
25
25
close - lag(close) OVER (PARTITION BY symbol ORDER BY timestamp) AS change
26
26
FROM market_data_ohlc_15m
27
27
WHERE symbol = @symbol
28
-
AND timestamp > @lookback
28
+
AND timestamp IN @lookback
29
29
),
30
30
gains_losses AS (
31
31
SELECT
@@ -68,8 +68,8 @@ The query:
68
68
-**RSI = 50**: Neutral momentum
69
69
-**Divergence**: When price makes new highs but RSI doesn't, it may signal weakening momentum
70
70
71
-
:::note RSI smoothing
72
-
Traditional RSI uses Wilder's smoothing (equivalent to EMA with period 2N-1). The `avg(value, 'period', 14)`function uses standard EMA where α = 2/(14+1). For exact Wilder smoothing, use `avg(value, 'period', 27)` for a 14-period RSI.
71
+
:::note EMA vs Wilder's smoothing
72
+
This recipe uses standard EMA smoothing via `avg(value, 'period', 14)` where α = 2/(N+1). Traditional RSI (Wilder's) uses α = 1/N, which is more gradual. For exact Wilder smoothing with a 14-period lookback, use `avg(value, 'period', 27)`. Most modern platforms offer both variants.
0 commit comments