def runStrategy(in_prices): global prices, ps log.debug('beginning fma strategy ...') prices = in_prices ps = [p['close'] for p in prices] #12_0.15_SMA_31_EMA_56_SMA_160__0__0,93,93,1558,25166.84 #12_0.15_SMA_25_LWMA_48_SMA_160__0__0,105,97,1987,25156.73 #12_0.15_SMA_30_EMA_58_SMA_160__0__0,96,95,1558,24957.8 #36_0.15_SMA_31_EMA_56_SMA_160__0__0,92,87,1935,23762.4 #24_0.2_SMA_37_LWMA_64_SMA_140__0__0,92,86,1452,24911.19 #12_0.15__0__0_SMA_35_SMA_78_SMA_120,75,69,4941,24376.28 #12_0.15__0__0_MA_30_SMA_78_SMA_100,93,83,4376,24252.22 #12_0.15__0__0_SMA_35_SMA_72_SMA_120,77,71,4930,24391.03 #12_0.15__0__0_SMA_39_SMA_72_SMA_120,77,70,4946,24365.99 #36_0.15__0__0_EMA_17_LWMA_24_SMA_150,276,282,3205,24670.78 #24_0.2__0__0_SMA_9_MA_16_SMA_170,216,219,3667,24692.56 pool = Pool(10) doTrade(pool, 12, 0.15, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'SMA', 35, 'SMA', 78, 'SMA', 120) doTrade(pool, 12, 0.15, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 78, 'SMA', 100) doTrade(pool, 12, 0.15, 'SMA', 31, 'EMA', 56, 'SMA', 160, 'SMA', 35, 'SMA', 72, 'SMA', 120) doTrade(pool, 12, 0.15, 'SMA', 31, 'EMA', 56, 'SMA', 160, 'MA', 30, 'SMA', 78, 'SMA', 100) doTrade(pool, 36, 0.15, 'SMA', 31, 'EMA', 56, 'SMA', 160, 'EMA', 17, 'LWMA', 24, 'SMA', 150) doTrade(pool, 24, 0.2, 'SMA', 37, 'LWMA', 64, 'SMA', 140, 'SMA', 9, 'MA', 16, 'SMA', 170) pool.showStrategies() return
def runStrategy(in_prices): global prices, ps log.debug("beginning fma strategy ...") prices = in_prices ps = [p["close"] for p in prices] # 20_1.0_LWMA_10_EMA_24_EMA_25__0__0,20,23,533,36486.0 # 20_1.0__0__0_MA_6_MA_36_MA_37,18,18,354,30755.0 pool = Pool(10) doTrade(pool, 20, 1.0, "LWMA", 10, "EMA", 24, "EMA", 25, "MA", 6, "MA", 36, "MA", 37) # doTrade(pool, 25, 1.3, 'LWMA', 10, 'EMA', 24, 'EMA', 25, 'MA', 6, 'MA', 36, 'MA', 37) doTrade(pool, 25, 1.3, "MA", 7, "SMA", 13, "EMA", 31, "SMA", 7, "MA", 12, "MA", 13) pool.showStrategies() return
def runStrategy(in_prices): global prices, ps log.debug('beginning fma strategy ...') prices = in_prices ps = [p['close'] for p in prices] #20_1.0_LWMA_10_EMA_24_EMA_25__0__0,20,23,533,36486.0 #20_1.0__0__0_MA_6_MA_36_MA_37,18,18,354,30755.0 pool = Pool(10) doTrade(pool, 20, 1.0, 'LWMA', 10, 'EMA', 24, 'EMA', 25, 'MA', 6, 'MA', 36, 'MA', 37) #doTrade(pool, 25, 1.3, 'LWMA', 10, 'EMA', 24, 'EMA', 25, 'MA', 6, 'MA', 36, 'MA', 37) doTrade(pool, 25, 1.3, 'MA', 7, 'SMA', 13, 'EMA', 31, 'SMA', 7, 'MA', 12, 'MA', 13) pool.showStrategies() return
def runStrategy(in_prices): global mas, emas, smas, lwmas, std, prices log.debug('beginning ma strategy ...') prices = in_prices ps = [p['close'] for p in prices] std = [0] * 51 l = len(prices) for period in range(2, 51): std[period] = [0] * l for i in range(period - 1, l): std[period][i] = np.std(ps[i-period+1 : i+1], dtype=np.float64, ddof=0) mas = [0] * 81 emas = [0] * 81 smas = [0] * 81 lwmas = [0] * 81 for period in range(2, 81): mas[period] = ma.calc_ma(ps, period) emas[period] = ma.calc_ema(ps, period) smas[period] = ma.calc_sma(ps, period) lwmas[period] = ma.calc_lwma(ps, period) pool = Pool(100) #t = doTrade(pool, 25, 1.0, 'MA', 7, 'SMA', 12, 'EMA', 31, 'SMA', 7, 'MA', 12, 'MA', 13) #t = doTrade(pool, 25, 1.3, 'MA', 7, 'SMA', 13, 'EMA', 31, 'SMA', 7, 'MA', 12, 'MA', 13) #pool.showStrategies() #return log.debug('running ma strategy ...') starttime = datetime.datetime.now() matypes = ['MA', 'EMA', 'SMA', 'LWMA'] farr = range(5, 20) s1arr = range(8, 40) s2arr = range(0, 80) poola = Pool(10) poolb = Pool(10) for stdPeriod in [20, ]: for stdGuage in [1.0, ]: log.debug('*** ' + str(stdPeriod) + ',' + str(stdGuage) + ' ***') for ft, f in [(matype, period) for matype in matypes for period in farr]: for s1t, s1 in [(matype, period) for matype in matypes for period in s1arr]: if s1 != 0 and s1 <= f: continue elapsed = (datetime.datetime.now() - starttime).seconds log.debug('== ' + str(elapsed) + ',' + ft + '_' + str(f) + ',' + s1t + '_' + str(s1) + ' ==') for s2t, s2 in [(matype, period) for matype in matypes for period in s2arr]: if s2 != 0 and s2 <= s1: continue if s2 == 0 and (s2t == 'EMA' or s2t == 'SMA' or s2t == 'LWMA'): continue doTrade(poola, stdPeriod, stdGuage, ft, f, s1t, s1, s2t, s2, '', 0, '', 0, '', 0) doTrade(poolb, stdPeriod, stdGuage, '', 0, '', 0, '', 0, ft, f, s1t, s1, s2t, s2) poola.showStrategies() poolb.showStrategies()
def runStrategy(in_prices): global mas, emas, smas, lwmas, std, prices log.debug('beginning ma strategy ...') prices = in_prices ps = [p['close'] for p in prices] std = [0] * 51 l = len(prices) for period in range(2, 51): std[period] = [0] * l for i in range(period - 1, l): std[period][i] = np.std(ps[i - period + 1:i + 1], dtype=np.float64, ddof=0) malength = 181 mas = [0] * malength emas = [0] * malength smas = [0] * malength lwmas = [0] * malength for period in range(2, malength): mas[period] = ma.calc_ma(ps, period) emas[period] = ma.calc_ema(ps, period) smas[period] = ma.calc_sma(ps, period) lwmas[period] = ma.calc_lwma(ps, period) pool = Pool(10) t = doTrade(pool, 12, 0.15, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'SMA', 30, 'EMA', 58, 'SMA', 160) t = doTrade(pool, 12, 0.15, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 12, 0.15, 'SMA', 25, 'EMA', 38, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 12, 0.1, 'SMA', 25, 'EMA', 38, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 12, 0.12, 'SMA', 25, 'EMA', 38, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 20, 0.15, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 20, 0.1, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 20, 0.12, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 40, 0.15, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 40, 0.1, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) t = doTrade(pool, 40, 0.12, 'SMA', 25, 'LWMA', 48, 'SMA', 160, 'MA', 30, 'SMA', 68, 'SMA', 100) #t = doTrade(pool, 25, 1.3, 'MA', 7, 'SMA', 13, 'EMA', 31, 'SMA', 7, 'MA', 12, 'MA', 13) pool.showStrategies() return log.debug('running ma strategy ...') starttime = datetime.datetime.now() matypes = ['MA', 'EMA', 'SMA', 'LWMA'] farr = range(5, 40) s1arr = range(8, 80) s2arr = range(0, 180) poola = Pool(10) poolb = Pool(10) for stdPeriod in [ 12, ]: for stdGuage in [ 0.15, ]: log.debug('*** ' + str(stdPeriod) + ',' + str(stdGuage) + ' ***') for ft, f in [(matype, period) for matype in matypes for period in farr]: for s1t, s1 in [(matype, period) for matype in matypes for period in s1arr]: if s1 != 0 and s1 <= f: continue elapsed = (datetime.datetime.now() - starttime).seconds log.debug('== ' + str(elapsed) + ',' + ft + '_' + str(f) + ',' + s1t + '_' + str(s1) + ' ==') for s2t, s2 in [(matype, period) for matype in matypes for period in s2arr]: if s2 != 0 and s2 <= s1: continue if s2 == 0 and (s2t == 'EMA' or s2t == 'SMA' or s2t == 'LWMA'): continue doTrade(poola, stdPeriod, stdGuage, ft, f, s1t, s1, s2t, s2, '', 0, '', 0, '', 0) doTrade(poolb, stdPeriod, stdGuage, '', 0, '', 0, '', 0, ft, f, s1t, s1, s2t, s2) poola.showStrategies() poolb.showStrategies()