在给定一系列价格数据的情况下,我想找到股票的最大可能回报.鉴于您只能以未来的价格出售,我认为我需要在每一行上设置最大的未来价格:
def maxf(idx):
return prc[idx:].bid.max()
prc['MaxF'] = prc.index.map(lambda x: maxf(x))
Run Code Online (Sandbox Code Playgroud)
这段代码确实有效,但需要比pandas.cummax()更长的时间.是否有直接的矢量方式来编码?