Using a conditional function with TimeSeriesThread

Hello,

I have trouble using a function that hosts a “Which” function inside a TimeSeriesThread function.

This is a function I wrote, the Which function lies in it :

MyFunction = Function[{ts1,ts2,ts3},
Which[
(ts1-ts2)>=(2*(ts3-ts2)/3),1,
(ts1-ts2)>((ts3-ts2)/3)&&(ts1-ts2)<(2*(ts3-ts2)/3),0,
(ts1-ts2)<=(ts3-ts2)/3,-1]];

Let’s suppose I have 3-time series named “TimeS1”, “TimeS2” and “TimeS3” with numerical Values only. If I call my function inside a TimeSeriesThread :

TimeSeriesThread[myFunction[First[#],Take[#,2],Last[#]]&,{TimeS1,TimeS2,TimeS3}]["Path"]

the “Path” display prints this instead of the calculated values:

{{3818707200,Which[{0.,2.63041}≥{2.78062,4.53423},1,128.453-{128.453,125.823}> etc

Do you have any idea of how I could run properly my function inside a TimeSeriesThread?

Thank you!

I haven’t checked your MyFunction for correctness, but the thing that jumps out at me is the Take[#,2] expression. That will produce a List. I think what you probably wanted was Part[#,2].

Probably not related to your question, but I think you can simplify

MyFunction[First[#],Part[#,2],Last[#]]&

to be just

Apply[MyFunction]

Thank you very much!