コード例 #1
0
ファイル: l2voter.py プロジェクト: 547872495/pymisc
def genMaOps(ps, ft, f, st, s):
	
	if ft == 'MA':
		fma = ma.calc_ma(ps, f)
	elif ft == 'EMA':
		fma = ma.calc_ema(ps, f)
	elif ft == 'SMA':
		fma = ma.calc_sma(ps, f)
	elif ft == 'LWMA':
		fma = ma.calc_lwma(ps, f)
		
	if st == 'MA':
		sma = ma.calc_ma(ps, s)
	elif st == 'EMA':
		sma = ma.calc_ema(ps, s)
	elif st == 'SMA':
		sma = ma.calc_sma(ps, s)
	elif st == 'LWMA':
		sma = ma.calc_lwma(ps, s)
		
	
	l = len(ps)
	ops = [0] * l
	for i in range(s, l):
		diff = fma[i] - sma[i]
		if diff > 0:
			ops[i] = 1
		elif diff < 0:
			ops[i] = -1
			
	return ops
	
コード例 #2
0
ファイル: maStrategy.py プロジェクト: 547872495/pymisc
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()
コード例 #3
0
ファイル: fmaStrategy.py プロジェクト: 547872495/pymisc
def getMas(matype, period):
	if matype == 'MA':
		return ma.calc_ma(ps, period)
	elif matype == 'EMA':
		return ma.calc_ema(ps, period)
	elif matype == 'SMA':
		return ma.calc_sma(ps, period)
	elif matype == 'LWMA':
		return ma.calc_lwma(ps, period)
	else:
		return None
コード例 #4
0
ファイル: fmaStrategy.py プロジェクト: ongbe/pymisc
def getMas(matype, period):
    if matype == "MA":
        return ma.calc_ma(ps, period)
    elif matype == "EMA":
        return ma.calc_ema(ps, period)
    elif matype == "SMA":
        return ma.calc_sma(ps, period)
    elif matype == "LWMA":
        return ma.calc_lwma(ps, period)
    else:
        return None
コード例 #5
0
ファイル: masVoter.py プロジェクト: 547872495/pymisc
def runVoter(in_prices):
	global mas, emas, smas, lwmas, prices
	log.debug('beginning ma voter ...')
	
	prices = in_prices
	ps = [p['close'] for p in prices]
	
	malength = 101
	mas = [0] * malength
	emas = [0] * malength
	smas = [0] * malength
	lwmas = [0] * malength
	for period in range(2, malength):
		if period % 30 == 0: print period
		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)
	
	
	log.debug('running ma voter ...')
	starttime = time.time() 
	matypes = ['MA', 'EMA', 'SMA', 'LWMA']
	
	pool = VoterPool(1, prices)
	#calcTickets(pool, 'SMA', 95, 'LWMA', 240)
	#calcTickets(pool, 'SMA', 3, 'EMA', 4)
	#calcTickets(pool, 'MA', 7, 'SMA', 13)
	#pool.showVoters()
	#return
	
	
	farr = range(5, 30)[::3]
	sarr = range(10, 100)[::5]
	
	for ft, f in [(matype, period) for matype in matypes for period in farr]:
		elapsed = long(time.time() - starttime)
		log.debug('== ' + str(elapsed) + ',' + ft + '_' + str(f) + ' ==')
		for st, s in [(matype, period) for matype in matypes for period in sarr]:
			if s < f: continue
			calcTickets(pool, ft, f, st, s)
	
	pool.showVoters()
コード例 #6
0
ファイル: maVoter.py プロジェクト: 547872495/pymisc
def runVoter(in_prices):
	global mas, emas, smas, lwmas, prices
	log.debug('beginning ma voter ...')
	
	prices = in_prices
	ps = [p['close'] for p in prices]
	
	mas = [0] * 61
	emas = [0] * 61
	smas = [0] * 61
	lwmas = [0] * 61
	for period in range(2, 61):
		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)
	
	
	log.debug('running ma voter ...')
	starttime = time.time() 
	matypes = ['MA', 'EMA', 'SMA', 'LWMA']
	
	pool = VoterPool(2, prices)
	#calcTickets(pool, 'MA', 7, 'EMA', 18)
	#calcTickets(pool, 'SMA', 3, 'EMA', 4)
	#calcTickets(pool, 'MA', 7, 'SMA', 13)
	#pool.showVoters()
	#return
	
	
	farr = range(2, 10)
	sarr = range(4, 60)
	
	for ft, f in [(matype, period) for matype in matypes for period in farr]:
		elapsed = long(time.time() - starttime)
		#log.debug('== ' + str(elapsed) + ',' + ft + '_' + str(f) + ' ==')
		for st, s in [(matype, period) for matype in matypes for period in sarr]:
			if s < f: continue
			calcTickets(pool, ft, f, st, s)
	
	pool.showVoters()
