<s> '''<STR_LIT:U+0020>''' <EOL> import matplotlib <EOL> import matplotlib . pyplot as plt <EOL> import matplotlib . ticker as mticker <EOL> import matplotlib . dates as mdates <EOL> import numpy as np <EOL> from numpy import loadtxt <EOL> import time <EOL> totalStart = time . time ( ) <EOL> date , bid , ask = np . loadtxt ( '<STR_LIT>' , unpack = True , <EOL> delimiter = '<STR_LIT:U+002C>' , <EOL> converters = { <NUM_LIT:0> : mdates . strpdate2num ( '<STR_LIT>' ) } ) <EOL> def percentChange ( startPoint , currentPoint ) : <EOL> try : <EOL> x = ( ( float ( currentPoint ) - startPoint ) / abs ( startPoint ) ) * <NUM_LIT> <EOL> if x == <NUM_LIT:0.0> : <EOL> return <NUM_LIT> <EOL> else : <EOL> return x <EOL> except : <EOL> return <NUM_LIT> <EOL> def patternStorage ( ) : <EOL> '''<STR_LIT>''' <EOL> startTime = time . time ( ) <EOL> x = len ( avgLine ) - <NUM_LIT:30> <EOL> y = <NUM_LIT> <EOL> currentStance = '<STR_LIT:none>' <EOL> while y < x : <EOL> pattern = [ ] <EOL> p1 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p2 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p3 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p4 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p5 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p6 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p7 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p8 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p9 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p10 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:20> ] ) <EOL> p11 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p12 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p13 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p14 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:16> ] ) <EOL> p15 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:15> ] ) <EOL> p16 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p17 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT> ] ) <EOL> p18 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:12> ] ) <EOL> p19 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:11> ] ) <EOL> p20 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:10> ] ) <EOL> p21 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:9> ] ) <EOL> p22 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:8> ] ) <EOL> p23 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:7> ] ) <EOL> p24 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:6> ] ) <EOL> p25 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:5> ] ) <EOL> p26 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:4> ] ) <EOL> p27 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:3> ] ) <EOL> p28 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:2> ] ) <EOL> p29 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y - <NUM_LIT:1> ] ) <EOL> p30 = percentChange ( avgLine [ y - <NUM_LIT:30> ] , avgLine [ y ] ) <EOL> outcomeRange = avgLine [ y + <NUM_LIT:20> : y + <NUM_LIT:30> ] <EOL> currentPoint = avgLine [ y ] <EOL> try : <EOL> avgOutcome = reduce ( lambda x , y : x + y , outcomeRange ) / len ( outcomeRange ) <EOL> except Exception , e : <EOL> print str ( e ) <EOL> avgOutcome = <NUM_LIT:0> <EOL> futureOutcome = percentChange ( currentPoint , avgOutcome ) <EOL> '''<STR_LIT>''' <EOL> pattern . append ( p1 ) <EOL> pattern . append ( p2 ) <EOL> pattern . append ( p3 ) <EOL> pattern . append ( p4 ) <EOL> pattern . append ( p5 ) <EOL> pattern . append ( p6 ) <EOL> pattern . append ( p7 ) <EOL> pattern . append ( p8 ) <EOL> pattern . append ( p9 ) <EOL> pattern . append ( p10 ) <EOL> pattern . append ( p11 ) <EOL> pattern . append ( p12 ) <EOL> pattern . append ( p13 ) <EOL> pattern . append ( p14 ) <EOL> pattern . append ( p15 ) <EOL> pattern . append ( p16 ) <EOL> pattern . append ( p17 ) <EOL> pattern . append ( p18 ) <EOL> pattern . append ( p19 ) <EOL> pattern . append ( p20 ) <EOL> pattern . append ( p21 ) <EOL> pattern . append ( p22 ) <EOL> pattern . append ( p23 ) <EOL> pattern . append ( p24 ) <EOL> pattern . append ( p25 ) <EOL> pattern . append ( p26 ) <EOL> pattern . append ( p27 ) <EOL> pattern . append ( p28 ) <EOL> pattern . append ( p29 ) <EOL> pattern . append ( p30 ) <EOL> patternAr . append ( pattern ) <EOL> performanceAr . append ( futureOutcome ) <EOL> y += <NUM_LIT:1> <EOL> endTime = time . time ( ) <EOL> print len ( patternAr ) <EOL> print len ( performanceAr ) <EOL> print '<STR_LIT>' , endTime - startTime <EOL> def currentPattern ( ) : <EOL> mostRecentPoint = avgLine [ - <NUM_LIT:1> ] <EOL> cp1 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:30> ] ) <EOL> cp2 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp3 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp4 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp5 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp6 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp7 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp8 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp9 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp10 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp11 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:20> ] ) <EOL> cp12 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp13 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp14 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp15 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:16> ] ) <EOL> cp16 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:15> ] ) <EOL> cp17 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp18 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT> ] ) <EOL> cp19 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:12> ] ) <EOL> cp20 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:11> ] ) <EOL> cp21 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:10> ] ) <EOL> cp22 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:9> ] ) <EOL> cp23 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:8> ] ) <EOL> cp24 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:7> ] ) <EOL> cp25 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:6> ] ) <EOL> cp26 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:5> ] ) <EOL> cp27 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:4> ] ) <EOL> cp28 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:3> ] ) <EOL> cp29 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:2> ] ) <EOL> cp30 = percentChange ( avgLine [ - <NUM_LIT> ] , avgLine [ - <NUM_LIT:1> ] ) <EOL> patForRec . append ( cp1 ) <EOL> patForRec . append ( cp2 ) <EOL> patForRec . append ( cp3 ) <EOL> patForRec . append ( cp4 ) <EOL> patForRec . append ( cp5 ) <EOL> patForRec . append ( cp6 ) <EOL> patForRec . append ( cp7 ) <EOL> patForRec . append ( cp8 ) <EOL> patForRec . append ( cp9 ) <EOL> patForRec . append ( cp10 ) <EOL> patForRec . append ( cp11 ) <EOL> patForRec . append ( cp12 ) <EOL> patForRec . append ( cp13 ) <EOL> patForRec . append ( cp14 ) <EOL> patForRec . append ( cp15 ) <EOL> patForRec . append ( cp16 ) <EOL> patForRec . append ( cp17 ) <EOL> patForRec . append ( cp18 ) <EOL> patForRec . append ( cp19 ) <EOL> patForRec . append ( cp20 ) <EOL> patForRec . append ( cp21 ) <EOL> patForRec . append ( cp22 ) <EOL> patForRec . append ( cp23 ) <EOL> patForRec . append ( cp24 ) <EOL> patForRec . append ( cp25 ) <EOL> patForRec . append ( cp26 ) <EOL> patForRec . append ( cp27 ) <EOL> patForRec . append ( cp28 ) <EOL> patForRec . append ( cp29 ) <EOL> patForRec . append ( cp30 ) <EOL> def graphRawFX ( ) : <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:10> , <NUM_LIT:7> ) ) <EOL> ax1 = plt . subplot2grid ( ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) , rowspan = <NUM_LIT> , colspan = <NUM_LIT> ) <EOL> ax1 . plot ( date , bid ) <EOL> ax1 . plot ( date , ask ) <EOL> ax1 . xaxis . set_major_formatter ( mdates . DateFormatter ( '<STR_LIT>' ) ) <EOL> plt . grid ( True ) <EOL> for label in ax1 . xaxis . get_ticklabels ( ) : <EOL> label . set_rotation ( <NUM_LIT> ) <EOL> plt . gca ( ) . get_yaxis ( ) . get_major_formatter ( ) . set_useOffset ( False ) <EOL> ax1_2 = ax1 . twinx ( ) <EOL> ax1_2 . fill_between ( date , <NUM_LIT:0> , ( ask - bid ) , facecolor = '<STR_LIT:g>' , alpha = <NUM_LIT> ) <EOL> plt . subplots_adjust ( bottom = <NUM_LIT> ) <EOL> plt . show ( ) <EOL> def patternRecognition ( ) : <EOL> plotPatAr = [ ] <EOL> patFound = <NUM_LIT:0> <EOL> for eachPattern in patternAr : <EOL> sim1 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:0> ] , patForRec [ <NUM_LIT:0> ] ) ) <EOL> sim2 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:1> ] , patForRec [ <NUM_LIT:1> ] ) ) <EOL> sim3 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:2> ] , patForRec [ <NUM_LIT:2> ] ) ) <EOL> sim4 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:3> ] , patForRec [ <NUM_LIT:3> ] ) ) <EOL> sim5 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:4> ] , patForRec [ <NUM_LIT:4> ] ) ) <EOL> sim6 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:5> ] , patForRec [ <NUM_LIT:5> ] ) ) <EOL> sim7 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:6> ] , patForRec [ <NUM_LIT:6> ] ) ) <EOL> sim8 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:7> ] , patForRec [ <NUM_LIT:7> ] ) ) <EOL> sim9 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:8> ] , patForRec [ <NUM_LIT:8> ] ) ) <EOL> sim10 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:9> ] , patForRec [ <NUM_LIT:9> ] ) ) <EOL> sim11 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:10> ] , patForRec [ <NUM_LIT:10> ] ) ) <EOL> sim12 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:11> ] , patForRec [ <NUM_LIT:11> ] ) ) <EOL> sim13 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:12> ] , patForRec [ <NUM_LIT:12> ] ) ) <EOL> sim14 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim15 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim16 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:15> ] , patForRec [ <NUM_LIT:15> ] ) ) <EOL> sim17 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:16> ] , patForRec [ <NUM_LIT:16> ] ) ) <EOL> sim18 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim19 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim20 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim21 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT:20> ] , patForRec [ <NUM_LIT:20> ] ) ) <EOL> sim22 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim23 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim24 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim25 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim26 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim27 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim28 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim29 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> sim30 = <NUM_LIT> - abs ( percentChange ( eachPattern [ <NUM_LIT> ] , patForRec [ <NUM_LIT> ] ) ) <EOL> howSim = ( sim1 + sim2 + sim3 + sim4 + sim5 + sim6 + sim7 + sim8 + sim9 + sim10 <EOL> + sim11 + sim12 + sim13 + sim14 + sim15 + sim16 + sim17 + sim18 + sim19 + sim20 <EOL> + sim21 + sim22 + sim23 + sim24 + sim25 + sim26 + sim27 + sim28 + sim29 + sim30 ) / <NUM_LIT> <EOL> if howSim > <NUM_LIT> : <EOL> patdex = patternAr . index ( eachPattern ) <EOL> patFound = <NUM_LIT:1> <EOL> xp = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> ] <EOL> plotPatAr . append ( eachPattern ) <EOL> '''<STR_LIT>''' <EOL> if patFound == <NUM_LIT:1> : <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:10> , <NUM_LIT:6> ) ) <EOL> for eachPatt in plotPatAr : <EOL> plt . plot ( xp , eachPatt ) <EOL> plt . plot ( xp , patForRec , '<STR_LIT>' , linewidth = <NUM_LIT:3> ) <EOL> plt . grid ( True ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> plt . show ( ) <EOL> dataLength = int ( bid . shape [ <NUM_LIT:0> ] ) <EOL> print '<STR_LIT>' , dataLength <EOL> toWhat = <NUM_LIT> <EOL> while toWhat < dataLength : <EOL> avgLine = ( ( bid + ask ) / <NUM_LIT:2> ) <EOL> avgLine = avgLine [ : toWhat ] <EOL> patternAr = [ ] <EOL> performanceAr = [ ] <EOL> patForRec = [ ] <EOL> patternStorage ( ) <EOL> currentPattern ( ) <EOL> patternRecognition ( ) <EOL> totalEnd = time . time ( ) - totalStart <EOL> print '<STR_LIT>' , totalEnd , '<STR_LIT>' <EOL> toWhat += <NUM_LIT:1> </s>
