Mariner Backtesting - IndexError

  • An IndexError means that you are trying to access an index of the list that do not exist.
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 661, in simulate
    context_collection.process_event(event, delivery_timestamp)
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/context.py", line 708, in process_event
    context.process_event(event, delivery_timestamp)
  File "/opt/anaconda/lib/python2.7/site-packages/tradesim/context.py", line 402, in process_event
    self.strategy.on_trade(event, self.market[event.symbol], self.order, self.service, self.account)
  File "job/Gr8Script3260d2b9719d4a3fa73d305c091473c8.py", line 61, in on_trade
    and ((self.dbars.close[-1]) <= (self.dbars.open[-1] - md.stat.atr*1.00)) 
IndexError: index -1 is out of bounds for axis 0 with size 0
Sample Broken Code
 bars = md.bars.daily(start=-6)

close = bars.close[6]   ### only 6 elements in list you are accessing the 7th
Sample Fixed Code
 bars = md.bars.daily(start=-6)

if len(bars.close) ==6:

    close = bars.close[6]  
Notes
  • This error occurs when you are trying to access an element that does not exist. Start counting at 0 then 1, 2, etc