# Forecasting time series based on a behavior of other one

Apologies for this vague and unclear question, I have no background in statistics.

I have two vectors of time series data, covering a six month period. The data is in daily intervals (except for weekends).

The first vector contains the stock volume for a company on each of the days. The second vector contains an external volume variable (the number of Google searches) taken on the same date. As visible on the graph above, (which is out of scale etc.) there is some type of relationship between the two.

I want to model the two time series as to predict a future stock volume values.

So far I have briefly looked into:

• support vector machines for regression: but when I plotted the data on a scatter graph there isn't any clear relationship, so this made me think that the SVM approach would fail.

• time series analysis: this approach confused me because there isn't any obvious trends in the data

Can anyone offer any advice on what I approach I should take?

• In the sentence "I want to model the two time series as to predict a future values of $X$", what is $X$? Is that one of the two time series or is this a third variable? – Macro Aug 16 '11 at 15:12
• @Macro, apologies, I want to predict future values of the first vector, the stock volume. – S0rin Aug 16 '11 at 15:53
• Is this really a rephrasing of your previous question at stats.stackexchange.com/questions/14237/…? – whuber Aug 16 '11 at 16:11
• @whuber, I think not. The purpose of that question is/was about normalisation, specifically how to normalise stock volume. The purpose of this question is to get feedback on how to model the actual data, which is displayed on the above graph. – S0rin Aug 16 '11 at 16:16

You can learn a lot by exploring the temporal relationships among the data before setting off on more sophisticated methods of time series analysis.

Because the image does not provide a horizontal scale, I have used an artificial one (pixel coordinates of the image columns). I have freely rescaled the two plots and placed the activity at zero, which is likely what its minimum is: (There's a tiny problem where the two graphs originally overlapped, but that won't affect the analysis.)

Because you're looking for a potential causal effect of activity (red) on volume (blue), plot the forward cross-correlation function. This simply computes the correlation of the activity[1..n+1-k] and volume[k..n] as a function of k (the "lag"). My first pass at this found--as one would expect--that the extreme activity peak has a lot of leverage, so I went back and used the logarithm of 1+activity instead. Here's the cross-correlation: It reaches a definite peak at a lag of k=20. (The peak using the untransformed activities was at k=18, essentially the same.) To better see what's going on, look at the scatterplot of activity[1..n+1-20] against volume[20..n]: That is, each log activity value (x) is plotted against the volume after 20 units of time have elapsed (y). (The points are colored according to time. This is really a 3D plot with time as the z coordinate, looked at from high above. 3D manipulations make the patterns clearer.)

This scatterplot makes it evident that the relatively high correlation at this lag (about 0.40 according to the preceding plot) is due entirely to the activity peak at time 220 being followed by the volume peak at time 220+20 (as followed by a plunge shortly thereafter). Everything else looks like random wandering. This tells us that there may be less than meets the eye: the appearance of a temporal relationship between these two series is caused by a single event and its aftermath; it does not appear to be a general association.

In effect, you may have one observation of a high activity followed after a certain short time by a spike in volume. Was this a coincidence or (hopefully) evidence of a pattern? It's impossible to tell. Additional data might bear out this generalization or might falsify it. Regardless, cross-correlation plots and lagged scatterplots are powerful and useful tools to evaluate the relationships.

• "(pixel coordinates of the image columns)" i've heard of this, what software did you use to achieve that? – user603 Aug 16 '11 at 18:39
• @user Mathematica 8. It can import an image as an array of (r,g,b,a) values. I used it to select the row indexes of all such values that were predominantly red (resp. blue) in each column (after trimming off the legend), then averaged those and plotted the results to verify. Where blue values were missing (the red curve crosses over the blue), I substituted red values. This approach was possible because each time series appears as a distinct functional graph: only one value in each column. – whuber Aug 16 '11 at 18:51
• @whuber, thank you so much for the detailed answer. It is much appreciated. I'm taking my time to try and understand it all. – S0rin Aug 18 '11 at 9:51
• @Moom If you need details, examples, or clarification, ask away: our objective on this site is to create great answers by using the community to improve what we have. – whuber Aug 18 '11 at 15:24
• @Lepidopterist Yes, the log was a quick and dirty way of reducing the leverage of extremely high values. The colors are explained directly beneath the graphic: "The points are colored according to time... ." This particular sequence of colors was a terrible choice, because it does not clearly indicate the times, but at least the colors help the eye discriminate groups of data within narrower time ranges. They demonstrate that the excursions beyond log activities of 4 and below volumes of 250 occurred during the same narrow period. – whuber Mar 19 '17 at 20:55

What do you want to do : - Make forecasting of each of the time serie independently? - Make forecasting of one time series and then determine the values of the other one?

In any case this reference will help you a lot : http://www.sciencedirect.com/science/article/pii/S0169207006000021

What is the length of your time series (meaning how much data do you have)? What is the horizon of forecasting (meaning do you want to make 1 day, 1 month or 1 year ahead prediction)?

By looking at your data, I would say that there is no obvious trend of seasonality, to look at a longer time series would help to be sure, to see if there's any seasonality or trend, plot the autocorrelation function (you can find lot of stuff about it).

For both of your time series, they look like a random walk except maybe for the peak, it depend of what you want to model. If you're interested of modeling the right amount of peak in your data without being precise on the other value beetween the peak, use a count process (poisson process) or maybe a threshold model. If you want to model the other value, then autoregressive model could be a solution.

You can use time series analysis even if there is no trend in your data. Support Vector Machine are maybe a little too complex for the kind of time series you have, but it could be an interesting to dig into it, if you have time to spend on it.

• thanks for the response. I just want to predict the stock volume one day in advance. I have six months data, however, the stock volume time series does't have weekend data. I'll look into the count process (poisson process) and threshold models. – S0rin Aug 16 '11 at 15:54

You're trying to predict what, future volume? Is this a market impact model or something?

If you're trying to predict volume, time series analysis is likely your friend. This would basically be running an autoregressive model, i.e. a linear regression where the $x_{ij}$ are changes in volume ($j=0$) and Google searches ($j=1$) and the $y_i$ are future changes.

As for SVMs, an ordinary linear SVM might not be the best bet; check out kernel SVMs, which transform the data in various ways to elucidate relationships that would otherwise not be linearly separable. This could be helpful for dealing with any nonlinearities in your data, which definitely occur in financial data sets.

If you're actually intending to predict future price change, the KSVMs are likely the way to go, since predicting returns is extremely difficult and I could imagine many of the most useful aspects of the data would involve extreme values, i.e. nonlinearities.

If you're actually predicting volume/market impact/slippage, time series analysis is the most standard way to go.

• I am only trying to model and then predict stock volume, preferably by a day. I'll look into time series analysis again. Thanks. – S0rin Aug 16 '11 at 16:04
• Would this be a Vector AutoRegressive model? – S0rin Aug 16 '11 at 17:03
• Yes, but with fixed coefficients. – William Aug 16 '11 at 20:20