Skip to content

Commit

Permalink
bug fixes for execution agents
Browse files Browse the repository at this point in the history
bug fixes for execution agents
  • Loading branch information
mamahfouz authored Nov 19, 2020
2 parents f81f2b4 + 025b4b2 commit c4bf157
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 833 deletions.
4 changes: 2 additions & 2 deletions agent/FinancialAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# exchanges to make this more useful later on.
class FinancialAgent(Agent):

def __init__(self, id, name, type, random_state):
def __init__(self, id, name, type, random_state, log_to_file=True):
# Base class init.
super().__init__(id, name, type, random_state)
super().__init__(id, name, type, random_state, log_to_file)

# Used by any subclass to dollarize an int-cents price for printing.
def dollarize (self, cents):
Expand Down
6 changes: 4 additions & 2 deletions agent/NoiseAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

class NoiseAgent(TradingAgent):

def __init__(self, id, name, type, symbol='IBM', starting_cash=100000, log_orders=False, random_state=None, wakeup_time = None ):
def __init__(self, id, name, type, symbol='IBM', starting_cash=100000,
log_orders=False, log_to_file=True, random_state=None, wakeup_time = None ):

# Base class init.
super().__init__(id, name, type, starting_cash=starting_cash, log_orders=log_orders, random_state=random_state)
super().__init__(id, name, type, starting_cash=starting_cash, log_orders=log_orders,
log_to_file=log_to_file, random_state=random_state)

self.wakeup_time = wakeup_time,

Expand Down
4 changes: 2 additions & 2 deletions agent/TradingAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
# implementing a strategy without too much bookkeeping.
class TradingAgent(FinancialAgent):

def __init__(self, id, name, type, random_state=None, starting_cash=100000, log_orders=False):
def __init__(self, id, name, type, random_state=None, starting_cash=100000, log_orders=False, log_to_file=True):
# Base class init.
super().__init__(id, name, type, random_state)
super().__init__(id, name, type, random_state, log_to_file)

# We don't yet know when the exchange opens or closes.
self.mkt_open = None
Expand Down
5 changes: 3 additions & 2 deletions agent/ValueAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class ValueAgent(TradingAgent):

def __init__(self, id, name, type, symbol='IBM', starting_cash=100000, sigma_n=10000,
r_bar=100000, kappa=0.05, sigma_s=100000,
lambda_a=0.005, log_orders=False, random_state=None):
lambda_a=0.005, log_orders=False, log_to_file=True, random_state=None):

# Base class init.
super().__init__(id, name, type, starting_cash=starting_cash, log_orders=log_orders, random_state=random_state)
super().__init__(id, name, type, starting_cash=starting_cash,
log_orders=log_orders, log_to_file=log_to_file, random_state=random_state)

# Store important parameters particular to the ZI agent.
self.symbol = symbol # symbol to trade
Expand Down
11 changes: 7 additions & 4 deletions agent/execution/ExecutionAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self, id, name, type, symbol, starting_cash,
self.trade = trade
self.log_orders = log_orders

self.state = 'AWAITING_WAKEUP'

def kernelStopping(self):
super().kernelStopping()
if self.trade:
Expand Down Expand Up @@ -79,17 +81,18 @@ def handleOrderAcceptance(self, currentTime, msg):
log_print('[---- {} - {} ----]: ACCEPTED QUANTITY : {}'.format(self.name, currentTime, accepted_qty))

def placeOrders(self, currentTime):
if currentTime == self.execution_time_horizon[-2]:
if currentTime.floor('1s') == self.execution_time_horizon[-2]:
self.placeMarketOrder(symbol=self.symbol, quantity=self.rem_quantity, is_buy_order=self.direction == 'BUY')
elif currentTime in self.execution_time_horizon[:-2]:
elif currentTime.floor('1s') in self.execution_time_horizon[:-2]:
bid, _, ask, _ = self.getKnownBidAsk(self.symbol)

if currentTime == self.start_time:
if currentTime.floor('1s') == self.start_time:
self.arrival_price = (bid + ask) / 2
log_print("[---- {} - {} ----]: Arrival Mid Price {}".format(self.name, currentTime,
self.arrival_price))

qty = self.schedule[pd.Interval(currentTime, currentTime+datetime.timedelta(minutes=1))]
qty = self.schedule[pd.Interval(currentTime.floor('1s'),
currentTime.floor('1s')+datetime.timedelta(minutes=1))]
price = ask if self.direction == 'BUY' else bid
self.placeLimitOrder(symbol=self.symbol, quantity=qty,
is_buy_order=self.direction == 'BUY', limit_price=price)
Expand Down
53 changes: 0 additions & 53 deletions agent/execution/PassiveAgent.py

This file was deleted.

2 changes: 1 addition & 1 deletion agent/execution/VWAPExecutionAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def generate_schedule(self):
def synthetic_volume_profile(date, freq):
mkt_open = pd.to_datetime(date.date()) + pd.to_timedelta('09:30:00')
mkt_close = pd.to_datetime(date.date()) + pd.to_timedelta('16:00:00')
day_range = pd.date_range(mkt_open, mkt_close, freq=f'{freq}s')
day_range = pd.date_range(mkt_open, mkt_close, freq=freq)

vol_profile = {}
for t, x in zip(day_range, range(int(-len(day_range) / 2), int(len(day_range) / 2), 1)):
Expand Down
154 changes: 0 additions & 154 deletions agent/execution/util.py

This file was deleted.

Loading

0 comments on commit c4bf157

Please sign in to comment.