Skip to main content
. 2020 Oct 15;22(10):1162. doi: 10.3390/e22101162
Algorithm 1. Auto-Labeling Data for CTL
Input: Original Time series dataX=[x1,x2,x3,...,xN]T,ω>0, which represents the proportion threshold parameter of the trend definition
Output: The label vector Y=[label1,label2,label3,...,labelN]T
Initialization of related variables:
FP=x1, which represents the first price obtained by the algorithm; xH =x1, used to mark the highest price; HT=t1, used to mark the time when the highest price occurs; xL =x1, used to mark the lowest price; LT=t1, used to mark the time when the lowest price occurs; Cid=0, used to mark the current direction of labeling; FP_N =0, the index of the highest or lowest point obtained initially.
fori = 1:N
  if (xi > FP + x1*ω)
    Set [xH, HT, FP_N, Cid ] = [ xi, ti, i,1] and end for
   if (xi < FP- x1*ω)
    Set [xL, LT, FP_N, Cid ] = [ xi, ti, i, −1] and end for
end for i
for i = FP_N+1:N
   if (Cid > 0)
    if (xi > xH)
     Set [xH, HT] = [ xi, ti ]
    if (xi < xH - xH*ω and LT <= HT)
     for j = 1:N
      if (tj > LT and tj <= HT)
       Set yj = 1
     end for j
      Set [xL, LT, Cid] = [ xi, ti, −1]
    if (Cid < 0)
     if (xi < xL)
      Set [xL, LT] = [ xi, ti ]
     if (xi > xL + xL *ω and HT <= LT)
     for j = 1:N
      if (tj > HT and tj < = LT)
       Set yj = −1
     end for j
     Set[xH, HT, Cid] = [ xi, ti, 1]
end for i