How CNNs reuse local filters across grids: a checked 1D example, channels, receptive fields, pooling, bottlenecks and the timing rules for financial data.
Convolutional neural network
A convolutional neural network (CNN) is a neural network that applies learned local filters repeatedly across a grid, such as image pixels or time-indexed observations. In quantitative research, this offers a compact way to extract recurring local patterns from structured data. The useful assumption is that the same local relationship may matter at several positions; arbitrary columns in a spreadsheet do not automatically have that structure.
One filter, reused
A kernel is a small array of weights. Slide it along the input and take a weighted sum at each position. The resulting sequence or grid is a feature map. Reusing the weights is parameter sharing; the input region that can influence an output is its receptive field. Dive into Deep Learning §7.1 derives this local, shared structure from constraints on a fully connected layer.
Take the unitless input (1,2,3,4) and kernel (1,−1). Use stride one, zero bias, no activation and valid padding, meaning no extra entries at the edges. Under the cross-correlation convention, without reversing the kernel:
yi=xi−xi+1,i=0,1,2.
The three outputs are 1−2=−1, 2−3=−1 and 3−4=−1. The filter measures the negative of each adjacent increment. It does not predict the next observation.
Three sliding windows over unitless input 1, 2, 3, 4 reuse kernel 1, minus 1. With stride 1, valid padding and bias zero, calculations 1 minus 2, 2 minus 3 and 3 minus 4 each produce minus 1 before activation.
Original illustrative calculation: the weights are shared across positions; the input values change with the window.
Check the convention. Neural-network libraries often call cross-correlation “convolution.” Mathematical convolution reverses the kernel: the valid output for these same stored values is instead (1,1,1). The distinction changes hand calculations even though either convention can learn filters. Also, these are pre-activation outputs: applying a rectified linear activation would turn all three negative values into zero. Deep Learning §9.1 explains the kernel-flip distinction.
Channels are not extra time steps
For a 1D financial input, time can be the sliding axis while returns, volume and spread are separate input channels. An ordinary ungrouped filter has weights for every channel at every kernel position; it sums across those channels to produce one output channel. Several filters produce several output channels. The TensorFlow Conv1D specification distinguishes width, input channels and output channels explicitly.
For kernel width K, input-channel count Cin and output-channel count Cout, an ordinary layer with one bias per output channel has
Cout(KCin+1)
trainable parameters. The count does not grow with sequence length. Grouped or depthwise layers impose different channel connectivity, so this formula does not apply unchanged to them.
The stride is the distance between successive window starts. Padding supplies boundary entries, often zeros. With length N, symmetric padding of P entries on each side, stride S, no dilation and N+2P≥K, the output length is
Nout=⌊SN+2P−K⌋+1.
For the worked example this gives three outputs. Keras documents valid, same and causal modes, channel layouts and their shape implications in its Conv1D reference. “Same” describes output-size behaviour under specified strides; it does not certify time causality.
Building a hierarchy without retaining every position
Nonlinear activations between convolutional layers allow increasingly complex features. Stacking layers also expands the nominal receptive field: two width-three, stride-one layers without dilation let an interior second-layer output depend on five original positions. That describes possible dependencies, not equal importance of all five inputs.
Pooling summarises nearby activations, usually by a maximum or average. With downsampling it reduces resolution and loses positional detail; it does not guarantee invariance to every input shift. A strided convolution also reduces resolution, but learns its local transformation rather than applying a fixed maximum or average. Deep Learning §9.3 develops the pooling distinction.
A bottleneck block tackles channel cost: a pointwise 1×1 convolution reduces channels, a spatial 3×3 convolution works on the narrower representation, and another 1×1 convolution restores channels. Pointwise means one spatial position, not one input channel: channels can still mix. The original ResNet bottleneck design combines this construction with a shortcut connection; the shapes must agree before addition. See He et al., §4.1 and Figure 5.
A financial feature must use only information available when the decision is made. In the worked example, the first output needs both x0 and x1: it becomes available after x1, not after x0. Label alignment matters as much as the filter formula.
For an output at each timestamp, a centred window can introduce look-ahead bias if it reaches beyond that timestamp. Keras's causal padding prevents an output from depending on later inputs. Conversely, a centred operation entirely inside a historical window ending at the current decision cutoff can be valid for a single prediction at that cutoff. Symmetric padding is not inherently leakage; using unavailable observations is.
Architecture cannot repair future-fitted preprocessing or a contaminated evaluation split. Nor does converting prices into candlestick images establish predictive value or trading profitability. A temporal convolutional network develops specialised sequence architecture; a CNN for order books must additionally respect book structure and event timing.