2016-12-22 20:15:07 +04:00
|
|
|
import numpy as np
|
2016-12-23 14:18:33 +04:00
|
|
|
import math
|
2016-12-22 20:15:07 +04:00
|
|
|
from pyFTS import *
|
|
|
|
|
2016-12-23 14:18:33 +04:00
|
|
|
|
2017-01-23 17:00:27 +04:00
|
|
|
def differential(original, lags=1):
|
2016-12-22 20:15:07 +04:00
|
|
|
n = len(original)
|
2017-01-23 17:00:27 +04:00
|
|
|
diff = [original[t - lags] - original[t] for t in np.arange(lags, n)]
|
|
|
|
for t in np.arange(0, lags): diff.insert(0, None)
|
2016-12-23 14:18:33 +04:00
|
|
|
return np.array(diff)
|
|
|
|
|
|
|
|
|
|
|
|
def boxcox(original, plambda):
|
|
|
|
n = len(original)
|
|
|
|
if plambda != 0:
|
|
|
|
modified = [(original[t] ** plambda - 1) / plambda for t in np.arange(0, n)]
|
|
|
|
else:
|
|
|
|
modified = [math.log(original[t]) for t in np.arange(0, n)]
|
|
|
|
return np.array(modified)
|
2017-01-20 19:51:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
def Z(original):
|
|
|
|
mu = np.mean(original)
|
|
|
|
sigma = np.std(original)
|
|
|
|
z = [(k - mu)/sigma for k in original]
|
|
|
|
return z
|
2017-01-23 17:00:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
# retrieved from Sadaei and Lee (2014) - Multilayer Stock ForecastingModel Using Fuzzy Time Series
|
|
|
|
def roi(original):
|
|
|
|
n = len(original)
|
|
|
|
roi = []
|
|
|
|
for t in np.arange(0, n-1):
|
|
|
|
roi.append( (original[t+1] - original[t])/original[t] )
|
|
|
|
return roi
|