def __init__(self, dataSeries, period, numStdDev, maxLen=None): self.__sma = ma.SMA(dataSeries, period, maxLen=maxLen) self.__stdDev = stats.StdDev(dataSeries, period, maxLen=maxLen) self.__upperBand = dataseries.SequenceDataSeries(maxLen) self.__lowerBand = dataseries.SequenceDataSeries(maxLen) self.__numStdDev = numStdDev # It is important to subscribe after sma and stddev since we'll use those values. dataSeries.getNewValueEvent().subscribe(self.__onNewValue)
def __init__(self, maxLen=None): super(analyzer_skysense, self).__init__() self.__netReturns = dataseries.SequenceDataSeries(maxLen=maxLen) self.__cumReturns = dataseries.SequenceDataSeries(maxLen=maxLen) self.__benchmarkDailyReturns = dataseries.SequenceDataSeries( maxLen=maxLen) self.__benchmarkCumuReturns = dataseries.SequenceDataSeries( maxLen=maxLen) self.__benchmarkList = [] self.__dailyPeriodAnalysis = { 'Date': [], 'profit': [], 'profitratio': [] } self.__presentEquity = None self.__lastEquity = None self.__presentBenchmark = None self.__lastBenchmark = None self.__strat = None self.__totalSlippage = 0 self.__momentPrice = 0 self.__actionList = ["BUY", "BUY_TO_COVER", "SELL", "SELL_SHORT"] self.__tradesListDict = { 'type': [], 'date': [], 'price': [], 'shares': [], 'return': [], 'returnrate': [], 'instrument': [], 'position': [], 'cost': [], 'datetime': [] } self.__long = 0 self.__short = 0 self.__countTrades = 0 self.__positionsList = [] self.__dateTimeList = [] self.__equityList = [] self.__cashList = [] self.__barsList = [] self.__buyPricesList = [] self.__buySharesList = [] self.__sellShortPricesList = [] self.__sellShortSharesList = [] self.__holdingCostList = [] self.__buyPricesDict = {} self.__buySharesDict = {} self.__sellShortPricesDict = {} self.__sellShortSharesDict = {} self.__positionsListByOrder = [{}] self.__orderDatetimeList = []
def datetime_aligned(ds1, ds2, maxLen=None): """ Returns two dataseries that exhibit only those values whose datetimes are in both dataseries. :param ds1: A DataSeries instance. :type ds1: :class:`DataSeries`. :param ds2: A DataSeries instance. :type ds2: :class:`DataSeries`. :param maxLen: The maximum number of values to hold for the returned :class:`DataSeries`. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used. :type maxLen: int. """ aligned1 = dataseries.SequenceDataSeries(maxLen) aligned2 = dataseries.SequenceDataSeries(maxLen) Syncer(ds1, ds2, aligned1, aligned2) return (aligned1, aligned2)
def getBenchmarkCumuReturns(self): cumuReturns = dataseries.SequenceDataSeries(maxLen=None) dateList = self.getDateTimeList() benchmarkList = self.getBenchmarkList() assert len(dateList) == len(benchmarkList) for i in range(0, len(benchmarkList)): cumuReturns.appendWithDateTime(dateTime=dateList[i], value=(benchmarkList[i] - benchmarkList[0]) / benchmarkList[0]) return cumuReturns
def __init__(self, dataSeries, fastEMA, slowEMA, signalEMA, maxLen=None): assert (fastEMA > 0) assert (slowEMA > 0) assert (fastEMA < slowEMA) assert (signalEMA > 0) super(MACD, self).__init__(maxLen) # We need to skip some values when calculating the fast EMA in order for both EMA # to calculate their first values at the same time. # I'M FORCING THIS BEHAVIOUR ONLY TO MAKE THIS FITLER MATCH TA-Lib MACD VALUES. self.__fastEMASkip = slowEMA - fastEMA self.__fastEMAWindow = ma.EMAEventWindow(fastEMA) self.__slowEMAWindow = ma.EMAEventWindow(slowEMA) self.__signalEMAWindow = ma.EMAEventWindow(signalEMA) self.__signal = dataseries.SequenceDataSeries(maxLen) self.__histogram = dataseries.SequenceDataSeries(maxLen) dataSeries.getNewValueEvent().subscribe(self.__onNewValue)
def __init__(self, maxLen=None): super(BarDataSeries, self).__init__(maxLen) self.__openDS = dataseries.SequenceDataSeries(maxLen) self.__closeDS = dataseries.SequenceDataSeries(maxLen) self.__highDS = dataseries.SequenceDataSeries(maxLen) self.__lowDS = dataseries.SequenceDataSeries(maxLen) self.__volumeDS = dataseries.SequenceDataSeries(maxLen) self.__adjCloseDS = dataseries.SequenceDataSeries(maxLen) self.__extraDS = {} self.__useAdjustedValues = False
def __getOrCreateExtraDS(self, name): ret = self.__extraDS.get(name) if ret is None: ret = dataseries.SequenceDataSeries(self.getMaxLen()) self.__extraDS[name] = ret return ret
def __init__(self, maxLen=None): super(Returns, self).__init__() self.__netReturns = dataseries.SequenceDataSeries(maxLen=maxLen) self.__cumReturns = dataseries.SequenceDataSeries(maxLen=maxLen)
def createDataSeries(self, key, maxLen): return dataseries.SequenceDataSeries(maxLen)