1. Deterministic Pure Functions
Every indicator in our calculation engine lives inside a dedicated pure module. Functions accept an immutable series of input bars and parameter configurations and return calculated values. They contain:
- No database queries or side effects
- No network calls
- No non-deterministic operations (e.g.
Date.now()) - No hidden lookahead parameters
This guarantees that the indicators evaluated in historic backtests are mathematically identical to those computed at market close.
2. Relative Strength Index (RSI 14)
Our 14-period RSI strictly adheres to J. Welles Wilder Jr.'s original smoothing methodology rather than the simplified moving average approximations seen in some charting libraries.
Change = Close[t] - Close[t-1]
Gain = max(Change, 0), Loss = max(-Change, 0)
AvgGain[t] = (AvgGain[t-1] * 13 + Gain[t]) / 14
AvgLoss[t] = (AvgLoss[t-1] * 13 + Loss[t]) / 14
RS = AvgGain / AvgLoss
RSI = 100 - (100 / (1 + RS))
Warm-up Period: Requires at least 15 bars for an initial seed value, and stabilization occurs asymptotically after 100+ sessions.
3. Exponential Moving Averages (EMA)
We track 20, 50, and 200-session EMAs. The weighting multiplier (α) applied to the closing price is:
α = 2 / (Period + 1)
EMA[t] = Close[t] * α + EMA[t-1] * (1 - α)
Seed value is initialized via a Simple Moving Average (SMA) over the initial window of length Period.
4. Moving Average Convergence Divergence (MACD)
Standard 12/26/9 configuration:
MACD Line = EMA(12) - EMA(26)
Signal Line = EMA(9, MACD Line)
Histogram = MACD Line - Signal Line
5. Corporate Action Invariant & Read-Time Adjustments
Raw price history stored in the database is never mutated (an append-only database trigger enforces this rule). When a stock undergoes a corporate action:
- A row is recorded in
corporate_actionswith theexDateand exact numeric ratio (e.g. a 1:5 split carriesratio = 0.2). - Every candle prior to
exDateis multiplied by the cumulative adjustment ratio on read. - Volume scales inversely (divided by ratio) to preserve true liquidity equivalence.
- Adjusted prices are rounded back to the nearest integer paise (never float).