예제 #1
0
    def getMinDate(self, historyData):
        df = historyData.copy()

        ########
        from avera.mods.VSASpread import VSASpread
        from avera.mods.HeikenAshiMod import HeikenAshiMod
        from avera.mods.EnergyMod import EnergyMod
        historyMod = VSASpread()
        df = historyMod.modHistory(df)
        historyMod = HeikenAshiMod()
        df = historyMod.modHistory(df)
        historyMod = EnergyMod()
        df = historyMod.modHistory(df,
                                   featList=["open", "close", "low", "high"])
        ########

        for i in range(self.nDiffs):
            for feat in self.featureList:
                notShifted = df[feat]
                shiftedData = df[feat].shift(periods=1)
                df[feat] = notShifted - shiftedData
            iter = next(df.iterrows())
            df = df.drop(iter[0])
        iter = df.iterrows()
        obs = next(iter)
        #acceleration
        #for i in range(self.nPoints + self.nPoints):
        #
        for i in range(self.nPoints - 1):
            obs = next(iter)

        return obs[0]
예제 #2
0
    def getManyPointsFeat(self, datetimeStr, historyData):

        obsList = None
        if self.fitMode:
            obsList = self.fitData.loc[:str(datetimeStr)].tail(
                self.nPoints).copy()
        else:
            df = historyData.copy()

            ########
            df = df[:str(datetimeStr)].tail(500)
            from avera.mods.VSASpread import VSASpread
            from avera.mods.HeikenAshiMod import HeikenAshiMod
            from avera.mods.EnergyMod import EnergyMod
            historyMod = VSASpread()
            df = historyMod.modHistory(df)
            historyMod = HeikenAshiMod()
            df = historyMod.modHistory(df)
            historyMod = EnergyMod()
            df = historyMod.modHistory(
                df, featList=["open", "close", "low", "high"])
            ########

            for i in range(self.nDiffs):
                for feat in self.featureList:
                    notShifted = df[feat]
                    shiftedData = df[feat].shift(periods=1)
                    df[feat] = notShifted - shiftedData
                iter = next(df.iterrows())
                df = df.drop(iter[0])

            obsList = df.loc[:str(datetimeStr)].tail(self.nPoints).copy()

            obsListTransformed = {}
            for obs in obsList.iterrows():
                for feat in self.featureList:
                    data = obs[1][feat]
                    data = data.reshape(-1, 1)
                    data = self.scalerDict[feat].transform(data)
                    obs[1][feat] = data
                obsListTransformed[obs[0]] = obs[1]
            obsList = pd.DataFrame(obsListTransformed.values(),
                                   index=list(obsListTransformed.keys()))

        obs = []
        if self.flatStack:
            localObs = np.zeros((self.nPoints, ))
            # for feat in self.featureList:
            #    localObs = np.vstack([localObs, vectorPrices[feat]])
            # obs = np.array(localObs[1:])
        else:
            localObs = np.zeros((self.nPoints, ))
            for feat in self.featureList:
                localObs = np.vstack([localObs, obsList[feat].values])
            obs.append(localObs[1:])
        obs = np.array(obs)

        obs = np.reshape(obs, (obs.shape[1], obs.shape[2], 1))

        return obs
예제 #3
0
def preprocData(df):
    historyMod = VSASpread()
    modDf = historyMod.modHistory(df)
    historyMod = HeikenAshiMod()
    modDf = historyMod.modHistory(modDf)
    historyMod = EnergyMod()
    modDf = historyMod.modHistory(modDf, featList=["open", "close", "low", "high"])
    return modDf
예제 #4
0
def createGenerators(df, priceFeatList):
    ########
    historyMod = VSASpread()
    df = historyMod.modHistory(df)
    historyMod = HeikenAshiMod()
    df = historyMod.modHistory(df)
    historyMod = EnergyMod()
    df = historyMod.modHistory(df, featList=["open", "close", "low", "high"])
    ########

    priceDiffGenerator = MultiScalerDiffGenerator(featureList=priceFeatList, nDiffs=1, nPoints=32, flatStack=False,fitOnStep=False)
    priceDiffGenerator.setFitMode(True)
    priceDiffGenerator = priceDiffGenerator.globalFit(df)
    priceDiffGenerator.saveGenerator("./MSDiffGen.pkl")

    pass
