Exemple #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)
    ldfData = norObj.get_data( ldtTimestamps, lsSym, lsKeys )
    dData = dict(zip(lsKeys, ldfData))
    
    ''' Imported functions from qstkfeat.features, NOTE: last function is classification '''
    lfcFeatures = [ featMA, featRSI, class_fut_ret ]

    ''' Default Arguments '''
    #ldArgs = [{}] * len(lfcFeatures) 
    
    ''' Custom Arguments '''
    ldArgs = [ {'lLookback':30, 'bRel':True},\
               {},\
               {}]                    
    
    ''' 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 '''
Exemple #3
0

from QSTK.qstkfeat.classes import class_fut_ret
import QSTK.qstkfeat.featutil as ftu	
	
import sys
import time

from functions import *

if __name__ == '__main__':
	dDataTrain, dDataTest = get_data0()
	lfcFeatures,ldArgs = get_features0()
	
	''' Generate a list of DataFrames, one for each feature, with the same index/column structure as price data '''
	ldfFeaturesTrain = ftu.applyFeatures( dDataTrain, lfcFeatures, ldArgs, '$SPX')
	ldfFeaturesTest = ftu.applyFeatures( dDataTest, lfcFeatures, ldArgs, '$SPX')

	''' Pick Test and Training Points '''		
	dtStartTrain = dt.datetime(2008,01,01)
	dtEndTrain = dt.datetime(2009,12,31)
	dtStartTest = dt.datetime(2010,01,01)
	dtEndTest = dt.datetime(2010,12,31)
	
	''' Stack all information into one Numpy array ''' 
	naFeatTrain = ftu.stackSyms( ldfFeaturesTrain, dtStartTrain, dtEndTrain )
	naFeatTest = ftu.stackSyms( ldfFeaturesTest, 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 '''
Exemple #4
0
    norObj = da.DataAccess('Yahoo')
    ldtTimestamps = du.getNYSEdays(dtStart, dtEnd, dt.timedelta(hours=16))

    lsKeys = ['open', 'high', 'low', 'close', 'volume']
    ldfData = norObj.get_data(ldtTimestamps, lsSym, lsKeys)
    dData = dict(zip(lsKeys, ldfData))
    ''' Imported functions from qstkfeat.features, NOTE: last function is classification '''
    lfcFeatures = [featMA, featRSI, class_fut_ret]
    ''' Default Arguments '''
    #ldArgs = [{}] * len(lfcFeatures)
    ''' Custom Arguments '''
    ldArgs = [ {'lLookback':30, 'bRel':True},\
               {},\
               {}]
    ''' 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]
Exemple #5
0
    ldArgs = [  {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {'lLookback':5,'bDown':True},{'lLookback':10,'bDown':True},{'lLookback':20,'bDown':True},{'lLookback':5,'bDown':False},{'lLookback':10,'bDown':False},{'lLookback':20,'bDown':False},{'lLookback':5,'bDown':True,'MR':True},{'lLookback':10,'bDown':True,'MR':True},{'lLookback':20,'bDown':True,'MR':True},{'lLookback':5,'bDown':False,'MR':True},{'lLookback':10,'bDown':False,'MR':True},{'lLookback':20,'bDown':False,'MR':True},\
				#{'lLookback':5,'bFast':True},{'lLookback':10,'bFast':True},{'lLookback':20,'bFast':True},{'lLookback':5,'bFast':False},{'lLookback':10,'bFast':False},{'lLookback':20,'bFast':False},{'lLookback':5,'bFast':True,'MR':True},{'lLookback':10,'bFast':True,'MR':True},{'lLookback':20,'bFast':True,'MR':True},{'lLookback':5,'bFast':False,'MR':True},{'lLookback':10,'bFast':False,'MR':True},{'lLookback':20,'bFast':False,'MR':True},\
       {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {'lLookback':5},{'lLookback':10},{'lLookback':20}, {'lLookback':5,'MR':True},{'lLookback':10,'MR':True},{'lLookback':20,'MR':True},\
       {},\
       {},\
       {'i_lookforward':5}
       ]
    ''' Generate a list of DataFrames, one for each feature, with the same index/column structure as price data '''
    ldfFeaturesTrain = ftu.applyFeatures(dDataTrain, lfcFeatures, ldArgs,
                                         '$SPX')
    ldfFeaturesTest = ftu.applyFeatures(dDataTest, lfcFeatures, ldArgs, '$SPX')
    ''' Pick Test and Training Points '''
    dtStartTrain = dt.datetime(2008, 01, 01)
    dtEndTrain = dt.datetime(2009, 12, 31)
    dtStartTest = dt.datetime(2010, 01, 01)
    dtEndTest = dt.datetime(2010, 12, 31)
    ''' Stack all information into one Numpy array '''
    naFeatTrain = ftu.stackSyms(ldfFeaturesTrain, dtStartTrain, dtEndTrain)
    naFeatTest = ftu.stackSyms(ldfFeaturesTest, 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)

    lFeatures = range(0, len(lfcFeatures) - 1)