如何计算 python 中 stocks/cryptocurrencies 的收盘价和高低增量?
How to calculate close and high-low deltas of a stocks/cryptocurrencies in python?
我正在研究股票和加密货币的波动性。我的目标是计算它们的历史 high/low 和收盘增量。
在数学上,close delta 的公式是:(1 - close price/previous close price) and high/low delta formula is: (Difference between High and Low / Previous Close Price)
我想将结果合并到一个数据框中。我在下面试过:
for i in range(len(df)):
df['Closedelta'] = (1 - df['Close'].iloc[i] / df['Close'].iloc[i-1])
使用此代码,每一行我都得到相同的结果,output。
感谢任何帮助,谢谢。
在 for 循环中使用 df['Closedelta'] 为整个列设置 1 个值,您还应该指定要将值连接到的行。
将df['Closedelta']
改为df.iloc[i,5]
我正在研究股票和加密货币的波动性。我的目标是计算它们的历史 high/low 和收盘增量。
在数学上,close delta 的公式是:(1 - close price/previous close price) and high/low delta formula is: (Difference between High and Low / Previous Close Price)
我想将结果合并到一个数据框中。我在下面试过:
for i in range(len(df)):
df['Closedelta'] = (1 - df['Close'].iloc[i] / df['Close'].iloc[i-1])
使用此代码,每一行我都得到相同的结果,output。
感谢任何帮助,谢谢。
在 for 循环中使用 df['Closedelta'] 为整个列设置 1 个值,您还应该指定要将值连接到的行。
将df['Closedelta']
改为df.iloc[i,5]