def init(self, instrumentId): # let's fetch ten days of hourly history. endDate = date.today().strftime('%Y%m%d') startDate = (date.today() - timedelta(days=10)).strftime('%Y%m%d') self.candles[instrumentId] = onlinearchive.history(instrumentId, 'HOURS_1', startDate, endDate) print 'Fetched ', len(self.candles[instrumentId]), ' candles from history archive.' return
def init(self, instrumentId): # let's fetch ten days of hourly history. endDate = date.today().strftime('%Y%m%d') startDate = (date.today() - timedelta(days=10)).strftime('%Y%m%d') self.candles[instrumentId] = onlinearchive.history( instrumentId, 'HOURS_1', startDate, endDate) print 'Fetched ', len( self.candles[instrumentId]), ' candles from history archive.' return
def init(self, instrumentId): self.logger.info('Initializing ' + instrumentId) # let's fetch ten days of hourly history. endDate = date.today().strftime('%Y%m%d') startDate = (date.today() - timedelta(days=10)).strftime('%Y%m%d') self.candlesHourly[instrumentId] = onlinearchive.history(instrumentId, 'HOURS_1', startDate, endDate) length = len(self.candlesHourly[instrumentId]) lastClose = self.candlesHourly[instrumentId]['C'][length - 1] tradingRange = self.calculateTradingRange(self.candlesHourly[instrumentId][length - 10:length]) # let's store the current price range for later reuse. self.currentPriceRanges[instrumentId] = tradingRange self.upperBoundaries[instrumentId] = lastClose + tradingRange self.lowerBoundaries[instrumentId] = lastClose - tradingRange print 'Fetched ', len(self.candlesHourly[instrumentId]), ' candles from history archive.' return
def init(self, instrumentId): self.logger.info('Initializing ' + instrumentId) # let's fetch ten days of hourly history. endDate = date.today().strftime('%Y%m%d') startDate = (date.today() - timedelta(days=10)).strftime('%Y%m%d') self.candlesHourly[instrumentId] = onlinearchive.history( instrumentId, 'HOURS_1', startDate, endDate) length = len(self.candlesHourly[instrumentId]) lastClose = self.candlesHourly[instrumentId]['C'][length - 1] tradingRange = self.calculateTradingRange( self.candlesHourly[instrumentId][length - 10:length]) # let's store the current price range for later reuse. self.currentPriceRanges[instrumentId] = tradingRange self.upperBoundaries[instrumentId] = lastClose + tradingRange self.lowerBoundaries[instrumentId] = lastClose - tradingRange print 'Fetched ', len( self.candlesHourly[instrumentId]), ' candles from history archive.' return
import os import sys from aq.util import onlinearchive import pybacktest import matplotlib.pyplot as plt import pandas from pandas import Series, ewma, concat, DataFrame import matplotlib.pyplot as plt # h = onlinearchive.history('EURUSD','HOURS_1',20130615,20130701) eurusd = onlinearchive.history('EURUSD', 'HOURS_1', 20130501, 20130701) # usdchf = onlinearchive.history2('CNX.MDI.EUR/GBP','HOURS_1',20120801,20130701) # eurusd.plot() # usdchf.plot() # plt.show() slowEma1 = DataFrame(ewma(eurusd.ix[:, 3], span=20)) fastEma1 = DataFrame(ewma(eurusd.ix[:, 3], span=50)) emaDiff = (fastEma1 - slowEma1) * 1000000 emaDiff = emaDiff.astype(int) # signal = (((fastEma1 - slowEma1) > 0) * 2 - 1) signal = emaDiff.shift(1).ix[:, 0] closeDiff = eurusd.ix[:, 3].diff()