def Xindicator(self, syms, dates): sma = ind.SMA(syms, 20, dates) bb = ind.BB(syms, 20, 2, dates) _, macd = ind.MACD(syms, 12, 26, 9, dates) rsi = ind.RSI(syms, 14, dates) X = pd.DataFrame({'SMA': sma, 'BB': bb, "MACD": macd, "RSI": rsi}) return X
def calculate_thres(): symbol = 'JPM' sd=dt.datetime(2008,1,1) ed=dt.datetime(2009,12,31) date = pd.date_range(sd - dt.timedelta(days=50), ed) stockvals = get_data([symbol], date) stockvals = stockvals.loc[:, [symbol]] sma = ind.SMA(symbol, 20, date, gen_plot = False) sma = sma[sma.index >= sd] bb = ind.BB(symbol, 20, 2, date, gen_plot = False) bb = bb[bb.index >= sd] _, macd = ind.MACD(symbol, 12, 26, 9, date, gen_plot = False) macd = macd[macd.index >= sd] rsi = ind.RSI(symbol, 14, date, gen_plot = False) rsi = rsi[rsi.index >= sd] bounds = [(0, 1), (60, 85), (15,40)] optimal_thres = differential_evolution(optimalize, bounds, args=(sma, bb, macd, rsi, )) return(optimal_thres)
def testPolicy(symbol = 'JPM', sd=dt.datetime(2008,1,1), ed=dt.datetime(2009,12,31), sv = 100000): date = pd.date_range(sd - dt.timedelta(days=50), ed) stockvals = get_data([symbol], date) stockvals = stockvals.loc[:, [symbol]] sma = ind.SMA(symbol, 20, date, gen_plot = False) sma = sma[sma.index >= sd] bb = ind.BB(symbol, 20, 2, date, gen_plot = False) bb = bb[bb.index >= sd] _, macd = ind.MACD(symbol, 12, 26, 9, date, gen_plot = False) macd = macd[macd.index >= sd] rsi = ind.RSI(symbol, 14, date, gen_plot = False) rsi = rsi[rsi.index >= sd] thres = [0.99243522, 84.70103144, 25.01519814] """ from calculate_thres """ order_signal = signal(sma, bb, macd, rsi, thres) order = Order(order_signal) return order