22
$\begingroup$

Has anyone attempted time series prediction using support vector regression?

I understand support vector machines and partially understand support vector regression, but I don't understand how they can be used to model time series, especially multivariate time series.

I've tried to read a few papers, but they are too high level. Can anyone explain in lay terms how they would work, especially in relation to multivariate time series?

EDIT:To elaborate a bit, let me try to explain with a stock price example.

Say we have stock prices for N days. Then, for each day we could construct a feature vector, which, in a simple case, could be be the previous day's price and the current day's price. The response for each feature vector would be the next day's price. Thus, given yesterday's price and today's price the objective would be to predict the next days price. What I don't understand is, say we have six months training data, how would you give greater emphasis to the more recent feature vectors?

$\endgroup$
17
$\begingroup$

In the context of support vector regression, the fact that your data is a time series is mainly relevant from a methodological standpoint -- for example, you can't do a k-fold cross validation, and you need to take precautions when running backtests/simulations.

Basically, support vector regression is a discriminative regression technique much like any other discriminative regression technique. You give it a set of input vectors and associated responses, and it fits a model to try and predict the response given a new input vector. Kernel SVR, on the other hand, applies one of many transformations to your data set prior to the learning step. This allows it to pick up nonlinear trends in the data set, unlike e.g. linear regression. A good kernel to start with would probably be the Gaussian RBF -- it will have a hyperparameter you can tune, so try out a couple values. And then when you get a feeling for what's going on you can try out other kernels.

With a time series, an import step is determining what your "feature vector" ${\bf x}$ will be; each $x_i$ is called a "feature" and can be calculated from present or past data, and each $y_i$, the response, will be the future change over some time period of whatever you're trying to predict. Take a stock for example. You have prices over time. Maybe your features are a.) the 200MA-30MA spread and b.) 20-day volatility, so you calculate each ${\bf x_t}$ at each point in time, along with $y_t$, the (say) following week's return on that stock. Thus, your SVR learns how to predict the following week's return based on the present MA spread and 20-day vol. (This strategy won't work, so don't get too excited ;)).

If the papers you read were too difficult, you probably don't want to try to implement an SVM yourself, as it can be complicated. IIRC there is a "kernlab" package for R that has a Kernel SVM implementation with a number of kernels included, so that would provide a quick way to get up and running.

$\endgroup$
  • $\begingroup$ @Jason, thanks for the response. I'm confused as to how to make older data less important during training, i.e. how to give important to the last say 100 examples, rather than the last 10,000 examples. Also, I have some experience working with SVMs in Python, so I am looking to use that. $\endgroup$ – raconteur Aug 19 '11 at 9:20
  • $\begingroup$ You can't really use all the past data as your feature vector; you have to transform it somehow into a meaningful feature. For example, consider averaging the past 20 values of the time series, or the current value of the series divided by the moving average. These are features that indicate in one simple number an import characteristic of the data set. Come up with (say) 10 or so features that you think will be as predictive as possible. So to make older data less important, you'd make it less important when defining your features (i.e. use shorter moving averages). $\endgroup$ – William Aug 19 '11 at 14:35
  • $\begingroup$ @Jason, let me try to explain with a stock price example. Say we have stock prices for N days. Then, for each day we could construct a feature vector, which, in a simple case, could be be the previous day's price and the current day's price. The response for each feature vector would be the next day's price. Thus, given yesterday's price and today's price the objective would be to predict the next days price. What I don't understand is, say we have six months training data, how would you give greater emphasis to the more recent feature vectors? $\endgroup$ – raconteur Aug 19 '11 at 15:26
  • 2
    $\begingroup$ Oh I see what you mean now. The short answer is, you can't, at least not without reengineering the SVM to understand the notion of recency. An SVM is defined in terms of x-y pairs, not ordered x-y pairs, and so the objective function it minimizes is a function of said pairs. OTOH, you could run several separate SVMs, one with the past month, one with the past year, and one with the past two years -- and then do a weighted average of the responses you get back based on your personal preference for recent vs. old data (e.g. 0.7 * past month + 0.2 * past year + 0.1 * past 2 years). $\endgroup$ – William Aug 20 '11 at 0:28
  • $\begingroup$ @William.. do you have any recommendation on which machine learning algorithms would be best for time series prediction (the same problem that raconteur asked) other than SVM? would the answer be different when applied in different domain? e.g. stock price vs supply chain forecasting (forecasting the demand of the products we are selling).. $\endgroup$ – Lam Feb 17 '17 at 4:24
1
$\begingroup$

My personal answer to the question as asked is "yes". You may view it as a pro or a con that there are an infinite number of choices of features to describe the past.Try to pick features that correspond to how you might concisely describe to someone what the market has just done [eg "the price is at 1.4" tells you nothing if it is not related to some other number]. As for the target of the SVM, the simplest are the difference in prices and the ratio of prices for two consecutive days. As these correspond directly to the fate of a hypothetical trade, they seem good choices.

I have to pedantically disagree with the first statement by Jason: you can do k-fold cross-validation in situations like that described by raconteur and it is useful (with a proviso I will explain). The reason it is statistically valid is that the instances of the target in this case have no intrinsic relationship: they are disjoint differences or ratios. If you choose instead to use data at higher resolution than the scale of the target, there would be reason for concern that correlated instances might appear in the training set and validation set, which would compromise the cross-validation (by contrast, when applying the SVM you will have no instances available whose targets overlap the one you are interested in).

The thing that does reduce the effectiveness of cross-validation is if the behavior of the market is changing over time. There are two possible ways to deal with this. The first is to incorporate time as a feature (I've not found this very useful, perhaps because the values of this feature in the future are all new). A well-motivated alternative is to use walk-forward validation (which means testing your methodology on a sliding window of time, and testing it on the period just after this window. If behaviour is changing over time, the saying attributed to Niels Bohr "Prediction is very difficult, especially about the future" is especially appropriate. There is some evidence in the literature that the behaviour of financial markets does change over time, generally becoming more efficient, which typically means that successful trading systems deteriorate in performance over time.

Good luck!

$\endgroup$
  • $\begingroup$ Velcome to our site! $\endgroup$ – kjetil b halvorsen Jun 14 '14 at 16:45
0
$\begingroup$

There's an example up on Quantum Financier for using an SVM to forecast financial series. It could easily be converted from a classification system (Long/Short) to a regression system.

$\endgroup$
  • 1
    $\begingroup$ DEAR GOD PLEASE nobody use that strategy! That's how beginners get smoked by Wall St :( The oldest trick in the book is retrofitting a statistical model using some basic technical analytic like RSI so the newbs think they've struck gold. $\endgroup$ – William Aug 19 '11 at 14:37
  • 1
    $\begingroup$ @Jason from the original post "I also want to make clear that I do not think that this is a good system." However, it is a good example of how to fit a support vector machine to a time series. $\endgroup$ – Zach Aug 19 '11 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.