问题描述
首先感谢您对像我这样的新人表现出的爱。
现在来看代码。
我有一段看似简单的代码,有人编写该代码用于计算价格的移动平均线,但要理解它并遵循它,我需要回答一个关于where 定义的问题。
def ma(Data,lookback,what,where):
for i in range(len(Data)):
try:
Data[i,where] = (Data[i - lookback + 1:i + 1,what].mean())
except IndexError:
pass
return Data
#1 The Data variable is the OHLC array
#2 The what variable is the closing price column
#3 The where variable is where to put the indicator
#4 The lookback variable is the moving average's period
但是说到#3,我不明白。 指标放在哪里是什么意思?我想计算数据,并使用该数据。我不想将指标放在任何地方,只是为了参考。
这是我想用作数据的数据框:
open high low close
hr
2021-02-01 01:00 32835.839519 33438.836060 32835.839519 33389.974454
2021-02-01 02:00 33400.422170 33663.000232 33260.343246 33569.816646
2021-02-01 03:00 33581.206956 33633.454861 33437.081539 33466.178320
2021-02-01 04:00 33473.881292 33680.926267 33473.881292 33512.310031
2021-02-01 05:00 33496.550836 33692.662741 33442.771302 33692.295982
2021-02-01 06:00 33674.363254 33931.304243 33372.640454 33372.640454
2021-02-01 07:00 33466.277250 33718.499099 33410.173005 33543.580113
2021-02-01 08:00 33691.622420 34155.668712 33577.491467 34155.668712
2021-02-01 09:00 34541.989582 34541.989582 34246.591606 34255.313422
2021-02-01 10:00 34254.311054 34318.042807 34009.930110 34043.516502
2021-02-01 11:00 34102.209535 34181.236131 33960.033182 34181.236131
2021-02-01 12:00 34196.688991 34196.688991 33677.872302 33677.872302
2021-02-01 13:00 33658.073761 33831.043558 33616.263612 33616.263612
2021-02-01 14:00 33506.144521 33698.288934 33298.355558 33458.379708
2021-02-01 15:00 33449.472954 33540.119075 33137.424801 33137.424801
2021-02-01 16:00 33129.661923 33444.487621 33129.661923 33444.487621
2021-02-01 17:00 33427.510914 33966.758995 33328.452664 33966.758995
2021-02-01 18:00 33883.647812 33883.647812 33692.664177 33753.657270
2021-02-01 19:00 33568.840250 33904.003721 33568.840250 33817.161851
2021-02-01 20:00 33716.826906 33857.417730 33663.339958 33757.230256
2021-02-01 21:00 33608.964863 33692.950108 33508.713475 33553.086495
2021-02-01 22:00 33475.494546 33629.985564 33423.225607 33423.225607
2021-02-01 23:00 33396.069559 33614.188165 33361.882597 33405.990357
2021-02-02 00:00 33423.242711 33912.467287 33423.242711 33626.927090
2021-02-02 01:00 33578.032588 33578.032588 33470.631802 33470.631802
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)