我正在尝试创建一个函数来计算Heikin Ashi candles (用于金融分析)。我的indicators.py文件如下所示
from pandas import DataFrame, Series
def heikinashi(dataframe):
open = dataframe['open']
high = dataframe['high']
low = dataframe['low']
close = dataframe['close']
ha_close = 0.25 * (open + high + low + close)
ha_open = 0.5 * (open.shift(1) + close.shift(1))
ha_low = max(high, ha_open, ha_close)
ha_high = min(low, ha_open, ha_close)
return dataframe, ha_close, ha_open, ha_low, ha_high在我的主脚本中,我试图调用这个函数来最有效地返回这四个数据帧: ha_close、ha_open、ha_low和ha_high
我的主脚本看起来像这样:
import indicators as ata
ha_close, ha_open, ha_low, ha_high = ata.heikinashi(dataframe)
dataframe['ha_close'] = ha_close(dataframe)
dataframe['ha_open'] = ha_open(dataframe)
dataframe['ha_low'] = ha_low(dataframe)
dataframe['ha_high'] = ha_high(dataframe)但是由于某种奇怪的原因,我找不到数据帧,执行此操作的最有效方法是什么?代码明智,调用次数最少
我希望dataframe‘’ha_close‘等返回正确的数据,如函数所示
感谢您的任何建议
谢谢!
发布于 2021-05-27 17:52:28
在heikinashi()中,您将返回五个元素dataframe和ha_*,然而,在您的主脚本中,您仅将返回值分配给了四个变量。
尝试将主脚本更改为:
dataframe, ha_close, ha_open, ha_low, ha_high = ata.heikinashi(dataframe)除此之外,你传递给heikinashi()的dataframe看起来并没有在任何地方定义。
https://stackoverflow.com/questions/67710134
复制相似问题