コード例 #7
0
ファイル: maTrader.py プロジェクト: 547872495/pymisc
def runStrategy(in_prices):
	global mas, emas, smas, lwmas, prices
	log.debug('beginning ma strategy ...')
	
	prices = in_prices
	ps = [p['close'] for p in prices]
	
	log.debug('generating mas ...')
	mas = [0] * 61
	emas = [0] * 61
	smas = [0] * 61
	lwmas = [0] * 61
	for period in range(2, 61):
		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 = StrategyPool(20)
	doMaTrade(pool, 'SMA', 19, 'MA', 40, 'LWMA', 60)
	pool.showStrategies()
	return
	
	log.debug('running ma strategy ...')
	starttime = datetime.datetime.now() 
	matypes = ['MA', 'EMA', 'SMA', 'LWMA']
	pool = StrategyPool(100)
	
	for ft, f in [(matype, period) for matype in matypes for period in range(2, 10)]:
		for s1t, s1 in [(matype, period) for matype in matypes for period in range(4, 21)]:
			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 range(0, 41)]:
				if s2 != 0 and s2 <= s1: continue
				if s2 == 0 and (s2t == 'EMA' or s2t == 'SMA' or s2t == 'LWMA'): continue
				doMaTrade(pool, ft, f, s1t, s1, s2t, s2)
	
	pool.showStrategies()
コード例 #8
0
ファイル: n2Trader.py プロジェクト: 547872495/pymisc
def runStrategy(in_prices):
	global mas, emas, smas, lwmas, std, prices
	log.debug('beginning one strategy ...')
	
	prices = in_prices
	ps = [p['close'] for p in prices]
	
	std = [0] * 51
	l = len(prices)
	for period in range(20, 21):
		std[period] = [0] * l
		for i in range(period - 1, l):
			std[period][i] = round(np.std(ps[i-period+1 : i+1], dtype=np.float64, ddof=0), 3)
	
	mas = [0] * 181
	emas = [0] * 181
	smas = [0] * 181
	lwmas = [0] * 181
	for period in range(2, 181):
		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 = StrategyPool(100)
	#t = doTrade(pool, 20, 0.1, 0.2, 'SMA', 20, 'SMA', 34, 'LWMA', 40, 'SMA', 20, 'SMA', 34, 'LWMA', 120)
	#pool.showStrategies()
	#return 
	
	log.debug('running first strategy ...')
	starttime = time.time() 
	matypes = ['MA', 'EMA', 'SMA', 'LWMA']
	
	#farr = [2, 3, 4, 5, 6, 7, ]
	#s1arr = [4, 6, 8, 10, 12, 14, 16, 18, 20, ]
	#s2arr = [0, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, ]
	#farr = [20,]
	#s1arr = [40, ]
	#s2arr = [0, ]
	farr = range(40, 41)[::3]
	s1arr = range(4, 121)[::6]
	s2arr = range(0, 181)[::15]
	
	stdGuage1, stdGuage2 = 0.1, 0.2
	pool = StrategyPool(50)
	poola = StrategyPool(10)
	poolb = StrategyPool(10)
	
	for stdPeriod in [20, ]:
		for no in ['A', 'B', ]:
			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 < f: continue
					elapsed = long(time.time() - starttime)
					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
						if no == 'A':
							doTrade(poola, stdPeriod, stdGuage1, stdGuage2, ft, f, s1t, s1, s2t, s2, '', 0, '', 0, '', 0)
						elif no == 'B':
							doTrade(poolb, stdPeriod, stdGuage1, stdGuage2, '', 0, '', 0, '', 0, ft, f, s1t, s1, s2t, s2)
			elapsed = long(time.time() - starttime)
			log.info('find ' + no + ' time: ' + str(elapsed) + ' ')
		
		for i in range(10):
			sa = poola.strategies[i]
			sb = poolb.strategies[i]
			t = doTrade(pool, stdPeriod, stdGuage1, stdGuage2, sa[0].args[0], sa[0].args[1], sa[0].args[2], sa[0].args[3], sa[0].args[4], sa[0].args[5], sb[0].args[6], sb[0].args[7], sb[0].args[8], sb[0].args[9], sb[0].args[10], sb[0].args[11])
			#t.generateGraph()
	
	pool.showStrategies()