Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tucker777/QSTK
Browse files Browse the repository at this point in the history
  • Loading branch information
sb2nov committed Dec 19, 2012
2 parents 8c60b61 + 6f88741 commit 3dd1639
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
57 changes: 55 additions & 2 deletions qstkfeat/featutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
''' Our Imports '''
import qstklearn.kdtknn as kdt
from qstkutil import DataAccess as da
from qstkutil import DataEvolved as de
from qstkutil import qsdateutil as du
from qstkutil import tsutil as tsu

Expand Down Expand Up @@ -415,6 +416,58 @@ def testFeature( fcFeature, dArgs ):
plt.title( '%s-%s'%(fcFeature.__name__, str(dArgs)) )
plt.show()


def speedTest(fcFeature,ldArgs):
'''
@Author: Tingyu Zhu
@summary: Function to test the runtime for a list of features, and output them by speed
@param lsFeature: a list of features that will be sorted by runtime
@param dArgs: Arguments to pass into feature function
'''

'''pulling out 2 years data to run test'''
daData = de.DataAccess('mysql')
#daData = da.DataAccess('Yahoo')
dtStart = dt.datetime(2010,12,1)
dtEnd = dt.datetime(2010,12,31)
dtTimeofday = dt.timedelta(hours=16)
#lsSym = ['AAPL','GOOG','XOM','AMZN','BA','GILD']
lsSym = daData.get_all_symbols()

print lsSym

'''set up variables for applyFeatures'''
lsKeys = ['open', 'high', 'low', 'close', 'volume', 'actual_close']
ldtTimestamps = du.getNYSEdays( dtStart,dtEnd, dtTimeofday)
ldfData = daData.get_data( ldtTimestamps,lsSym, lsKeys)
dData = dict(zip(lsKeys,ldfData))



'''loop through features'''
lsRuntime = []
dicLog = {}
for feature in fcFeature:
print feature.__name__
dtFuncStart = dt.datetime.now()
ldfFeatures = applyFeatures( dData,[feature], ldArgs)
dtFuncEnd = dt.datetime.now()
tRuntime = dtFuncEnd - dtFuncStart
dicLog[tRuntime] = feature.__name__
lsRuntime.append(tRuntime)
lsRuntime.sort()

'''print out result'''
txLog = []
for i in lsRuntime:
temp = dicLog[i] + ' : ' + str(i)
txLog.append(temp)
print temp


return txLog

if __name__ == '__main__':
testFeature( class_fut_ret, {'MR':True})
pass
speedTest([featMA,featRSI,featAroon,featBeta,featCorrelation,featBollinger,featStochastic],[{'lLookback':30}])
#testFeature( class_fut_ret, {'MR':True})
#pass
8 changes: 5 additions & 3 deletions qstkutil/DataEvolved.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ def get_data_hard_read(self, ts_list, symbol_list, data_item, verbose=False, inc
' FROM priceadjusted WHERE assetid in (' + s_idlist + ')' + \
' AND date >= %s AND date <= %s '


self.cursor.execute(s_query, (ts_list[0].replace(hour=0), ts_list[-1]))

try:
self.cursor.execute(s_query, (ts_list[0].replace(hour=0), ts_list[-1]))
except:
print 'Data error, probably using an non-existent symbol'

# Retrieve Results
results = self.cursor.fetchall()

Expand Down

0 comments on commit 3dd1639

Please sign in to comment.