鉴于以下情况:
toy = pd.DataFrame({
'price': [100, 103, 107, 105, 99, 96, 98, 103],
'barrier': [102, 102, 102,102,102,102, 102, 102],
'date': ['2020-02-28', '2020-03-01', '2020-03-02','2020-03-03', '2020-03-04', '2020-
03-05', '2020-03-06', '2020-03-07']})
toy['date'] = pd.to_datetime(toy['date']) #just make datetime obj
toy['rets'] = np.log(toy['price']/toy['price'].shift(1))
toy['ret_cum'] = toy['rets'].cumsum()
toy['loop'] = [0, 103, 0, 0, 99, 0, 0, 103] #some signal
toy['inten'] = 0.0 #initialize
我希望toy['inten']
在循环为99时为max(toy['ret_cum'].iloc[1,4])
(即0.067..),然后在循环为103时为min(toy['ret_cum'].iloc[5,7])
(即-0.0408),依此类推
更一般地说,np.where(toy['loop'] != 0)
产生(1,4,7)…我想检查在间隔1到4,然后是5到7之间达到的最大水平,以此类推
好吧,这可能有用。它在最小值和最大值之间交替,因为没有提供其背后的特定标准
输出-
相关问题 更多 >
编程相关推荐