-1

我收到 NameError: name 'current_portfolio' is not defined

def initialize(context):
context.sym = symbol('xxx')
context.i = 0


def handle_data(context, data):

context.i += 1
if context.i < 60:
    return

sma1 = data.history(context.sym, 'price', 5, '1d').mean()
sma2 = data.history(context.sym, 'price', 60, '1d').mean()

current_price = data[context.sym].price
**current_position = current_portfolio.positions[symbol('xxx')].amount**
cash = context.portfolio.cash

如果有人可以提供帮助,我将不胜感激。

4

1 回答 1

0

您没有在此代码中的任何地方定义 current_portfolio,至少从显示的内容来看。

为了调用 current_portfolio 它必须在你调用它的上面的某个地方定义。

这就是您收到“未定义”错误的原因。

于 2020-02-02T03:21:05.527 回答