I'm using package dtw (R) to compare subsets of a price time-series. I have 100 observations through which I loop a rolling window and extract subsets of 5 consecutive observations. I thus obtain multiple equal subsets of my data.

    > head(data_xts[,4])
2015-06-01 00:00:00 0.88337
2015-06-01 00:01:00 0.88375
2015-06-01 00:02:00 0.88412
2015-06-01 00:03:00 0.88394
2015-06-01 00:04:00 0.88380
2015-06-01 00:05:00 0.88393

I now want to compare the line resulted from the above subset with another subset from the same list

f <- dtw(input, input2, step=asymmetricP1, keep=T)

enter image description here

The question is: As Prices increase or decrease (as they do) if I compare the price line of my first 5 periods with that of the last 5 periods i have lines on a different scale. is scale an issue? and if yes should I standardize my data first?

I have three options:

Option 1

I calculate the % difference between observations prior to subsetting. i.e % return. Then I subset into consecutive periods of 5.Then simulate a USD = 1 investment in that 5 period return to generate a new line. Thus my scale always starts from USD = 1.

Option 2

I normalize all values across the 100 periods using Z score and then split.

Option 3.

I normalize all values using Z score after splitting on individual subsets of 5. I thus use the standard deviation and mean of each subset in the calculation instead of the total.

  • $\begingroup$ "I now want to compare the line resulted from the above subset with another subset from the same list" - What is the intention of your comparison? Are you simply shape matching, or does absolute value and shape simultaneously matter? $\endgroup$
    – Arun Jose
    Commented Jun 13, 2018 at 18:24
  • $\begingroup$ the absolute value is not relevant, the shape maters. It is strictly used for pattern / shape matching. The method used is Euclidean Distance $\endgroup$ Commented Jun 13, 2018 at 18:29

1 Answer 1


Option 3 seems like what I'd try first. This ensures every single subset will not be affected by its current local mean, and will have record low distance when shapes indeed line up.

Option 2 would not alleviate any problem faced while using raw data as is. This is simply because all you are doing is changing units, but not adjusting for differences in local means.

Option 1 might be a useful alternative that can be compared to results of option 3.

More so, I don't see any reason why option 1 or 3 should be the "right" answer. They are ways of investigating two different questions. Based on your problem definition, you might be in a better position to choose.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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