GithubHelp home page GithubHelp logo

modwt-mars's Introduction

MODWT-MARS

A hybrid model that combines maximal overlap discrete wavelet transform multiresolution analysis (MODWT-MRA) with the multivariate adaptive regression splines algorithm (MARS) to produce a one-step-ahead forecast.

This project is partially inspired from this paper by Jothimani, D., Shankar, R., Yadav, S.S.: Discrete Wavelet Transform Based Prediction of Stock Index: A Study on National Stock Exchange FiftyIndex to explore their general concept and to evaluate their findings and methodolgy.

The premise of this framework is to decompose the close price or log-return of a stock using MODWT-MRA and use the resulting detail coefficients and smooth coefficient as inputs for the MARS model. The MARS algorithm is chosen here subjectively to compare to the papers use of SVR and ANN models.

MODWT allows for decomposition of nondyadic lengthed signals (not constrained to lengths that are multiples of $2^j$ where $j$ is the level of decomposition) and is circular-shift invariant (output is the same regardless of what time-step we start at) making it more suitable for real-world financial time series. It decomposes a signal in time-frequency space, exposing time-frequency information in the orignal signal not seen otherwise. The MODWT-MRA also circularly shifts the coefficients by the phase shift of the underlying wavelet filter to approximately align them in time with the original series, and generally produces a smoother decomposition than MODWT alone while providing additive reconstruction.

A level 3 MODWT-MRA, using a Daubechies least asymmetric wavelet of length 8, is performed in R using reflection at the right boundary* (See Methodological Flaws below). A feature set is generated autoregressively by taking the 4 previous values at each time step given by the expression below.

At time t, value x is defined as:

$x(t) = f(x(t-1),x(t-2),x(t-3),x(t-4))$

This is done for the 3 detail coefficients $D1, D2, D3$ and the smooth coefficient $S3$.

Each coefficient is predicted separately using MARS and then AdaBoost. The predicted coeffcient vectors are then summed up afterwards to produce the final prediction vector since the MRA can additively reconstruct the original signal.

Methodological Flaws

  • It is a common problem amongst quantitative finance research papers to incorrectly apply wavelet transforms, and DSP generally, to financial data and use decompositions as features for model training. My model produces results that are significantly better than the mentioned paper's (Both RMSE (2.827e-03) and DA (95.8%) scores, as used in the paper) but it is misleading and unsusable in the real world. Both the DWT-MRA and MODWT-MRA are fundamentally noncausal methods: at any time t, in order to compute the coefficients the MRA uses data from $t-L+1$ to $t+L-1$ where $L$ is the filter length of the basis wavelet. In the case of this project the choice of the $la8$ wavelet would mean we are looking 7 time steps in the future. Because of the circular convolution in MRA, we also have boundary effected coefficients at both the start and end. The first $L_j - 1$ coefficients and the last $N-L_j+1$ coefficients (where $L_j = (2^j−1)(L−1) + 1$ and $j, L$ are the decomposition level and wavelet filter length respectively) are effected. Only the first $L_j - 1$ coefficients are effected in standard MODWT and Algorithme A Trous (AT), both of which are actually causal. In both cases, these boundary coefficients must be removed and in the case of MRA this makes forecasting impossible.

  • Additionally, applying ML algorithms to each detail coefficient and smooth coefficient separately only compounds these errors in boundary coefficients once added back together. A more thorough and causal framework is required for accurate sequential forecasting.

Packages

Python R
  • numpy
  • pandas
  • statsmodels
  • alphavantage
  • datetime
  • matplotlib
  • scipy
  • xgboost
  • py-earth
  • sklearn
  • waveslim
  • ggplot2
  • alphavantager

Plots

Out of Sample Results (MSE & MDA): alt text

Out of Sample Results (Zoomed in): alt text

modwt-mars's People

Contributors

0zean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar Sayantan Banerjee avatar dubmarm avatar Lungoupao Khongsai avatar Henry Lao avatar Rayyy avatar  avatar 椎名 avatar  avatar  avatar X avatar Lor avatar Claudia Dong avatar  avatar

Watchers

 avatar James Cloos avatar Kostas Georgiou avatar  avatar

modwt-mars's Issues

Decomposing a time series on a rolling window basis.

Hi there Nicholas i'm doing research for my own paper, when i came across your repository,
although i am not quite fluent in R i can see from the code that you have transformed the entirety of the data in one batch, depending on the decomposition algorithm used there could be leaks from data as far as t+3, have you tried an implementation using a rolling window transform.

Best

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.