I'm using VSCode with python to do some backtesting using backtrader. I just starting following a tutorial and the first test code seems to comeup with a syntax error when instantiating cerebro. Here is the code:
import backtrader as bt
from datetime import datetime
class LogClass(bt.Strategy):
def __init__(self):
self.dataclose = self.datas[0].close
def log(next, txt, dt=None):
dt = dt or self.datas[0].datetime.date(0)
print(f'{dt} {txt}')
def next(self):
self.log('Close: {}'.format(self.dataclose[0])
cerebro = bt.Cerebro()
data = bt.feeds.YahooFinanceData(dataname=LogClose.params.ticker,
fromdate= LogClose.params.fromDate,
todate= LogClose.params.toDate)
cerebro.adddata(data)
cerebro.addstrategy(LogClose)
cerebro.run()
when I run the file using 'Run Python File in Terminal', I get the error
File "log.py", line 16
cerebro = bt.Cerebro()
^
SyntaxError: invalid syntax
I tried searching for a solution with no luck. I changed the interpreter to use python3.7, installed pylint, update pip. restarted the laptop, nothing. Help.
in def next() self.log() unmatched ( add a ) to the end of self.log('Close: {}'.format(self.dataclose[0])