假设我们还有另一个包含财务数据的数据框:
timestamp,close,security_code,volume,bid_volume,ask_volume
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.383985+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.384040+00:00,4968.5,ES,1,1,0
2024-02-05 01:00:01.385840+00:00,4968.5,ES,2,0,2
2024-02-05 01:00:01.385840+00:00,4968.5,ES,1,0,1
2024-02-05 01:00:01.385840+00:00,4968.5,ES,1,0,1
2024-02-05 01:00:01.385840+00:00,4968.5,ES,1,0,1
2024-02-05 01:00:01.385840+00:00,4968.5,ES,2,0,2
人们可以像这样计算 POC(控制点,交易最多合约的地方)
def poc(self, df):
""" Calculate the POC. """
return df['close'].expanding().agg({'poc': lambda s:mode(s)[0]})['poc']
然而,这没有考虑体积。如果该特定水平上的交易量较大,则应考虑到这一点。如何mode
相应地改变/lambda?
要考虑到卷,您需要进行分组
close
并求和:返回
更新:添加滚动窗口
为此,您需要确定最小开始时间和最大结束时间,并准备以每个 x 分钟的块(窗口)循环遍历此范围(此处我选择 5)。在每个循环中,乘以收盘价并将每个价格的所有交易量相加。
这会给