Indicators & Oscillators
Level 5 — Mastery (cross-domain: math + statistics + coding) Time limit: 90 minutes Total marks: 60
Instructions: Answer all three questions. Show derivations, code logic (pseudocode or Python is accepted), and justify all claims. Use / for mathematics.
Question 1 — EMA smoothing, weights & lag (20 marks)
The Exponential Moving Average is defined recursively as where is the closing price and is the period.
(a) Prove by unrolling the recursion that the EMA is a weighted sum of all past prices, and show the weights form a geometric series that sums to in the infinite limit. State the weight assigned to . (6 marks)
(b) The center of mass (average lag, in bars) of an indicator is where is the weight on . Derive a closed form for the EMA's center of mass in terms of , then in terms of . Compare it against the SMA lag of for . (7 marks)
(c) Write a vectorised or iterative code function ema(prices, N) returning the full EMA series (seed the first value with the price or an SMA — state your choice). Then explain, in terms of your part (b) result, why an EMA reacts to a price shock faster than an SMA of the same . (7 marks)
Question 2 — RSI construction, bounds & divergence (20 marks)
RSI uses Wilder's smoothing over periods: where , are smoothed average gains and losses.
(a) Prove that for all valid , and find the exact RS value that produces . (5 marks)
(b) A stock has these 8 daily closes: . Using simple averaging of the up/down moves across the 7 changes (not Wilder smoothing), compute , , and the resulting . Round RSI to one decimal. (8 marks)
(c) Define bearish RSI divergence precisely in terms of price highs and RSI highs. Then design pseudocode detect_bearish_divergence(price, rsi) that flags divergence over a lookback window, and explain one reason it can produce false signals in a strong trend. (7 marks)
Question 3 — MACD, Bollinger squeeze & indicator overload (20 marks)
(a) MACD line ; signal ; histogram MACD signal. Prove that a bullish MACD/signal crossover occurs exactly when the histogram crosses from negative to positive, and relate the histogram's sign-change to the rate of change of the MACD line. (6 marks)
(b) Bollinger Bands use middle , upper/lower , with typically . The bandwidth is . For a window of prices with , , compute the SMA, the population standard deviation, the bandwidth, and state what a falling bandwidth (a "squeeze") implies. (8 marks)
(c) Two indicators are redundant if they encode strongly correlated information. Explain mathematically why combining RSI, Stochastic %K and Williams %R on the same chart is a form of indicator overload, using the fact that all three are bounded oscillators derived from recent price extremes/changes. Propose a principled 3-indicator dashboard (one from each of: trend, momentum, volatility) and justify the low-redundancy choice. (6 marks)
Answer keyMark scheme & solutions
Question 1
(a) (6 marks) Unroll:
- Correct unrolling to two/three levels (2)
- General form with weight on (2)
- Sum of weights: ✓ (geometric series, ratio ) (2)
(b) (7 marks) Using with . (3) Substitute : (2) For : ; . They are equal in center-of-mass. (2) (Note/insight: EMA has same average lag but a fatter recent-weight tail, so it responds faster to new data — leads into (c).)
(c) (7 marks)
def ema(prices, N):
alpha = 2/(N+1)
e = [prices[0]] # seed with first price
for p in prices[1:]:
e.append(alpha*p + (1-alpha)*e[-1])
return e- Correct recursion & alpha (3); valid seeding stated (1)
- Explanation (3): Although average lag matches SMA, the EMA weight on the most recent price exceeds the SMA's flat weight (since for ). A price shock at therefore moves the EMA more on the same bar, whereas the SMA weights it only and must also wait for the shock to enter/exit the fixed window. Hence faster reaction to shocks.
Question 2
(a) (5 marks) As , , so , giving . Limits: ; . Bounds proven. (3) For : . (2)
(b) (8 marks) Changes: . Gains: → sum ; Losses: → sum . Over 7 periods: , . (3) . (2) . (3)
(c) (7 marks) Bearish divergence: price makes a higher high while RSI makes a lower high over the same interval — momentum weakening despite rising price. (2)
def detect_bearish_divergence(price, rsi, lookback=20):
highs = local_maxima_indices(price, lookback) # swing highs
for a, b in consecutive_pairs(highs):
if price[b] > price[a] and rsi[b] < rsi[a]:
return True, (a, b)
return False, None- Correct definition (2); pseudocode identifying two swing highs & comparing price↑ vs RSI↓ (3)
- False-signal reason (2): in a strong uptrend RSI can stay pinned high (repeated overbought) and print lower peaks purely from smoothing/scaling while price keeps advancing legitimately — divergence fires early and the trend continues.
Question 3
(a) (6 marks) Histogram MACD signal. A bullish MACD/signal crossover is defined as MACD rising through signal, i.e. transition from MACD signal to MACD signal transitions from to . Thus crossover histogram zero-crossing (negative→positive). (3) Since signal lags MACD, MACD (its own smoothed value) the recent rate of change of MACD; and rising indicates MACD accelerating upward. Sign change of marks where MACD's momentum turns positive relative to its average. (3)
(b) (8 marks) Mean . (2) Deviations: ; squares , sum . Population variance ; . (3) Upper ; lower . . (2) Falling bandwidth = squeeze: contracting volatility, bands tighten; often precedes a volatility expansion / breakout. (1)
(c) (6 marks) RSI, Stochastic %K and Williams %R are all bounded momentum oscillators built from recent price range/change; %K and Williams %R are algebraically near-mirror images ( over the same ), and both correlate strongly with RSI. Stacking them adds near-zero independent information but multiplies visual noise and gives a false sense of "confirmation" (correlated signals agreeing is not independent evidence) — classic indicator overload. (3) Low-redundancy dashboard: Trend = ADX (or MA crossover) — measures directional strength; Momentum = RSI or MACD — one oscillator only; Volatility = Bollinger Bandwidth or ATR — measures dispersion. Each captures an orthogonal dimension (direction / speed / spread), minimizing correlation and maximizing information per indicator. (3)
[
{"claim":"EMA center of mass = (N-1)/2 for N=19 equals 9","code":"N=19; alpha=Rational(2,N+1); L=(1-alpha)/alpha; result=(L==9)"},
{"claim":"RS for RSI=70 is 7/3","code":"RS=symbols('RS'); sol=solve(Eq(100-100/(1+RS),70),RS)[0]; result=(sol==Rational(7,3))"},
{"claim":"Q2b RSI equals 80","code":"U=Rational(8,7); D=Rational(2,7); RS=U/D; RSI=100-100/(1+RS); result=(RSI==80)"},
{"claim":"Bollinger population sigma sqrt2 and bandwidth 2*sqrt2/11","code":"vals=[20,22,21,23,24]; m=Rational(sum(vals),5); var=sum((v-m)**2 for v in vals)/5; sd=sqrt(var); bw=(4*sd)/m; result=(simplify(sd-sqrt(2))==0 and simplify(bw-2*sqrt(2)/11)==0)"}
]