I want to call a function inside strategy object to output a list member in the object, but it fail with
TypeError: retrieveLog() missing 1 required positional argument: 'self'
Please enlighten me on how to do it properly?
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Create a Stratey
class simpleStrategy(bt.Strategy):
def log(self, txt, dt=None):
''' Logging function for this strategy'''
dt = dt or self.datas[0].datetime.date(0)
logLine = '%s, %s' % (dt.isoformat(), txt)
# LOG TO LIST INSTEAD OF PRINTING IT OUT
self.logStr.append(logLine)
def __init__(self):
# Keep a reference to the "close" line in the data[0] dataseries
self.dataclose = self.datas[0].close
# To keep track of log string
self.logStr = []
def next(self):
# log to list
self.log('test')
# PRINT THE LOG LIST
def retrieveLog(self):
print(self.logStr)
cerebro = bt.Cerebro()
# Add a strategy
cs = simpleStrategy
cerebro.addstrategy(cs)
# Add the Data Feed to Cerebro1
cerebro.adddata(bt.feeds.PandasData(dataname=theDf))
# Print out the starting conditions
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
# Run over everything
cerebro.run()
# Print out the final result
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
# -------------- ERROR ---------------------------------
# TypeError: retrieveLog() missing 1 required positional argument: 'self'
cs.retrieveLog()