Python代码import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom pandas_datareader import data as wbstock='3988.HK'df = wb.DataReader(stock,data_source='yahoo',start='2018-07-01')rsi_period = 14chg = df['Close'].diff(1)gain = chg.mask(chg<0,0)df['Gain'] = gainloss = chg.mask(chg>0,0)df['Loss'] = lossavg_gain = gain.ewm(com = rsi_period-1,min_periods=rsi_period).mean()avg_loss = loss.ewm(com = rsi_period-1,min_periods=rsi_period).mean()df['Avg Gain'] = avg_gaindf['Avg Loss'] = avg_lossrs = abs(avg_gain/avg_loss)rsi = 100-(100/(1+rs))df['RSI'] = rsidf.reset_index(inplace=True)df在这种情况下,我想创建一个新列“14 个交易日内的最大收盘价”。“14 个交易日内的最大收盘价”=接下来 14 天内的最大“收盘价”。例如,在第 0 行,数据范围应该是从第 1 行到第 15 行,“14 个交易日内的最大收盘价”= 3.86
添加回答
举报
0/150
提交
取消