# Time Series

As explained above, each stock indicator is modelled as a time series. A time series is a vector of  values (float) associated with a calendar. Times series can have different time scales. Calendars can differ in time units and in positions in time. To reconsile time series with different calendars, we introduce the synchronize opertor synchronize(A, cal, fun) where A is the time series to transform, cal a calendar (given as a time series of time)  and fun a function. The operator use the function to  either group values condensed in a time unit, or split a value distributed among several time units. This usefull operator in the context of multiple time series coming from multiple sources at different scales is formally denoted Θfun(TS1, TS2).

Other binary operations such as intersection, union, and join of TS can be introduced. We only need for our financial application a sort of join on calendars denoted ∩fun. It merges two series with same calendars by applying on the corresponding entries the function fun, i.e., it replaces the two values X[i] and Y[i] with same time index i by fun( X[i] ,Y[i] ). Let us point out that :

### B ∩- C = A - B A ∩+ C = A + B

Thence, ∩fun is a more general operation that covers full product of TS. For example, D = B  ∩* C is a full product of B and C given below :

 0 1 2 3 4 5 300 147 ! 75 192 !

### Windowing Operations

Most indicators proposed to predict time series future values (e.g., stock prices) work on sliding time periods called windows. Let [xi-w, xi-w+1, ... xi] be a window vector sliding on a time series TS when i goes from 0 (the begining of the series) to n (the last time of the series). To derive a new value from a window, a function on the corresponding vector must be applied. To apply such functions when sliding on a series, we introduce a new algebraic operator called apply as follows : apply(TS, win, fun). Notice that apply aggregates ordered window values, not only unorderd set of values as classical SQL aggregates. The parameter win is the window size.

Thence, the function can be a simple aggregate function not taking into account the vector order such as MIN, MAX, AVG, SUM, ..., or a function defined on ordered vectors such as MOM, EXP, RSI, ... Examples are more precisely:

• MOM the momentum calculated as (TS[i] - TS[i-w]); it is the differential of a series at rank w.

• EXP the exponential average using the formula Outpout[i] = Multiplier * Input[i] + (1-Muliplier) * Output[i-1].

• RSI the relative strength index; applied to a window at time i, it computes the ratio 100 * SUM(D+[i])/ (SUM(Pos[i])-SUM(Neg[i])), where Pos[i] is the positive gain (TS[i] - TS[i-1]) if > 0 and Neg[i] is the negative loss (TS[i] -TS[i-1]) if < 0.

• We formally denote Ωfun (TS, win) the application of a window function fun to a window of size win slidding over TS. To illustrate, we give below the time series EΩAVG (A, 3)  (if you prefer apply(A, 3, AVG)) that computes the moving average of A with a sliding window of 3.

 0 1 2 3 4 5 10 9 10 24.33 8.66 8.33

We finally give below the time series F = apply(A, 3, RSI) that computes the relative strenght index of A with a sliding window of 3.

 0 1 2 3 4 5 50 0 66 43 27 100

In summary, our model is quite powerful, incorporating time series with calendars, null values (unknown and not existing) encapsulated with classical operators (+, *, φ) and less classical and more generic ones (Θ, ∩, Ω), which are parametrized by a user function. It is powerful enough to model most indicators and buy/sell rules in the stock market technical analysis domain.