Esempio n. 1
0
def test_applyFeatures():
    dData = datautil.get_data0()
    ldfFeatures = ftu.applyFeatures(dData, [featMA], [{'lLookback':2}])
    print ldfFeatures
    ldfFeatures = ftu.stackSyms(ldfFeatures)
    print ldfFeatures
    ftu.normFeatures(ldfFeatures,-1,1,False)
        ''' Plot feature for XOM '''
        for i, fcFunc in enumerate(lfcFeatures[:-1]):
            plt.clf()
            plt.subplot(211)
            plt.title( fcFunc.__name__ )
            plt.plot( dfPrice.index, dfPrice['XOM'].values, 'r-' )
            plt.subplot(212)
            plt.plot( dfPrice.index, ldfFeatures[i]['XOM'].values, 'g-' )
            plt.show()
     
    ''' Pick Test and Training Points '''
    lSplit = int(len(ldtTimestamps) * 0.7)
    dtStartTrain = ldtTimestamps[0]
    dtEndTrain = ldtTimestamps[lSplit]
    dtStartTest = ldtTimestamps[lSplit+1]
    dtEndTest = ldtTimestamps[-1]
     
    ''' Stack all information into one Numpy array ''' 
    naFeatTrain = ftu.stackSyms( ldfFeatures, dtStartTrain, dtEndTrain )
    naFeatTest = ftu.stackSyms( ldfFeatures, dtStartTest, dtEndTest )
    
    ''' Normalize features, use same normalization factors for testing data as training data '''
    ltWeights = ftu.normFeatures( naFeatTrain, -1.0, 1.0, False )
    ''' Normalize query points with same weights that come from test data '''
    ftu.normQuery( naFeatTest[:,:-1], ltWeights )

    learnerTest( naFeatTrain, naFeatTest )
    
    
    
Esempio n. 3
0
               {}]
    ''' Generate a list of DataFrames, one for each feature, with the same index/column structure as price data '''
    ldfFeatures = ftu.applyFeatures(dData, lfcFeatures, ldArgs)

    bPlot = False
    if bPlot:
        ''' Plot feature for XOM '''
        for i, fcFunc in enumerate(lfcFeatures[:-1]):
            plt.clf()
            plt.subplot(211)
            plt.title(fcFunc.__name__)
            plt.plot(dfPrice.index, dfPrice['XOM'].values, 'r-')
            plt.subplot(212)
            plt.plot(dfPrice.index, ldfFeatures[i]['XOM'].values, 'g-')
            plt.show()
    ''' Pick Test and Training Points '''
    lSplit = int(len(ldtTimestamps) * 0.7)
    dtStartTrain = ldtTimestamps[0]
    dtEndTrain = ldtTimestamps[lSplit]
    dtStartTest = ldtTimestamps[lSplit + 1]
    dtEndTest = ldtTimestamps[-1]
    ''' Stack all information into one Numpy array '''
    naFeatTrain = ftu.stackSyms(ldfFeatures, dtStartTrain, dtEndTrain)
    naFeatTest = ftu.stackSyms(ldfFeatures, dtStartTest, dtEndTest)
    ''' Normalize features, use same normalization factors for testing data as training data '''
    ltWeights = ftu.normFeatures(naFeatTrain, -1.0, 1.0, False)
    ''' Normalize query points with same weights that come from test data '''
    ftu.normQuery(naFeatTest[:, :-1], ltWeights)

    learnerTest(naFeatTrain, naFeatTest)