예제 #5
0
hkFeatList = ["open", "close", "low", "high", "vsa_spread", "tick_volume",
              "hkopen", "hkclose", "enopen", "enclose", "enlow", "enhigh"]

#terminal = MT5Terminal()
dataUpdater = SymbolDataUpdater("../../data/raw/")
dataManager = SymbolDataManager("../../data/raw/")

#dataUpdater.fullUpdate(terminal, symbol, timeframe, startDate="2015-01-01 00:00:00")
df = SymbolDataManager().getData(symbol, timeframe)

########
historyMod = VSASpread()
modDf = historyMod.modHistory(df)
historyMod = HeikenAshiMod()
modDf = historyMod.modHistory(modDf)
historyMod = EnergyMod()
modDf = historyMod.modHistory(modDf, featList=["open", "close", "low", "high"])
########

genList = []
for i in range(2):
    gen = MultiScalerDiffGenerator(featureList=hkFeatList, nDiffs=i+1, nPoints = 96, flatStack = False, fitOnStep = False)
    genList.append( gen )

compositeGenerator = CompositeGenerator( genList=genList, flatStack=False)
compositeGenerator.setFitMode(True)
compositeGenerator.globalFit(modDf)
compositeGenerator.saveGenerator("./CompositeMSDiffGen.pkl")

################################
# train agent
예제 #6
0
symbol = "EURUSD_i"
timeframe = "H1"
energyFeatList = ["enopen", "enclose", "enlow", "enhigh"]
volumeFeatList = ["tick_volume"]

#terminal = MT5Terminal()
#dataUpdater = SymbolDataUpdater()
dataManager = SymbolDataManager()

#dataUpdater.fullUpdate(terminal, symbol, timeframe, startDate="2015-01-01 00:00:00")
df = SymbolDataManager().getData(symbol, timeframe)

########
#df = df.tail(1000)
print("applying energy mod...")
enMod = EnergyMod()
df = enMod.modHistory(df, ["open", "close", "low", "high"])
#enMod.checkQuality(df)
########
"""energyScaleGenerator = W2VScaleGenerator(featureList=energyFeatList, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)
energyDiffGenerator = W2VDiffGenerator(featureList=energyFeatList, nDiffs=1, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)"""
"""volumeScaleGenerator = W2VScaleGenerator(featureList=volumeFeatList, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)
volumeDiffGenerator = W2VDiffGenerator(featureList=volumeFeatList, nDiffs=1, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)"""
"""energyScaleGenerator.setFitMode(True)
energyScaleGenerator = energyScaleGenerator.globalFit(df)
#priceScaleGenerator.checkReconstructionQuality(df.head(10000))
#priceScaleGenerator.checkReconstructionQuality(df.tail(10000))
예제 #7
0
timeframe = "H1"
priceFeatList = ["open", "close", "low", "high"]
energyFeatList = ["enopen", "enclose", "enlow", "enhigh"]
volumeFeatList = ["tick_volume"]

#terminal = MT5Terminal()
#dataUpdater = SymbolDataUpdater("../../data/raw/")
dataManager = SymbolDataManager("../../data/raw/")

#dataUpdater.fullUpdate(terminal, symbol, timeframe, startDate="2015-01-01 00:00:00")
df = SymbolDataManager("../../data/raw/").getData(symbol, timeframe)

########
#df = df.tail(1000)
print("applying energy mod...")
enMod = EnergyMod()
df = enMod.modHistory(df, priceFeatList)
#enMod.checkQuality(df)
########
"""priceScaleGenerator = W2VScaleGenerator(featureList=priceFeatList, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)
priceDiffGenerator = W2VDiffGenerator(featureList=priceFeatList, nDiffs=1, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)
energyScaleGenerator = W2VScaleGenerator(featureList=energyFeatList, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)
energyDiffGenerator = W2VDiffGenerator(featureList=energyFeatList, nDiffs=1, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)
volumeScaleGenerator = W2VScaleGenerator(featureList=volumeFeatList, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)
volumeDiffGenerator = W2VDiffGenerator(featureList=volumeFeatList, nDiffs=1, nPoints = 21, flatStack = False, fitOnStep = False,
                 nIntervals = 10000, w2vSize=32, window=20, iter=100, min_count=0, sample=0.0, sg=0)