Objective
You should be able to write down a feed-forward network, run backpropagation by hand on a small one, explain why initialisation and activation choice matter, and argue clearly about when a neural network is the wrong tool for a return-prediction problem.
Layers and activations
A fully connected network composes affine maps with element-wise non-linearities:
Without the composition is a single linear map, however many layers you stack. With a non-linear , one wide enough hidden layer can approximate any continuous function on a compact set (the universal approximation theorem). That says nothing about how much data you need, which is the real constraint in finance.
| Activation | Notes | ||
|---|---|---|---|
| Sigmoid | Saturates; gradients vanish in deep stacks | ||
| tanh | Zero-centred, still saturates | ||
| ReLU | if , else | Cheap, no saturation for ; units can "die" |
The output layer matches the task: linear for regression, sigmoid for a binary probability, softmax for several classes.
Loss functions
- Mean squared error for regression: the Gaussian log-likelihood. Sensitive to fat-tailed targets; Huber loss caps the gradient on large errors.
- Binary cross-entropy with . Its gradient with respect to the logit is simply .
- Softmax cross-entropy for classes: gradient with respect to each logit.
The clean gradients are why sigmoid and softmax are paired with cross-entropy: MSE on a sigmoid output multiplies the gradient by , which is tiny when the unit saturates, even if the prediction is badly wrong.
Backpropagation
Backpropagation is the chain rule applied from the loss backwards, reusing each intermediate derivative. For one layer, given :
One forward pass stores the and values; one backward pass computes every gradient, at roughly twice the cost of the forward pass. That is why training large networks is feasible at all.
Worked example
one backpropagation step by hand
Input , target . Hidden layer with two ReLU units, weights and biases
linear output with , , and loss . Compute all gradients and the loss after one gradient step with learning rate .
Show solutionHide solution
Forward. , so . Then and .
Backward.
- .
- Output layer: and .
- Into the hidden layer: . The ReLU passes the gradient where and blocks it elsewhere, so .
- Hidden weights: and .
The second hidden unit gets zero gradient: it is inactive for this input. If it is inactive for every input it never recovers, which is the "dead ReLU" problem.
Update with learning rate : 's first row becomes , , , . New forward pass: , , and , down from .
With learning rate instead, and : the step overshoots and the loss rises. The step size has to respect the curvature of the loss.
The same computation in NumPy, which is how you would check a hand derivation in an interview take-home:
import numpy as np
x, y = np.array([2.0, 1.0]), 2.0
W1, b1 = np.array([[0.5, -0.5], [-1.0, 0.5]]), np.zeros(2)
w2, b2 = np.array([2.0, 1.0]), 0.0
def forward(W1, b1, w2, b2):
z = W1 @ x + b1
h = np.maximum(z, 0.0) # ReLU
y_hat = w2 @ h + b2
return z, h, y_hat, 0.5 * (y_hat - y) ** 2
z, h, y_hat, loss = forward(W1, b1, w2, b2)
d = y_hat - y # dL/dy_hat
g_w2, g_b2 = d * h, d
g_z = d * w2 * (z > 0) # back through w2, then the ReLU
g_W1, g_b1 = np.outer(g_z, x), g_z
print("loss", loss, "grad W1", g_W1.tolist(), "grad w2", g_w2.tolist())
lr = 0.05
*_, new_loss = forward(W1 - lr * g_W1, b1 - lr * g_b1, w2 - lr * g_w2, b2 - lr * g_b2)
print("loss after one step", round(new_loss, 4))
Output:
loss 0.5 grad W1 [[-4.0, -2.0], [-0.0, -0.0]] grad w2 [-0.5, -0.0]
loss after one step 0.0385
A finite-difference check, for each parameter, is the standard way to test a hand-written backward pass.
Initialisation
Weights cannot all start equal: identical units receive identical gradients and stay identical forever (the symmetry problem). Random weights must also have the right scale. If with independent zero-mean weights of variance , then . To keep activations from shrinking or exploding layer by layer, must scale like :
- Xavier/Glorot (tanh, sigmoid): .
- He (ReLU): . The factor 2 compensates for ReLU zeroing half its inputs.
For a ReLU layer with 512 inputs, He initialisation uses standard deviation .
Worked example
vanishing gradients through sigmoids
A gradient passes back through 10 sigmoid layers. Ignoring the weights (take them to have unit scale), what is the largest factor by which the gradient can be multiplied?
Show solutionHide solution
Each layer multiplies the gradient by , which is maximised at with value . Through 10 layers the factor is at most
Early layers barely learn. The remedies are the modern defaults: ReLU-type activations (derivative 1 on the active side), He initialisation, normalisation layers, and residual connections, which give the gradient an identity path around each block.
Regularisation
Networks have far more parameters than a typical financial dataset can support, so regularisation is not optional.
- Weight decay (L2). Add to the loss. The gradient step becomes : every step shrinks the weights geometrically, exactly the ridge idea from the bias–variance lesson. (With adaptive optimisers such as Adam, adding L2 to the loss is not equivalent to shrinking the weights directly; AdamW applies the decay separately.)
- Dropout. During training, zero each hidden unit independently with probability and scale survivors by so expected activations are unchanged ("inverted dropout"); at test time use the full network. It prevents units from co-adapting and behaves like averaging an ensemble of thinned networks.
- Early stopping. Monitor validation loss and keep the weights from its minimum. For a quadratic loss and gradient descent from small initial weights, stopping early acts much like an L2 penalty, with the number of steps playing the role of .
- Also: smaller networks, batch normalisation (mild regularising noise), and data augmentation, which is hard to do honestly with returns.
Why neural networks struggle with low signal-to-noise
Networks dominate vision and language, where labels are nearly noise-free and data are abundant. Return prediction is the opposite regime:
- Tiny . A daily model with predictive correlation explains of the variance. The gradient from the signal is a small bias buried in noisy per-sample gradients, and a flexible network fits the noise first.
- Small effective samples. Twenty years of daily data is about 5,000 rows per asset, and overlapping labels and cross-sectional correlation make the independent information much smaller.
- Non-stationarity. The function being learned drifts; a network trained on 2010–2019 may be fitting a relationship that no longer exists.
- Validation noise. With a tiny signal, the validation loss is itself so noisy that early stopping and hyperparameter search become a source of overfitting.
What works better in practice: strong priors through architecture (shared weights across assets, monotonicity constraints), heavy regularisation, ensembling many seeds, simple targets (ranks or signs rather than raw returns), and benchmarking every network against a ridge regression and a boosted tree on the same features. If the network does not beat both out of sample, it is not adding anything.
Knowledge check
A network with binary cross-entropy loss outputs p = 0.62 (logit 0.5) for an example whose label is 1. What is the gradient of the loss with respect to the logit?
Knowledge check
Every weight in a hidden layer is initialised to the same value 0.01. What happens during training with gradient descent?
Knowledge check
A deep network predicting next-day returns reaches training R² of 40% and validation R² of −2%. Which response is most sensible?
Key takeaways
- A network alternates affine maps and non-linearities; without the non-linearity depth adds nothing.
- Backpropagation is the chain rule run backwards: , and ReLU passes gradient only through active units.
- Pair sigmoid or softmax outputs with cross-entropy to get the clean gradient .
- Initialise randomly with variance about (He: for ReLU) to keep signals and gradients stable.
- Weight decay, dropout and early stopping all trade bias for variance; in finance they are essential, and a network must beat simple baselines out of sample to justify itself.
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).