Beispiel #1
0
    def __init__(self, barDataSeries, period, dSMAPeriod=3, useAdjustedValues=False, maxLen=None):
        assert dSMAPeriod > 1, "dSMAPeriod must be > 1"
        assert isinstance(barDataSeries, bards.BarDataSeries), \
            "barDataSeries must be a dataseries.bards.BarDataSeries instance"

        super(StochasticOscillator, self).__init__(barDataSeries, SOEventWindow(period, useAdjustedValues), maxLen)
        self.__d = ma.SMA(self, dSMAPeriod, maxLen)
Beispiel #2
0
 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)
Beispiel #3
0
from dmwTrader import dataseries

close = numpy.random.random(100)
print(close)
print()

# talib
start1 = time.time()
output1 = talib.SMA(close, 30)
end1 = time.time()
# print(output1)

# dmwTrader
start2 = time.time()
seqDS = dataseries.SequenceDataSeries()
output2 = ma.SMA(seqDS, 30)
for ele in close:
    seqDS.append(ele)
    # print(output2[-1])
end2 = time.time()

# 检查是否一致
# for i in range(100):
#     if numpy.isnan(output1[i]) and output2[i] is None:
#         print('neither')
#     elif not numpy.isnan(output1[i]) and output2[i] is not None:
#         print(round(output1[i] - output2[i], 10))
#     else:
#         print("error")

print("talib time: " + str(end1 - start1))
Beispiel #4
0
 def __init__(self, feed, instrument, smaPeriod):
     super(MyStrategy, self).__init__(feed)
     self.__position = None
     self.__instrument = instrument
     # 将sma与bar的收盘价绑定,拿收盘价作sma
     self.__sma = ma.SMA(feed[instrument].getPriceDataSeries(), smaPeriod)
Beispiel #5
0
 def __init__(self, feed, instrument):
     super(myStrategy, self).__init__(feed, 100000)
     self.__position = None
     self.__instrument = instrument
     self.__sma5 = ma.SMA(feed[instrument].getPriceDataSeries(), 5)
     self.__sma30 = ma.SMA(feed[instrument].getPriceDataSeries(), 30)