Last active
October 3, 2020 11:08
-
-
Save timotewb/8da892c7f61e106a4a81474f7a0bba8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def t3MovingAverage(period,data,vfactor=0.7,tcount=3): | |
#--- T3 Moving Average | |
# data: array, time series data e.g. daily close prices. | |
# period: integer, number of periods form time series array to include in calculation. | |
# vfactor: float, number between 1 and 0. 1 = DEMA, 0 = EMA. default 0.7. | |
# tcount: integer, number 1 or greater. times the data is smoothed with the generalisedDEMA. default 3 (T3). | |
# | |
# requires numpy and techind libraries | |
# | |
# see below link for maintained code | |
# https://github.com/codersnotepad/techind/blob/master/techind/t3MovingAverage.py | |
import numpy as np | |
import techind as ti | |
#---Generalised DEMA (GD) | |
def generalisedDEMA(period,data,vfactor): | |
ema1 = ti.exponentialMovingAverage(period,data) | |
ema2 = ti.exponentialMovingAverage(period,ema1) | |
# GD = EMA(period,data) x (1+vfactor) - EMA(periodT3,EMA(period,data)) x vfactor | |
return ema1 * (1 + vfactor) - (ema2 * vfactor) | |
#---Calculate smoothing passed based on tcount | |
if not (tcount >= 1): | |
raise ValueError('tcount must be 1 or more. Default = 3 to T3 calucation.') | |
elif tcount >= 1: | |
gd = generalisedDEMA(period,data,vfactor) | |
if tcount >1: | |
for i in range(tcount-1): | |
gd = generalisedDEMA(period,gd,vfactor) | |
return gd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment