假设我们还有另一个包含财务数据的数据框:
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?