Market Analysis
A Wavelet-Inspired LSTM-CNN Trading Model
This experimental trading agent takes long and short positions using an LSTM-CNN architecture. The design is motivated by wavelet analysis: recurrent layers can learn from changes across time, while convolutional layers can extract local patterns at different scales.
Agent Performance
On a random sample of S&P 1500 tickers, using the most recent 150 days as validation data, the agent returned about 0.05% per day more than the underlying asset's buy-and-hold return. Compounding that daily difference would imply roughly 20% over a year, but the short validation window, sampling design, and absence of transaction costs make that an illustrative backtest result rather than evidence of future performance.
Source Code
The source code is on GitHub.
Features for Each Stock Ticker
- Open, Close, High, Low, EMA(12), EMA(26), MA(6), DI, MACD, and PSY(13)
These features are calculated on first-differenced data: . This is done as financial instruments often trend over short periods. An augmented Dickey-Fuller test can check whether differencing produces a stationary series. Because the agent predicts price direction rather than price level, changes are also a more relevant input than the raw level.
The feature set combines price, trend, momentum, and range measures so the model does not have to infer each of those summaries from raw closing prices alone.
Theoretical Motivation
Time-series analysis often stays in the time domain, but the frequency domain offers another way to describe recurring behavior. For a zero-mean stationary time series , the spectral representation is
Where is a complex-valued process with uncorrelated increments. This representation moves a stationary series into the frequency domain without discarding information.
This is useful when a process contains periodic behavior. Suppose is a stochastic periodic series:
The angular frequency determines how often the process repeats. A frequency-domain representation exposes that component as a peak rather than requiring us to infer the cycle from the raw timeline. Now add a second component with twice the frequency:
The frequency representation for contains peaks at and . More generally, it separates periodic components that overlap in the time domain. We can add a linear trend with the term :
Note that under a difference operator
Without loss of generality we have
The trend disappears after differencing, leaving changes in the periodic components and the constant drift .
When frequencies remain fixed, a Fourier transform can expose them. Financial series rarely maintain a stable period across the full sample, which motivates a localized method such as a wavelet transform.
Wavelets
A wavelet lets us analyze localized frequency behavior. We start with two functions: mother wavelet (the wavelet function) and a father wavelet (the scaling function).
The scaling function is associated with low-pass filtering, while the wavelet function captures higher-frequency changes. A moving average is a familiar low-pass operation. First differencing, , emphasizes faster changes. Used together, these filters separate behavior at different scales without assuming a fixed period across the full series.
A CNN learns local filters over short windows, while an LSTM carries information across longer sequences. Those learned filters are not guaranteed to be low-pass or high-pass filters, and the network is not a formal wavelet transform. The wavelet connection is a design intuition: the two paths can learn complementary summaries at different time scales.
Theoretical Implications
For a simplified upward-trending price series, denote profit at time by , with . A buy-and-hold return can be written as
Suppose a strategy sells and rebuys during a cycle. Let be the extra gross return captured between the sale and repurchase:
In this simplified expression, a positive beats buy and hold before costs. Real performance also depends on whether the model identifies the turning points out of sample, how often it trades, bid-ask spreads, slippage, taxes, and shorting costs. The backtest should therefore be read as a model experiment, not as a trading claim.