13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

437

)

# Create the lookback and lookforward shifts

for i in range(0, lookback_minutes):

ts["Lookback%s" % str(i+1)] = ts["Close"].shift(i+1)

for i in range(0, lookforward_minutes):

ts["Lookforward%s" % str(i+1)] = ts["Close"].shift(-(i+1))

ts.dropna(inplace=True)

# Adjust all of these values to be percentage returns

ts["Lookback0"] = ts["Close"].pct_change()*100.0

for i in range(0, lookback_minutes):

ts["Lookback%s" % str(i+1)] = ts[

"Lookback%s" % str(i+1)

].pct_change()*100.0

for i in range(0, lookforward_minutes):

ts["Lookforward%s" % str(i+1)] = ts[

"Lookforward%s" % str(i+1)

].pct_change()*100.0

ts.dropna(inplace=True)

# Determine if the stock has gone up at least by

# ’up_down_factor’ x ’percent_factor’ and down no more

# then ’percent_factor’

up = up_down_factor*percent_factor

down = percent_factor

# Create the list of True/False entries for each date

# as to whether the up/down logic is true

down_cols = [

ts["Lookforward%s" % str(i+1)] > -down

for i in range(0, lookforward_minutes)

]

up_cols = [

ts["Lookforward%s" % str(i+1)] > up

for i in range(0, lookforward_minutes)

]

# Carry out the bitwise and, as well as bitwise or

# for the down and up logic

down_tot = down_cols[0]

for c in down_cols[1:]:

down_tot = down_tot & c

up_tot = up_cols[0]

for c in up_cols[1:]:

up_tot = up_tot | c

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!