Lesson 1
Moving Averages and ARIMA Forecasting
Moving averages smooth time series to reveal trends and serve as simple forecasts. ARIMA(p,d,q) models combine autoregression, differencing and moving-average error terms to forecast stationary or differenced financial series.
Moving Averages
- Simple moving average (SMA): SMA_t = (y_t + y_(t-1) + ... + y_(t-n+1)) / n.
- Larger window n gives a smoother series but more lag.
- Exponential moving average (EMA): EMA_t = a*y_t + (1-a)*EMA_(t-1), with 0 < a < 1; recent data weighted more.
- Trading use: crossovers of short and long MAs signal trend changes (e.g. 50-day crossing 200-day).
Stationarity
- ARMA models require stationarity: constant mean, variance and autocovariance over time.
- Prices are usually non-stationary; returns or first differences are usually closer to stationary.
- Differencing: y'_t = y_t - y_(t-1). The number of differences needed is d.
- The ADF test checks for a unit root (null hypothesis: non-stationary).
ARIMA(p,d,q)
- AR(p): y_t = c + phi_1*y_(t-1) + ... + phi_p*y_(t-p) + e_t.
- MA(q): y_t = mu + e_t + theta_1*e_(t-1) + ... + theta_q*e_(t-q) (uses past forecast errors, not a rolling average).
- I(d): series is differenced d times before fitting ARMA.
- ACF cuts off after lag q suggests MA(q); PACF cuts off after lag p suggests AR(p).
Model Building (Box-Jenkins)
- Identify: plot, test stationarity, difference, inspect ACF/PACF.
- Estimate parameters (maximum likelihood); compare models with AIC/BIC (lower is better).
- Diagnose: residuals should be white noise (Ljung-Box test).
- Forecast and evaluate out-of-sample with RMSE or MAE.
Key terms
- Simple moving average
- Equal-weighted mean of the last n observations.
- Exponential moving average
- Weighted average with exponentially decaying weights on older data.
- Stationarity
- Statistical properties of a series do not change over time.
- Differencing
- Subtracting the previous value to remove trend or unit root.
- ARIMA(p,d,q)
- Model with p AR lags, d differences and q MA error lags.
- ACF/PACF
- Autocorrelation and partial autocorrelation functions used to choose q and p.
- AIC
- Information criterion balancing fit against model complexity; lower is better.
Lesson 2
Portfolio Optimisation
Portfolio optimisation chooses asset weights to get the best trade-off between expected return and risk. Markowitz mean-variance theory shows diversification reduces risk when assets are imperfectly correlated, giving the efficient frontier and the maximum Sharpe ratio portfolio.
Portfolio Return and Risk
- Expected return: E(Rp) = sum of w_i * E(R_i).
- Two-asset variance: var_p = w1^2*s1^2 + w2^2*s2^2 + 2*w1*w2*rho*s1*s2.
- General form: var_p = w' * Cov * w.
- Weights sum to 1; a no-short-selling constraint requires w_i >= 0.
Diversification
- If correlation rho < 1, portfolio volatility is below the weighted average of asset volatilities.
- Lower correlation gives greater risk reduction; rho = -1 allows a zero-risk combination.
- Diversification removes unsystematic (specific) risk but not systematic (market) risk.
Efficient Frontier
- The set of portfolios with the highest return for each level of risk.
- Minimum variance portfolio: the leftmost point of the frontier.
- Portfolios below the frontier are inefficient.
Sharpe Ratio and Optimisation
- Sharpe ratio = (E(Rp) - Rf) / s_p.
- The tangency portfolio maximises the Sharpe ratio; the capital market line joins Rf to it.
- Solved numerically (e.g. scipy.optimize or Solver) with weights and constraints.
- Inputs are estimated from history; estimation error can cause extreme weights.
Key terms
- Mean-variance optimisation
- Markowitz method choosing weights to balance expected return and variance.
- Covariance matrix
- Matrix of asset variances and covariances used to compute portfolio risk.
- Efficient frontier
- Portfolios offering maximum expected return for each risk level.
- Minimum variance portfolio
- Portfolio with the lowest possible volatility.
- Sharpe ratio
- Excess return per unit of total risk.
- Tangency portfolio
- Risky portfolio with the highest Sharpe ratio.
Lesson 3
Value at Risk (VaR)
Value at Risk (VaR) estimates the maximum loss over a given horizon at a given confidence level under normal market conditions. It can be calculated by parametric, historical simulation or Monte Carlo methods, and is often supplemented by Expected Shortfall.
Definition
- VaR at confidence c over horizon T: the loss exceeded with probability only (1-c).
- Example: 1-day 95% VaR of $1m means a 5% chance of losing more than $1m in a day.
- Three inputs: confidence level, time horizon, portfolio value/returns.
Parametric (Variance-Covariance) VaR
- Assumes normally distributed returns.
- VaR = V * (z * s - mu); often mu is taken as 0, so VaR = z * s * V.
- z = 1.645 for 95%, 2.326 for 99%.
- Square-root-of-time scaling: VaR_T = VaR_1day * sqrt(T).
Historical and Monte Carlo VaR
- Historical: sort past returns and take the (1-c) percentile; no distribution assumption.
- Monte Carlo: simulate many return scenarios from a model and read off the percentile.
- Monte Carlo handles non-linear instruments like options but is computationally heavy.
Limitations and Expected Shortfall
- VaR says nothing about the size of losses beyond the threshold.
- Normality underestimates fat tails; history may miss new regimes.
- VaR is not subadditive, so it may penalise diversification.
- Expected Shortfall (CVaR) = average loss given the loss exceeds VaR.
- Backtesting counts exceptions: at 99% VaR, expect about 2-3 per 250 days.
Key terms
- Value at Risk
- Loss threshold not exceeded with a given confidence over a given horizon.
- Confidence level
- Probability that losses will not exceed VaR, e.g. 95% or 99%.
- Parametric VaR
- VaR calculated from mean and volatility assuming normal returns.
- Historical simulation
- VaR taken as a percentile of actual past returns.
- Monte Carlo VaR
- VaR from the distribution of simulated portfolio outcomes.
- Expected Shortfall
- Average loss in the tail beyond VaR.
Lesson 4
Machine Learning for Fraud Detection
Machine learning detects fraud by learning patterns that separate legitimate from fraudulent transactions, using supervised, unsupervised or hybrid methods. Fraud data is highly imbalanced, so resampling, cost-sensitive learning and metrics such as precision, recall and PR-AUC matter more than accuracy.
Approaches
- Supervised learning (logistic regression, random forests, gradient boosting, neural networks) trains on labelled fraud and non-fraud cases.
- Unsupervised anomaly detection (isolation forest, autoencoders, clustering) flags unusual behaviour without labels and can catch new fraud patterns.
- Rule-based systems are often combined with ML scores in a hybrid setup.
Data and features
- Fraud is rare, often below 1% of transactions, so the classes are severely imbalanced.
- Useful features include transaction amount, velocity (number of transactions per time window), location and device mismatch, merchant category, and deviation from the customer's usual behaviour.
- Handle imbalance with oversampling (e.g. SMOTE), undersampling, or class weights.
Evaluation
- Accuracy is misleading: predicting 'never fraud' scores 99%+ accuracy.
- Precision = TP/(TP+FP); recall = TP/(TP+FN).
- Use precision-recall curves and PR-AUC, and set the decision threshold by comparing the cost of missed fraud with the cost of false alarms.
- Fraud patterns change over time (concept drift), so models need monitoring and retraining.
Key terms
- Class imbalance
- A large disparity between the number of fraud and non-fraud examples.
- Anomaly detection
- Identifying observations that deviate strongly from normal patterns.
- Recall
- The share of actual fraud cases that the model catches.
- Precision
- The share of flagged cases that are actually fraud.
- Concept drift
- A change over time in the patterns of the data, which degrades model performance.
- SMOTE
- A technique that creates synthetic minority-class samples by interpolating between existing ones.
