繁体   English   中英

mac 上的 Visual Studio Code 使用 python 错误“syntax error: invalid syntax”在“cerebro = bt.Cerebro()”行

[英]Visual Studio Code on mac using python Error "syntax error: invalid syntax" at the line 'cerebro = bt.Cerebro()'

我正在使用 VSCode 和 python 使用 backtrader 进行一些回溯测试。 我刚开始学习教程,第一个测试代码在实例化 cerebro 时似乎出现了语法错误。 这是代码:

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()

当我使用“在终端中运行 Python 文件”运行文件时,出现错误

File "log.py", line 16
cerebro = bt.Cerebro()
      ^
SyntaxError: invalid syntax

我试图寻找一个没有运气的解决方案。 我将解释器更改为使用python3.7,安装pylint,更新pip。 重新启动笔记本电脑,什么都没有。 帮助。

在 def next() self.log() 不匹配(添加一个)到 self.log('Close: {}'.format(self.dataclose[0]) 的末尾

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM