Mariner Backtesting - ZeroDivisionError

Exception Processing

  • A ZeroDivsionError means that you tried to divide by 0.
Sample Traceback
 Traceback (most recent call last):
  File "run_simulation.py", line 550, in <module>
    main(sys.argv[1:])
  File "run_simulation.py", line 525, in main
    results = simulator()
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/engine.py", line 542, in __call__
    return self.simulate()
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/engine.py", line 614, in simulate
    market_storage, l1_mapping, l1_state, context_collection = self.setup_simulation_day(event.day, event.start_time, event.end_time, old_context_collection=context_collection)
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/engine.py", line 1856, in setup_simulation_day
    context_collection = self.setup_context_collection(self.main_contexts, new_market_storage, old_context_collection=old_context_collection)
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/engine.py", line 1908, in setup_context_collection
    context_collection.start() #.start() calls each strategy's on_start()
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/context.py", line 557, in _collection_caller
    result = function(*args, **kwargs) or result
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/context.py", line 557, in _collection_caller
    result = function(*args, **kwargs) or result
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/context.py", line 312, in start
    self.strategy.on_start(self.market, self.order, self.service, self.account)
  File "job/CQ782fdb866dd341e99d267b1d6a4adc0b.py", line 61, in on_start
    self.target_shares = int(self.__class__.cash / (2 * self.__class__.upQuantile) / bar.close[0])
ZeroDivisionError: integer division or modulo by zero
Sample Broken Code
 glue = 7/0
print glue
Sample Fixed Code
 glue = 7/1
print glue
Notes
  • This is a simple problem to fix as all you have to do is just change the denominator from zero to another number.