Skip to content

Commit

Permalink
Agent logging update: (#20)
Browse files Browse the repository at this point in the history
Made following changes:

  - Added `log_to_file=True` keyword argument to Agent class to allow suppression of logging of
individual agent events to file for speed reasons.
  - Added log_orders=None option to TradingAgent as a shorthand for
log_orders=False and log_to_file=False.
  - Updated relevant (tutorial) configs.

Co-authored-by: Danial Dervovic <[email protected]>
  • Loading branch information
ddervs and ddervs authored Jul 9, 2020
1 parent 5d343fe commit 7d56876
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions agent/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Agent:

def __init__ (self, id, name, type, random_state):
def __init__ (self, id, name, type, random_state, log_to_file=True):

# ID must be a unique number (usually autoincremented).
# Name is for human consumption, should be unique (often type + number).
Expand All @@ -16,6 +16,7 @@ def __init__ (self, id, name, type, random_state):
self.id = id
self.name = name
self.type = type
self.log_to_file = log_to_file
self.random_state = random_state

if not random_state:
Expand Down Expand Up @@ -89,7 +90,7 @@ def kernelTerminating (self):

# If this agent has been maintaining a log, convert it to a Dataframe
# and request that the Kernel write it to disk before terminating.
if self.log:
if self.log and self.log_to_file:
dfLog = pd.DataFrame(self.log)
dfLog.set_index('EventTime', inplace=True)
self.writeLog(dfLog)
Expand Down
7 changes: 6 additions & 1 deletion agent/TradingAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ def __init__(self, id, name, type, random_state=None, starting_cash=100000, log_
self.mkt_open = None
self.mkt_close = None

# Log all order activity?
# Log order activity?
self.log_orders = log_orders

# Log all activity to file?
if log_orders is None:
self.log_orders = False
self.log_to_file = False

# Store starting_cash in case we want to refer to it for performance stats.
# It should NOT be modified. Use the 'CASH' key in self.holdings.
# 'CASH' is always in cents! Note that agents are limited by their starting
Expand Down
2 changes: 1 addition & 1 deletion config/exp_agent_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
LimitOrder.silent_mode = not args.verbose

exchange_log_orders = True
log_orders = False
log_orders = None
book_freq = 0

simulation_start_time = dt.datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion config/rmsc03.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
LimitOrder.silent_mode = not args.verbose

exchange_log_orders = True
log_orders = False
log_orders = None
book_freq = 0

simulation_start_time = dt.datetime.now()
Expand Down

0 comments on commit 7d56876

Please sign in to comment.