def initialize(self,pathfilenamecandidatexml,showresults): import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize(pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML totalcandidatepairs = totalcandidatepairs + len(d1) #print(' --',len(d1),'candidate pairs found') for k,v in d1.items(): if v['specifications']['symbol'] in excludesymbols.values(): if not v['specifications']['symbol'] in d_exclude.values(): d_exclude[len(d_exclude)] = v['specifications']['symbol'] if not v['specifications']['symbol'] in excludesymbols.values(): d3[len(d3)] = v print(' --',len(d1),'candidate pairs in',v['specifications']['symbol']) print(' ','--',pathfilenamecandidatexml)
def initialize(self, pathfilenamecandidatexml, showresults): import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize(pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML totalcandidatepairs = totalcandidatepairs + len(d1) #print(' --',len(d1),'candidate pairs found') for k, v in d1.items(): if v['specifications']['symbol'] in excludesymbols.values(): if not v['specifications']['symbol'] in d_exclude.values(): d_exclude[len(d_exclude)] = v['specifications']['symbol'] if not v['specifications']['symbol'] in excludesymbols.values(): d3[len(d3)] = v print(' --', len(d1), 'candidate pairs in', v['specifications']['symbol']) print(' ', '--', pathfilenamecandidatexml)
def execute_process(self, directoryofcandidatexml, showresults): self.Complete = 0 from datetime import datetime starttime = datetime.now() #datetime.strptime(t1, TIME_FORMAT2) - datetime.strptime(t2, TIME_FORMAT2) #_.total_seconds() #-9.254 showresults = 0 import os import deserializecandidatesxml d1 = {} d2 = {} d3 = {} #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00\\45' #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00' #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00 archive' topdirectory = directoryofcandidatexml #'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-31' rootdir = topdirectory runningsumofxmlfiles = 0 runningsumofcandidates = 0 import mytools for subdir, dirs, files in os.walk(rootdir): runningsumofxmlfiles = runningsumofxmlfiles + len(files) for file in files: pathfilenamecandidatexml = os.path.join(subdir, file) print('-----------------------------') print('-- ', 'pathfilenamecandidatexml') print('-- ', pathfilenamecandidatexml) o1 = deserializecandidatesxml.deserialize( pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML runningsumofcandidates = runningsumofcandidates + len(d1) print('--------------------') print('-- processing ' + str(len(d1)) + ' candidates') for k, v in d1.items(): d3[len(d3)] = v if showresults == 1: print('k', v['keyid'], v['specifications']['symbol'], v['calculations']['sortbymeasurename'], v['calculations']['sortbymeasurevalue'], 'VAR (open)', v['calculations']['valueatriskopen'], v['earlier']['optionsymbol'], v['later']['optionsymbol'], v['earlier']['bucketquotedatetime']) print('') print('--------------------') print('-- End of test_loop_deserializecandidatexml') #endtime1 = datetime.now() #difftimexml = endtime1 - starttime # yields a timedelta object import convertcandidatesdictionarytosortable o_convertcandidatesdictionarytosortable = convertcandidatesdictionarytosortable.convert( d3, sortbymeasure='spreadpercentageopen') d4 = o_convertcandidatesdictionarytosortable.DictionaryOfSortableCandidatesOutput import sortasortablecandidatesdictionary o_sortasortablecandidatesdictionary = sortasortablecandidatesdictionary.sort( d4) d5 = o_sortasortablecandidatesdictionary.DictionaryOfSortedCandidatesOutput for k1, v1 in d5.items(): v = v1['candidate'] #earlieroptionsymbol = v['earlier']['optionsymbol'] #expirationdate = mytools.get_from_optionsymbol.expirationdate(earlieroptionsymbol).date() #vdate = mytools.mystrings.ConvertStringToDate('2015-02-14') #if expirationdate <= vdate: print( 'k', str(k1 + 1) # , v['keyid'] , v['specifications']['symbol'], '=', v['specifications']['stockprice'], v['calculations']['sortbymeasurename'], v['calculations']['sortbymeasurevalue'], 'VAR', v['calculations']['valueatriskopen'], 'earlierbid=', v['earlier']['bid'], 'laterask=', v['later']['ask'], v['earlier']['optionsymbol'], v['later']['optionsymbol'], v['earlier']['bucketquotedatetime']) endtime = datetime.now() print(str(starttime)) print(str(endtime)) difftimetotal = endtime - starttime # yields a timedelta object print('-- ', directoryofcandidatexml) print('-- ', str(runningsumofxmlfiles) + ' candidate xml files deserialized') print('-- ', str(runningsumofcandidates) + ' total candidates') print('-- ', str(len(d3)) + ' candidates now in base dictionary') #print('-- ', str(difftimexml.microseconds/100000.0), 'microseconds to process xml files') print('-- ', str(difftimetotal.microseconds / 100000.0), 'seconds to process everything') self.Complete = 1
def execute_process(self, dictionaryofcandidatexmldirectories, excludesymbols, showresults): self.Complete = 0 d_candidates = {} from datetime import datetime starttime = datetime.now() #datetime.strptime(t1, TIME_FORMAT2) - datetime.strptime(t2, TIME_FORMAT2) #_.total_seconds() #-9.254 showresults = 0 import os import deserializecandidatesxml d1 = {} #d2 = {} d3 = {} d_exclude = {} runningsumofxmlfiles = 0 totalcandidatepairs = 0 #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00\\45' #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00' #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00 archive' for k, directoryofcandidatexml in dictionaryofcandidatexmldirectories.items( ): topdirectory = directoryofcandidatexml #'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-31' rootdir = topdirectory #import mytools for subdir, dirs, files in os.walk(rootdir): runningsumofxmlfiles = runningsumofxmlfiles + len(files) for file in files: #testvalid = file[:15] #if file.find(excludesymbols) == -1: print(file) pathfilenamecandidatexml = os.path.join(subdir, file) print(' ', '-----------------------------') print( ' ', '-- Iterating: deserializefromdictionaryofcandidatexmldirectories.py' ) o1 = deserializecandidatesxml.deserialize( pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML totalcandidatepairs = totalcandidatepairs + len(d1) #print(' --',len(d1),'candidate pairs found') for k, v in d1.items(): if v['specifications'][ 'symbol'] in excludesymbols.values(): if not v['specifications'][ 'symbol'] in d_exclude.values(): d_exclude[len( d_exclude)] = v['specifications']['symbol'] if not v['specifications'][ 'symbol'] in excludesymbols.values(): d3[len(d3)] = v print(' --', len(d1), 'candidate pairs in', v['specifications']['symbol']) print(' ', '--', pathfilenamecandidatexml) #endtime1 = datetime.now() #difftimexml = endtime1 - starttime # yields a timedelta object print('---------------------------------------------------') print('-- Iterating Complete', '---------------------------') print('---------------------------------------------------') import convertcandidatesdictionarytosortable o_convertcandidatesdictionarytosortable = convertcandidatesdictionarytosortable.convert( d3, sortbymeasure='spreadpercentageopen') d4 = o_convertcandidatesdictionarytosortable.DictionaryOfSortableCandidatesOutput import sortasortablecandidatesdictionarydescending o_sortasortablecandidatesdictionary = sortasortablecandidatesdictionarydescending.sort( d4) d5 = o_sortasortablecandidatesdictionary.DictionaryOfSortedCandidatesOutput for k1, v1 in d5.items(): v = v1['candidate'] d_candidates[len(d_candidates)] = v #earlieroptionsymbol = v['earlier']['optionsymbol'] #expirationdate = mytools.get_from_optionsymbol.expirationdate(earlieroptionsymbol).date() #vdate = mytools.mystrings.ConvertStringToDate('2015-02-14') #if expirationdate <= vdate: ################################################################## #showresults = 0 if showresults == 1: print( 'k', str(k1 + 1) # , v['keyid'] , v['specifications']['symbol'], '=', v['specifications']['stockprice'], v['calculations']['sortbymeasurename'], v['calculations']['sortbymeasurevalue'], 'VAR', v['calculations']['valueatriskopen'], 'earlierbid=', v['earlier']['bid'], 'laterask=', v['later']['ask'], v['earlier']['optionsymbol'], v['later']['optionsymbol'], v['earlier']['bucketquotedatetime']) ################################################################## endtime = datetime.now() print('-- ', 'Started', str(starttime)) #print(str(endtime)) difftimetotal = endtime - starttime # yields a timedelta object print('-- --', 'Directory count', len(dictionaryofcandidatexmldirectories)) print('-- --', runningsumofxmlfiles, 'candidate xml files deserialized') #print('-- --', totalcandidatepairs,'total candidate xml files') print('-- --', len(d_candidates), ' candidates in base dictionary') print('-- --', len(d_exclude), 'candidate(s) excluded') #print('-- --', str(difftimexml.microseconds/100000.0), 'microseconds to process xml files') print('--', 'Ended:', str(endtime)) print('--', str(difftimetotal.microseconds / 100000.0), 'seconds to process') print('Source', dictionaryofcandidatexmldirectories.items()) self.DictionaryOfDeserializedCalendarSpreadCandidates = d_candidates self.DictionaryOfExcludedSymbols = d_exclude self.Complete = 1
# -*- coding: utf-8 -*- """ Created on Sun Jan 18 07:24:59 2015 @author: jmalinchak """ import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize( 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\xml\\calendarspreads 20150119053018.xml' ) d1 = o1.DictionaryOfCandidatesFromXML print(len(d1)) for k, v in d1.items(): print(k, v['keyid'], v['calculations']['sortbymeasurevalue'], v['specifications']['symbol'], v['earlier']['optionsymbol'], v['earlier']['bucketquotedatetime'], v['calculations']['sortbymeasurename']) o2 = deserializecandidatesxml.deserialize( 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\xml\\calendarspreads 20150119172619.xml' ) d2 = o2.DictionaryOfCandidatesFromXML print(len(d2)) for k, v in d2.items(): print(k, v['keyid'], v['calculations']['sortbymeasurevalue'], v['specifications']['symbol'], v['earlier']['optionsymbol'], v['earlier']['bucketquotedatetime'], v['calculations']['sortbymeasurename']) print('Count of Candidates 1:', len(o1.DictionaryOfCandidatesFromXML))
def serialize(self, downloadsdirectory, replacelistforcreatingdestinationpath, minpairspreadpercent, maxvalueatrisk, maxbidaskspreadpercentagesell, maxbidaskspreadpercentagebuy, showresults): ## ######################## ## How to get top directory import os downloadsdir_root = os.path.join(os.getcwd(), downloadsdirectory) if showresults == 1: print(downloadsdir_root) ## #################### ## Process downloads directories import readfiltersortserializetobucketdirectories dSerializedQuadCandidateXMLPathNames = {} iCount = 0 for root, dirs, files in os.walk(downloadsdir_root): for name in dirs: downloadsdir_check = os.path.join(root, name) iCount = self.countfiles(downloadsdir_check, '.csv') print('Count of Csv files:', iCount, downloadsdir_check) # ## ################################### if iCount > 0: sourcedirectoryfull = downloadsdir_check print(sourcedirectoryfull) o = readfiltersortserializetobucketdirectories.read( sourcedirectoryfull, minpairspreadpercent=minpairspreadpercent, maxvalueatrisk=maxvalueatrisk, maxbidaskspreadpercentagesell= maxbidaskspreadpercentagesell, maxbidaskspreadpercentagebuy= maxbidaskspreadpercentagebuy, sortbymeasure='spreadpercentageopen' ) # spreadpercentageopen | valueatriskopen self.DictionaryOfSerializedFileObjects = o.DictionaryOfSerializedFileObjects d1 = o.DictionaryOfSerializedFileObjects print( '-- --', 'Looping DictionaryOfSerializedFileObjects in runquadbysymbol' ) for k1, v1 in d1.items(): print('-- --', 'XMLFilenameOutput', v1.XMLFilenameOutput) import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize( v1.XMLFilenameOutput) d1 = o1.DictionaryOfCandidatesFromXML #minpairspreadpercent = 0.4 dSortableDictionary = {} import mytools mysymbol = '---' for k1, v1 in d1.items(): optiontype1 = mytools.get_from_optionsymbol.optiontype( v1['earlier']['optionsymbol']) if optiontype1 == 'C': for k2, v2 in d1.items(): if v1['specifications'][ 'bucketquotedatetime'] == v2[ 'specifications'][ 'bucketquotedatetime']: if v1['specifications']['symbol'] == v2[ 'specifications']['symbol']: mysymbol = v1['specifications'][ 'symbol'] optiontype2 = mytools.get_from_optionsymbol.optiontype( v2['earlier']['optionsymbol']) if optiontype2 == 'P': if float( v1['calculations'] ['spreadpercentageopen'] ) > minpairspreadpercent and float( v2['calculations'] ['spreadpercentageopen'] ) > minpairspreadpercent: EarlierStrike1 = mytools.get_from_optionsymbol.strike( v1['earlier'] ['optionsymbol']) LaterStrike1 = mytools.get_from_optionsymbol.strike( v1['later'] ['optionsymbol']) EarlierStrike2 = mytools.get_from_optionsymbol.strike( v2['earlier'] ['optionsymbol']) LaterStrike2 = mytools.get_from_optionsymbol.strike( v2['later'] ['optionsymbol']) if float( EarlierStrike1 ) > float( v1['specifications'] ['stockprice'] ) and float( LaterStrike1 ) > float(v1[ 'specifications'] ['stockprice']): if float( EarlierStrike2 ) < float( v1['specifications'] ['stockprice'] ) and float( LaterStrike2 ) < float(v1[ 'specifications'] ['stockprice'] ): if k1 != k2: sumofvalueatrisk = float( v1['calculations'] ['valueatriskopen'] ) + float( v2['calculations'] ['valueatriskopen'] ) dSortableDictionary[len( dSortableDictionary )] = { 'sortbymeasurevalue': sumofvalueatrisk, 'callcalendarspread': v1, 'putcalendarspread': v2, 'sortbymeasurename': 'valueatrisk' } from collections import OrderedDict dOrdered = OrderedDict( sorted(dSortableDictionary.items(), key=lambda t: t[1]['sortbymeasurevalue'])) import serializedictionaryofcalendarspreadquadstoxml oquads = serializedictionaryofcalendarspreadquadstoxml.serialize( sourcedirectoryfull, mysymbol, dOrdered, 1000, 0) #print('got to here 2212') if oquads.Complete == 1 and len( oquads.XMLFilenameOutput) > 0: print("oquads.XMLFilenameOutput=", oquads.XMLFilenameOutput) dSerializedQuadCandidateXMLPathNames[ len(dSerializedQuadCandidateXMLPathNames )] = oquads.XMLFilenameOutput #print('Count',sourcedirectoryfull,iCount) #destinationdirectoryfull = sourcedirectoryfull destinationdirectoryfull = sourcedirectoryfull.replace( replacelistforcreatingdestinationpath[0], replacelistforcreatingdestinationpath[1]) import mytools mytools.general.make_sure_path_exists( destinationdirectoryfull) print('Destination', destinationdirectoryfull) import shutil # Move src to dst (mv src dst) shutil.rmtree(destinationdirectoryfull, ignore_errors=True, onerror=None) shutil.move(sourcedirectoryfull, destinationdirectoryfull) print('got here 8181', len(dSerializedQuadCandidateXMLPathNames)) self.DictionaryOfSerializedQuadCandidateXMLPathNames = dSerializedQuadCandidateXMLPathNames
import os import deserializecandidatesxml d1 = {} d2 = {} topdirectory = "C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00\\45" # topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00' rootdir = topdirectory for subdir, dirs, files in os.walk(rootdir): for file in files: pathfilenamecandidatexml = os.path.join(subdir, file) print("-----------------------------") print("-- ", pathfilenamecandidatexml) o1 = deserializecandidatesxml.deserialize(pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML print(len(d1)) for k, v in d1.items(): print( k, v["keyid"], v["calculations"]["sortbymeasurevalue"], v["calculations"]["sortbymeasurename"], v["specifications"]["symbol"], v["earlier"]["optionsymbol"], v["earlier"]["bucketquotedatetime"], )
def execute_process(self,dictionaryofcandidatexmldirectories,excludesymbols,showresults): self.Complete = 0 d_candidates ={} from datetime import datetime starttime = datetime.now() #datetime.strptime(t1, TIME_FORMAT2) - datetime.strptime(t2, TIME_FORMAT2) #_.total_seconds() #-9.254 showresults = 0 import os import deserializecandidatesxml d1 = {} #d2 = {} d3 = {} d_exclude = {} runningsumofxmlfiles = 0 totalcandidatepairs = 0 #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00\\45' #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00' #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00 archive' for k,directoryofcandidatexml in dictionaryofcandidatexmldirectories.items(): topdirectory = directoryofcandidatexml #'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-31' rootdir = topdirectory #import mytools for subdir, dirs, files in os.walk(rootdir): runningsumofxmlfiles = runningsumofxmlfiles + len(files) for file in files: #testvalid = file[:15] #if file.find(excludesymbols) == -1: print(file) pathfilenamecandidatexml = os.path.join(subdir, file) print(' ','-----------------------------') print(' ','-- Iterating: deserializefromdictionaryofcandidatexmldirectories.py') o1 = deserializecandidatesxml.deserialize(pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML totalcandidatepairs = totalcandidatepairs + len(d1) #print(' --',len(d1),'candidate pairs found') for k,v in d1.items(): if v['specifications']['symbol'] in excludesymbols.values(): if not v['specifications']['symbol'] in d_exclude.values(): d_exclude[len(d_exclude)] = v['specifications']['symbol'] if not v['specifications']['symbol'] in excludesymbols.values(): d3[len(d3)] = v print(' --',len(d1),'candidate pairs in',v['specifications']['symbol']) print(' ','--',pathfilenamecandidatexml) #endtime1 = datetime.now() #difftimexml = endtime1 - starttime # yields a timedelta object print('---------------------------------------------------') print('-- Iterating Complete','---------------------------') print('---------------------------------------------------') import convertcandidatesdictionarytosortable o_convertcandidatesdictionarytosortable = convertcandidatesdictionarytosortable.convert(d3,sortbymeasure='spreadpercentageopen') d4 = o_convertcandidatesdictionarytosortable.DictionaryOfSortableCandidatesOutput import sortasortablecandidatesdictionarydescending o_sortasortablecandidatesdictionary = sortasortablecandidatesdictionarydescending.sort(d4) d5 = o_sortasortablecandidatesdictionary.DictionaryOfSortedCandidatesOutput for k1,v1 in d5.items(): v = v1['candidate'] d_candidates[len(d_candidates)] = v #earlieroptionsymbol = v['earlier']['optionsymbol'] #expirationdate = mytools.get_from_optionsymbol.expirationdate(earlieroptionsymbol).date() #vdate = mytools.mystrings.ConvertStringToDate('2015-02-14') #if expirationdate <= vdate: ################################################################## #showresults = 0 if showresults == 1: print( 'k' , str(k1+1) # , v['keyid'] , v['specifications']['symbol'] , '=' , v['specifications']['stockprice'] , v['calculations']['sortbymeasurename'] , v['calculations']['sortbymeasurevalue'] , 'VAR' , v['calculations']['valueatriskopen'] , 'earlierbid=' , v['earlier']['bid'] , 'laterask=' , v['later']['ask'] , v['earlier']['optionsymbol'] , v['later']['optionsymbol'] , v['earlier']['bucketquotedatetime'] ) ################################################################## endtime = datetime.now() print('-- ','Started',str(starttime)) #print(str(endtime)) difftimetotal = endtime - starttime # yields a timedelta object print('-- --', 'Directory count',len(dictionaryofcandidatexmldirectories)) print('-- --', runningsumofxmlfiles,'candidate xml files deserialized') #print('-- --', totalcandidatepairs,'total candidate xml files') print('-- --', len(d_candidates), ' candidates in base dictionary') print('-- --', len(d_exclude),'candidate(s) excluded') #print('-- --', str(difftimexml.microseconds/100000.0), 'microseconds to process xml files') print('--','Ended:',str(endtime)) print('--', str(difftimetotal.microseconds/100000.0), 'seconds to process') print('Source',dictionaryofcandidatexmldirectories.items()) self.DictionaryOfDeserializedCalendarSpreadCandidates = d_candidates self.DictionaryOfExcludedSymbols = d_exclude self.Complete = 1
""" Created on Sun Jan 18 07:24:59 2015 @author: jmalinchak """ import os import deserializecandidatesxml d1 = {} d2 = {} topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00\\45' #topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00' rootdir = topdirectory for subdir, dirs, files in os.walk(rootdir): for file in files: pathfilenamecandidatexml = os.path.join(subdir, file) print('-----------------------------') print('-- ', pathfilenamecandidatexml) o1 = deserializecandidatesxml.deserialize(pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML print(len(d1)) for k, v in d1.items(): print(k, v['keyid'], v['calculations']['sortbymeasurevalue'], v['calculations']['sortbymeasurename'], v['specifications']['symbol'], v['earlier']['optionsymbol'], v['earlier']['bucketquotedatetime'])
def serialize(self, downloadsdirectory , replacelistforcreatingdestinationpath , minpairspreadpercent , maxvalueatrisk , maxbidaskspreadpercentagesell , maxbidaskspreadpercentagebuy , showresults ): ## ######################## ## How to get top directory import os downloadsdir_root = os.path.join(os.getcwd(),downloadsdirectory) if showresults == 1: print(downloadsdir_root) ## #################### ## Process downloads directories import readfiltersortserializetobucketdirectories dSerializedQuadCandidateXMLPathNames = {} iCount = 0 for root, dirs, files in os.walk(downloadsdir_root): for name in dirs: downloadsdir_check = os.path.join(root, name) iCount = self.countfiles(downloadsdir_check,'.csv') print('Count of Csv files:',iCount,downloadsdir_check) # ## ################################### if iCount > 0: sourcedirectoryfull = downloadsdir_check print(sourcedirectoryfull) o = readfiltersortserializetobucketdirectories.read(sourcedirectoryfull, minpairspreadpercent = minpairspreadpercent, maxvalueatrisk = maxvalueatrisk, maxbidaskspreadpercentagesell = maxbidaskspreadpercentagesell, maxbidaskspreadpercentagebuy = maxbidaskspreadpercentagebuy, sortbymeasure = 'spreadpercentageopen') # spreadpercentageopen | valueatriskopen self.DictionaryOfSerializedFileObjects = o.DictionaryOfSerializedFileObjects d1 = o.DictionaryOfSerializedFileObjects print('-- --','Looping DictionaryOfSerializedFileObjects in runquadbysymbol') for k1,v1 in d1.items(): print('-- --','XMLFilenameOutput',v1.XMLFilenameOutput) import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize(v1.XMLFilenameOutput) d1 = o1.DictionaryOfCandidatesFromXML #minpairspreadpercent = 0.4 dSortableDictionary = {} import mytools mysymbol = '---' for k1,v1 in d1.items(): optiontype1 = mytools.get_from_optionsymbol.optiontype(v1['earlier']['optionsymbol']) if optiontype1 == 'C': for k2,v2 in d1.items(): if v1['specifications']['bucketquotedatetime'] == v2['specifications']['bucketquotedatetime']: if v1['specifications']['symbol'] == v2['specifications']['symbol']: mysymbol = v1['specifications']['symbol'] optiontype2 = mytools.get_from_optionsymbol.optiontype(v2['earlier']['optionsymbol']) if optiontype2 == 'P': if float(v1['calculations']['spreadpercentageopen']) > minpairspreadpercent and float(v2['calculations']['spreadpercentageopen']) > minpairspreadpercent: EarlierStrike1 = mytools.get_from_optionsymbol.strike(v1['earlier']['optionsymbol']) LaterStrike1 = mytools.get_from_optionsymbol.strike(v1['later']['optionsymbol']) EarlierStrike2 = mytools.get_from_optionsymbol.strike(v2['earlier']['optionsymbol']) LaterStrike2 = mytools.get_from_optionsymbol.strike(v2['later']['optionsymbol']) if float(EarlierStrike1) > float(v1['specifications']['stockprice']) and float(LaterStrike1) > float(v1['specifications']['stockprice']): if float(EarlierStrike2) < float(v1['specifications']['stockprice']) and float(LaterStrike2) < float(v1['specifications']['stockprice']): if k1 != k2: sumofvalueatrisk = float(v1['calculations']['valueatriskopen']) + float(v2['calculations']['valueatriskopen']) dSortableDictionary[len(dSortableDictionary)] = {'sortbymeasurevalue' : sumofvalueatrisk, 'callcalendarspread' : v1, 'putcalendarspread' : v2, 'sortbymeasurename' : 'valueatrisk'} from collections import OrderedDict dOrdered = OrderedDict(sorted(dSortableDictionary.items(), key=lambda t: t[1]['sortbymeasurevalue'])) import serializedictionaryofcalendarspreadquadstoxml oquads = serializedictionaryofcalendarspreadquadstoxml.serialize(sourcedirectoryfull,mysymbol,dOrdered,1000,0) #print('got to here 2212') if oquads.Complete == 1 and len(oquads.XMLFilenameOutput)>0: print("oquads.XMLFilenameOutput=",oquads.XMLFilenameOutput) dSerializedQuadCandidateXMLPathNames[len(dSerializedQuadCandidateXMLPathNames)] = oquads.XMLFilenameOutput #print('Count',sourcedirectoryfull,iCount) #destinationdirectoryfull = sourcedirectoryfull destinationdirectoryfull = sourcedirectoryfull.replace(replacelistforcreatingdestinationpath[0],replacelistforcreatingdestinationpath[1]) import mytools mytools.general.make_sure_path_exists(destinationdirectoryfull) print('Destination',destinationdirectoryfull) import shutil # Move src to dst (mv src dst) shutil.rmtree(destinationdirectoryfull,ignore_errors=True, onerror=None) shutil.move(sourcedirectoryfull, destinationdirectoryfull) print('got here 8181',len(dSerializedQuadCandidateXMLPathNames)) self.DictionaryOfSerializedQuadCandidateXMLPathNames = dSerializedQuadCandidateXMLPathNames
############################## import serializecsvfilestoxmlcandidatepairs o = serializecsvfilestoxmlcandidatepairs.read(downloadsdirectory = '$execute', replacelistforcreatingdestinationpath = ['\\$execute\\','\\$executeprocessed\\'], minpairspreadpercent = 0.1, maxvalueatrisk = 7.4, maxbidaskspreadpercentagesell = 0.25, maxbidaskspreadpercentagebuy = 0.25, showresults=1) d1 = o.DictionaryOfSerializedFileObjects print('-- --','Looping DictionaryOfSerializedFileObjects in runquadbysymbol') for k1,v1 in d1.items(): print('-- --','XMLFilenameOutput',v1.XMLFilenameOutput) import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize(v1.XMLFilenameOutput) d1 = o1.DictionaryOfCandidatesFromXML minpairspreadpercent = 0.4 dSortableDictionary = {} import mytools for k1,v1 in d1.items(): optiontype1 = mytools.get_from_optionsymbol.optiontype(v1['earlier']['optionsymbol']) if optiontype1 == 'C': for k2,v2 in d1.items(): if v1['specifications']['bucketquotedatetime'] == v2['specifications']['bucketquotedatetime']: if v1['specifications']['symbol'] == v2['specifications']['symbol']: optiontype2 = mytools.get_from_optionsymbol.optiontype(v2['earlier']['optionsymbol']) if optiontype2 == 'P':
downloadsdirectory='$execute', replacelistforcreatingdestinationpath=[ '\\$execute\\', '\\$executeprocessed\\' ], minpairspreadpercent=0.1, maxvalueatrisk=7.4, maxbidaskspreadpercentagesell=0.25, maxbidaskspreadpercentagebuy=0.25, showresults=1) d1 = o.DictionaryOfSerializedFileObjects print('-- --', 'Looping DictionaryOfSerializedFileObjects in runquadbysymbol') for k1, v1 in d1.items(): print('-- --', 'XMLFilenameOutput', v1.XMLFilenameOutput) import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize(v1.XMLFilenameOutput) d1 = o1.DictionaryOfCandidatesFromXML minpairspreadpercent = 0.4 dSortableDictionary = {} import mytools for k1, v1 in d1.items(): optiontype1 = mytools.get_from_optionsymbol.optiontype( v1['earlier']['optionsymbol']) if optiontype1 == 'C': for k2, v2 in d1.items(): if v1['specifications']['bucketquotedatetime'] == v2[ 'specifications']['bucketquotedatetime']: if v1['specifications']['symbol'] == v2['specifications'][
# -*- coding: utf-8 -*- """ Created on Sun Jan 18 07:24:59 2015 @author: jmalinchak """ import deserializecandidatesxml o1 = deserializecandidatesxml.deserialize('C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\xml\\calendarspreads 20150119053018.xml') d1 = o1.DictionaryOfCandidatesFromXML print(len(d1)) for k,v in d1.items(): print(k,v['keyid'],v['calculations']['sortbymeasurevalue'], v['specifications']['symbol'], v['earlier']['optionsymbol'], v['earlier']['bucketquotedatetime'], v['calculations']['sortbymeasurename'] ) o2 = deserializecandidatesxml.deserialize('C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\xml\\calendarspreads 20150119172619.xml') d2 = o2.DictionaryOfCandidatesFromXML print(len(d2)) for k,v in d2.items(): print(k,v['keyid'],v['calculations']['sortbymeasurevalue'], v['specifications']['symbol'], v['earlier']['optionsymbol'], v['earlier']['bucketquotedatetime'], v['calculations']['sortbymeasurename'] ) print('Count of Candidates 1:',len(o1.DictionaryOfCandidatesFromXML))
def execute_process(self, directoryofcandidatexml, showresults): self.Complete = 0 from datetime import datetime starttime = datetime.now() # datetime.strptime(t1, TIME_FORMAT2) - datetime.strptime(t2, TIME_FORMAT2) # _.total_seconds() # -9.254 showresults = 0 import os import deserializecandidatesxml d1 = {} d2 = {} d3 = {} # topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00\\45' # topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00' # topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-21\\00 archive' topdirectory = ( directoryofcandidatexml ) #'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\calendarspreadcandidates\\2015-01-31' rootdir = topdirectory runningsumofxmlfiles = 0 runningsumofcandidates = 0 import mytools for subdir, dirs, files in os.walk(rootdir): runningsumofxmlfiles = runningsumofxmlfiles + len(files) for file in files: pathfilenamecandidatexml = os.path.join(subdir, file) print("-----------------------------") print("-- ", "pathfilenamecandidatexml") print("-- ", pathfilenamecandidatexml) o1 = deserializecandidatesxml.deserialize(pathfilenamecandidatexml) d1 = o1.DictionaryOfCandidatesFromXML runningsumofcandidates = runningsumofcandidates + len(d1) print("--------------------") print("-- processing " + str(len(d1)) + " candidates") for k, v in d1.items(): d3[len(d3)] = v if showresults == 1: print( "k", v["keyid"], v["specifications"]["symbol"], v["calculations"]["sortbymeasurename"], v["calculations"]["sortbymeasurevalue"], "VAR (open)", v["calculations"]["valueatriskopen"], v["earlier"]["optionsymbol"], v["later"]["optionsymbol"], v["earlier"]["bucketquotedatetime"], ) print("") print("--------------------") print("-- End of test_loop_deserializecandidatexml") # endtime1 = datetime.now() # difftimexml = endtime1 - starttime # yields a timedelta object import convertcandidatesdictionarytosortable o_convertcandidatesdictionarytosortable = convertcandidatesdictionarytosortable.convert( d3, sortbymeasure="spreadpercentageopen" ) d4 = o_convertcandidatesdictionarytosortable.DictionaryOfSortableCandidatesOutput import sortasortablecandidatesdictionary o_sortasortablecandidatesdictionary = sortasortablecandidatesdictionary.sort(d4) d5 = o_sortasortablecandidatesdictionary.DictionaryOfSortedCandidatesOutput for k1, v1 in d5.items(): v = v1["candidate"] # earlieroptionsymbol = v['earlier']['optionsymbol'] # expirationdate = mytools.get_from_optionsymbol.expirationdate(earlieroptionsymbol).date() # vdate = mytools.mystrings.ConvertStringToDate('2015-02-14') # if expirationdate <= vdate: print( "k", str(k1 + 1) # , v['keyid'] , v["specifications"]["symbol"], "=", v["specifications"]["stockprice"], v["calculations"]["sortbymeasurename"], v["calculations"]["sortbymeasurevalue"], "VAR", v["calculations"]["valueatriskopen"], "earlierbid=", v["earlier"]["bid"], "laterask=", v["later"]["ask"], v["earlier"]["optionsymbol"], v["later"]["optionsymbol"], v["earlier"]["bucketquotedatetime"], ) endtime = datetime.now() print(str(starttime)) print(str(endtime)) difftimetotal = endtime - starttime # yields a timedelta object print("-- ", directoryofcandidatexml) print("-- ", str(runningsumofxmlfiles) + " candidate xml files deserialized") print("-- ", str(runningsumofcandidates) + " total candidates") print("-- ", str(len(d3)) + " candidates now in base dictionary") # print('-- ', str(difftimexml.microseconds/100000.0), 'microseconds to process xml files') print("-- ", str(difftimetotal.microseconds / 100000.0), "seconds to process everything") self.Complete = 1