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.

415

)

)

self.invested = "long"

elif et > sqrt_Qt:

# Short Entry

print("SHORT: %s" % event.time)

self.cur_hedge_qty = int(

floor(self.qty*self.theta[0])

)

self.events_queue.put(

SignalEvent(

self.tickers[1], "SLD", self.qty

)

)

self.events_queue.put(

SignalEvent(

self.tickers[0], "BOT",

self.cur_hedge_qty

)

)

self.invested = "short"

# If we are in the market...

if self.invested is not None:

if self.invested == "long" and et > -sqrt_Qt:

print("CLOSING LONG: %s" % event.time)

self.events_queue.put(

SignalEvent(

self.tickers[1],

"SLD", self.qty

)

)

self.events_queue.put(

SignalEvent(

self.tickers[0],

"BOT", self.cur_hedge_qty

)

)

self.invested = None

elif self.invested == "short" and et < sqrt_Qt:

print("CLOSING SHORT: %s" % event.time)

self.events_queue.put(

SignalEvent(

self.tickers[1],

"BOT", self.qty

)

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

Saved successfully!

Ooh no, something went wrong!