# Strategy Library

## SVM Wavelet Forecasting

### Introduction

Several methods have been developed to forecast time-series, from ARIMA to Neural Networks. In this strategy, we combine a Support Vector Machine (SVM) and Wavelets in an attempt to forecast EURJPY. Although SVMs are generally used for classification problems, such as classifying proteins, they can also be applied in regression problems, valued for their ability to handle non-linear data. Furthermore, Wavelets are often applied in Signal Processing applications. Wavelets allow us to decompose a time-series into multiple components, where each individual component can be denoised using thresholding, and this leads to a cleaner time-series after the components are recombined. To use these two models in conjunction, we first decompose the EURJPY data into components using Wavelet decomposition, then we apply the SVM to forecast one time-step ahead of each of the components. After we recombine the components, we get the aggregate forecast of our SVM-Wavelet model.

### Method

Given EURJPY data, our first step is to decompose our data into multiple resolutions.
We work with wavelets using the **pywt** package. For denoising, Daubechies and
Symlets are good choices for Wavelets, and we use Symlets 10 in our strategy. We create a Symlets 10 Wavelet
using the following:

w = pywt.Wavelet('sym10')

To determine the length of the data we’d need for a certain number of levels after decomposition, we can solve for:

\[log_{2}(\frac{len(data)}{wavelength-1})=levels\] Given the length of a Symlet 10 wavelet is 20, if we want three levels, we
solve for **len(data)** to get **len(data) = 152**, which means **data** would need to have at least
152 values. Since we will denoise our components using thresholding,
we specify **threshold = 0.5** to indicate the strength of the thresholding.
This **threshold** value can be any number between 0 and 1.

To decompose our data, we use:

coeffs = pywt.wavedec(data, w)

For each component, we threshold/denoise the component (except for the first component, the approximation coefficients), roll the values of the component one spot to the left, and replace the last value of the component with a value forecasted from an SVM. This process looks like the following in code:

for i in range(len(coeffs)): if i > 0: # we don't want to threshold the approximation coefficients coeffs[i] = pywt.threshold(coeffs[i], threshold*max(coeffs[i])) forecasted = __svm_forecast(coeffs[i]) coeffs[i] = np.roll(coeffs[i], -1) coeffs[i][-1] = forecasted

The **__svm_forecast** method fits partitioned data to an SVM model then predicts one value into the
future, and can be found under **SVMWavelet.py** file under the **Algorithm** section

Once we forecast one value into the future, we can aggregate the forecasts by recombining the components into a simple time-series. We do this with:

datarec = pywt.waverec(coeffs, w)

Since we want the aggregate forecast one time-step into the future, we return the last element of this time-series, or **datarec[-1]**.

Our trading rules are simple: feed in the past 152 points of daily closing prices of EURJPY into our SVM Wavelet forecasting method, and divide that number by the current close of EURJPY to get the forecasted percent change. Then, we emit an Insight based on the direction of the percent change with the weight of the Insight as the absolute value of the percent change. We use the **InsightWeightPortfolioConstructionModel** so that the weight of the Insight determines the portfolio allocation percentage, which means larger forecasted moves will have a larger allocation.

### Results

The performance of the algorithm was decent. Over the past five years, the algorithm achieved a Sharpe Ratio of 0.252, while buying and holding SPY over the same period would have achieved a Sharpe Ratio of 0.713. Some ideas for improvement include:

- Testing different Wavelet types (e.g. Daubechies)
- Trying out other time resolutions (e.g. Minute)
- Using alternative Decomposition methods (e.g. Stationary Wavelet Transform)

If a user comes across any interesting results with modifications of this algorithm, we’d love to hear about it in the Community Forum.

### References

- M. S. Raimundo and J. Okamoto, "SVR-wavelet adaptive model for forecasting financial time series," 2018 International Conference on Information and Computer Technologies (ICICT), DeKalb, IL, 2018, pp. 111-114, doi: 10.1109/INFOCT.2018.8356851. Online Copy.

You can also see our Documentation and Videos. You can also get in touch with us via Chat.

Did you find this page helpful?