Mariner Backtesting - AttributeError
- Attribute errors in Python are generally raised when you try to access or call an attribute that a particular object type does not possess.
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 417, in process_event
self.strategy.on_minute_bar(event, self.market, self.order, self.service, self.account, self.market.bar)
File "job/strat_any_hack_mid_single_instance.py", line 758, in on_minute_bar
self.historical_data[symbol]['price'] = list(self.historical_minutes.close)
AttributeError: 'dict' object has no attribute 'close'
Sample Broken Code
class Triangle(object):
def __init__(self, angle1, angle2, angle3):
self.self = self
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3
number_of_sides = 3
def check_angles(self):
if self.angle1+self.angle2+self.angle3 == 180:
return True
else:
return False
my_triangle = Triangle(90,30,60)
print my_triangle.number_of_sides
print my_triangle.check_angles()
Sample Fixed Code
class Triangle(object):
def __init__(self, angle1, angle2, angle3):
self.self = self
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3
number_of_sides = 3
def check_angles(self):
if self.angle1+self.angle2+self.angle3 == 180:
return True
else:
return False
my_triangle = Triangle(90,30,60)
print my_triangle.number_of_sides
print my_triangle.check_angles()
Notes
- This issue could be as simple as your whitespace being off or when something is not named correctly.