def Alligator(close): jawval=SMA(close,13) teethval=SMA(close,8) lipsval=SMA(close,5) jaw=offsetter(jawval,8) teeth=offsetter(teethval,5) lips=offsetter(lipsval,3) return jaw,teeth,lips
def ATR(close, high, low, period=14): tr = [high[0] - low[0]] for i in range(1, len(close)): tr.append( max(high[i] - low[i], abs(high[i] - close[i - 1]), abs(close[i - 1] - low[i]))) atr = SMA(tr[0:period], period) for i in range(period, len(tr)): atr.append((atr[i - 1] * (period - 1) + tr[i]) / period) return atr
def sell(open_p, close_p, low_p, high_p, volume): sell = [0] sma_close_21 = SMA(close_p, 21) sma_close_50 = SMA(close_p, 50) for i in range(1, len(close_p)): if sma_close_21[i] < sma_close_50[i] and sma_close_21[ i - 1] > sma_close_50[i - 1]: sell.append(1) else: sell.append(0) return sell
def buy(open_p, close_p, low_p, high_p, volume): buy = [0] sma_close_21 = SMA(close_p, 21) sma_close_50 = SMA(close_p, 50) for i in range(1, len(close_p)): if sma_close_21[i] > sma_close_50[i] and sma_close_21[ i - 1] <= sma_close_50[i - 1]: buy.append(1) else: buy.append(0) return buy
def EOM(high,low,volume,period=14): DM=[0] for i in range(1,len(high)): DM.append((high[i]+low[i])/2-(high[i-1]-low[i-1])/2) BR=[(v/100000000)/(h-l) for (v,h,l) in zip(volume,high,low)] EOM1=[d-b for (d,b) in zip(DM,BR)] EOM=SMA(EOM1,period) return EOM
def CCI(close, high, low, period=20): tp = [(i + j + k) / 3 for (i, j, k) in zip(close, high, low)] sma = SMA(tp, period) md = list(np.zeros(period - 1)) for i in range(period - 1, len(tp)): md.append(mad(np.array(tp[i - period + 1:i]))) cci = [(i - j) / (.015 * k) for (i, j, k) in zip(tp, sma, md)] return cci
def UI(close, period=14): HH = [] for i in range(period - 1): HH.append(max(close[0:i + 1])) for i in range(period - 1, len(close)): HH.append(max(close[i - period + 1:i + 1])) pd = [100 * (i - j) / j for (i, j) in zip(close, HH)] sa = SMA([i * i for i in pd], period) UI = [math.sqrt(i) for i in sa] return UI
def dispchart(close_p, sma_period=200, period=100): sma = SMA(close_p, sma_period) diff = [(close_p[i] - sma[i]) / close_p[i] for i in range(len(close_p))] print(len(diff)) gap = list(np.zeros(period)) gap += [sum(diff[i - period:i + 1]) for i in range(period, len(close_p))] plt.plot(np.arange(1000), gap) plt.axvline(period + sma_period, color='red') plt.axhline(0, color='black') plt.axvline(0, color='black') plt.show() return gap
def init(): global sma global Affich global nbTours global nbCase stop() Affich =dict() try: nbAgent = int(agent.get()) nbCase = int(case.get()) isTorique = int(torique.get()) nbTours = int(tours.get()) sma= SMA(nbCase, isTorique, nbAgent) update_grille() except ValueError: messagebox.showinfo("Erreur","Les valeurs saisies contiennent des erreurs")
def LRF(close, period=14): sma = SMA(close, period) m = list(np.zeros(period)) b = list(np.zeros(period)) for i in range(period, len(close)): xavg = sma[i - 1] yavg = sma[i] num = 0 dnum = 0 for j in range(period): num += (close[i - j - 1] - xavg) * (close[i - j] - yavg) dnum += (close[i - j - 1] - xavg) * (close[i - j - 1] - xavg) m.append(num / dnum) b.append(yavg - m[i] * xavg) pred = [0] pred = [i * j + k for (i, j, k) in zip(close[1:], m[1:], b[1:])] return pred
from SMA import SMA from View import View import time GRIDSIZEX = 10 GRIDSIZEY = 10 PARTICLENB = 10 TICKSNB = 10000 TOR = False v = View() sysma = SMA(GRIDSIZEX, GRIDSIZEY, 0, TICKSNB, PARTICLENB, TOR, v) v.drawWidgets(sysma.env) sysma.run() v.update() time.sleep(1)
def AO(high, low): day_avgs = [(i + j) / 2 for (i, j) in zip(high, low)] sma5 = SMA(day_avgs, 5) sma34 = SMA(day_avgs, 34) AO = [i - j for (i, j) in zip(sma5, sma34)] return AO
from Wall import Wall ############### recuperation arguments #################### tailleX = int(sys.argv[1]) tailleY = int(sys.argv[2]) tailleCase = int(sys.argv[3]) ralentisseur = int(sys.argv[4]) nbHunter = int(sys.argv[5]) nbHunted = int(sys.argv[6]) nbWall = int(sys.argv[7]) nbTours = 1000 fenetre = Tk() environnement = Environment(tailleX, tailleY, False) ############### lancement de la simulation ################## sma = SMA(environnement, True) for i in range(0, nbHunter + nbHunted + nbWall): x = choice(range(tailleX)) y = choice(range(tailleY)) while(not sma.isFree(x,y)): x=choice(range(tailleX)) y=choice(range(tailleY)) if(nbHunter > 0): sma.addAgent(Hunter(x, y)) nbHunter -= 1 elif(nbHunted > 0): sma.addAgent(Hunted(x, y)) nbHunted -= 1 else:
from Graphic import Graphic import matplotlib.pyplot as plt ############### recuperation arguments #################### tailleX = int(sys.argv[1]) tailleY = int(sys.argv[2]) tailleCase = int(sys.argv[3]) ralentisseur = int(sys.argv[4]) nbBille = int(sys.argv[5]) torique = ("True" == str(sys.argv[6])) nbTours = 1000 fenetre = Tk() environnement = Environment(tailleX, tailleY, torique) ############### lancement de la simulation ################## sma = SMA(environnement, False) for i in range(0, nbBille): x = choice(range(tailleX)) y = choice(range(tailleY)) while(not sma.isFree(x,y)): x=choice(range(tailleX)) y=choice(range(tailleY)) if(i%10 == 0): sma.addAgent(Shark(x,y)) else: sma.addAgent(Tuna(x,y)) #sma.addAgent(Tuna(x, y, pasX, pasY))
def DPO(close, period=14): sma = SMA(close, period) shift = int(period / 2) + 1 DPO = [i - j for (i, j) in zip(close[:-shift], sma[shift:])] return DPO
def STARC(close, high, low, period=15, maperiod=5, multiplier=1.33): ma = SMA(close, maperiod) atr = ATR(close, high, low, period) upperband = [i + j * multiplier for (i, j) in zip(ma, atr)] lowerband = [i - j * multiplier for (i, j) in zip(ma, atr)] return upperband, lowerband
def DI(close, period=14): DI = list(np.zeros(period - 1)) sma = SMA(close, period) DI += [(i - j) * 100 / j for (i, j) in zip(close[period - 1:], sma[period - 1:])] return DI
############### recuperation arguments #################### tailleX = int(sys.argv[1]) tailleY = int(sys.argv[2]) tailleCase = int(sys.argv[3]) ralentisseur = int(sys.argv[4]) nbBille = int(sys.argv[5]) torique = ("True" == str(sys.argv[6])) nbTours = 1000 fenetre = Tk() environnement = Environment(tailleX, tailleY, torique) ############### lancement de la simulation ################## sma = SMA(environnement, False) for i in range(0, nbBille): x = choice(range(tailleX)) y = choice(range(tailleY)) pasX = 0 pasY = 0 while(not sma.isFree(x,y)): x=choice(range(tailleX)) y=choice(range(tailleY)) pasX = choice([-1,0,1]) # on ne veux pas de bille immobille alors: if(pasX == 0): pasY = choice([-1,1]) else: pasY = choice([-1,0,1])