Market Analysis
An application of Wavelet Theory by LTSM-RNN-CNN Architecture
This project is a automated trading bot that can both buy long and short positions on the stock market utilizing the theoretical framework of wavelet theory to inform it's trade
Agent Performance
Using the most recent 150 days of our data as validation on a random sample of tickers from the S&P-1500, The agent has a relative profit of ~0.05% per day compared to the underlying asset's performance (i.e. buy and hold). This translates to beating the underlying asset by ~20% over the year assuming compound gains from reinvestment.
Source Code
The source code can be found here
Features For Each Stock Ticker
- Open, Close, High, Low, EMA(12), EMA(26), MA(6), DI, MACD, and PSY(13)
The above features are preformed on data that's been differenced once i.e. . This is done as financial instruments tend to show a linear trend over a short time period, this can be tested using a stationary test such as the Augmented Dickey Fuller Test. Given the Trading bot cares more about price direction/action rather than price level the first difference will give us more relevant information.
Furthermore features were chosen to give a wide variety of information upfront to improve training efficiency.
Theoretical Motivation
Usually the focus of analysis on a time series stays within the time-domain but there's a set of tools and methods available for the frequency-domain. Given a zero-mean stationary time series we can utilize the fact of the spectral representation of a stationary process to write
Where is a complex-valued process with uncorrelated increments. In essence this means we can represent any stationary time series in the frequency-domain and not lose any information (or vice-versa).
This is of particular importance when a process is known to exhibit some form of periodic behavior suppose is stochastic periodic series, i.e.
Given is a constant fix for simplicity, then we have
We see for
And for
In fact
And
With a stochastic periodic function it returns to a particular mean at given intervals. The frequency-domain would then give us insight at when completes one full period, I.e. it would spike at . While this is trivial let
The frequency-domain for would give us a spike at Generalizing this the frequency domain allows us to extract periodic components/signals from a time series. If we wanted to give it an upward trend such that on average it would increase over time all we need to do is add .
Note that under a difference operator
Without loss of generality we have
Which is another periodic stochastic time series.
If the periodicity is fixed like above then the intervals are regular and we can use the Spectral Fourier Transform. However, not all time series exhibit regular periodic intervals, especially financial instruments, and hence we will have use more generalized approach, Wavelets.
A Wavelet
A Wavelet allows us to operate on the frequency-domain. We start by introducing two functions: mother wavelet (the wavelet function) and a father wavelet (the scaling function).
A low-pass and high-pass filter can be derived from both the mother and father wavelet functions. The mother wavelet is a high-pass filter and the father wavelet is the low-pass filter. A standard example of a low-pass filter is any convolution, say a moving average. Where an example of a high-pass filter is a differencing operation i.e. . The low pass filter extracts the lower-frequency patterns while the high-pass filter extracts the higher-frequency patterns. Together these make up a band-pass filter which allows you to exact and isolate both low and high signals from your data - without implying the periodicity stays the same.
Given these two facts hold:
- A father wavelet can be seen in a CNN by definition you performing a convolution hence you are extracting low-frequency data
- A mother wavelet can be seen in a LTSM-RNN byallowing functional combinations of previous lags through LTSM cells (A difference operator is just a linear combination)
Thus LTSM-RNN-CNN architecture will allow an emergent property something similar to a trainable wavelet function in you have both the mother and father wavelet allowing you to exact frequency-domain information from the given time series.
Theoretical Implications
Now given that for the U.S. market on average financial time series are highly cyclical, and trending upwards. Denote as the profit at time , where . Suppose we bought and held for the entire time, then
Suppose you bought at and then sold and rebought every cycle. Let be the difference between the selling and rebuying price. For simplicity suppose the buy and hold strategy is represented by selling and immediately rebuying i.e. = 0, then
Maximum profit would be selling the maximum value of each cycle and buying the minimum value of each cycle, however any will beat the strategy of buying and holding. Hence, being informed about the periodic behavior of the underlying time series can allow you to capture more profit.