假设我们有如下所示的蜱虫数据
,timestamp,close,security_code,volume,bid_volume,ask_volume
2024-04-02 01:00:00.128123+00:00,2024-04-02 01:00:00.128123+00:00,18465.5,NQ,1,0,1
2024-04-02 01:00:00.128123+00:00,2024-04-02 01:00:00.128123+00:00,18465.5,NQ,1,0,1
2024-04-02 01:00:03.782064+00:00,2024-04-02 01:00:03.782064+00:00,18465.25,NQ,1,0,1
2024-04-02 01:00:04.112603+00:00,2024-04-02 01:00:04.112603+00:00,18465.0,NQ,1,0,1
2024-04-02 01:00:04.112603+00:00,2024-04-02 01:00:04.112603+00:00,18465.0,NQ,1,0,1
2024-04-02 01:00:04.112603+00:00,2024-04-02 01:00:04.112603+00:00,18464.75,NQ,1,0,1
2024-04-02 01:00:04.112603+00:00,2024-04-02 01:00:04.112603+00:00,18464.75,NQ,1,0,1
2024-04-02 01:00:05.759876+00:00,2024-04-02 01:00:05.759876+00:00,18464.5,NQ,1,0,1
2024-04-02 01:00:06.273686+00:00,2024-04-02 01:00:06.273686+00:00,18464.75,NQ,5,5,0
然后,可以如下计算电流高,电流低和最常点(poc),
import pandas as pd, matplotlib.pyplot as plt
from collections import defaultdict
df = pd.read_csv("csv/nq_out_daily.csv")
df.drop('Unnamed: 0', inplace=True, axis=1)
df['timestamp'] = pd.to_datetime(df['timestamp'])
df["timestamp"] = df['timestamp'].dt.strftime('%d-%m-%Y %H:%M:%S')
summary = {"high": [], "low": [], "poc": []}
dist = defaultdict(float)
current_high = current_low = None
for idx, (timestamp, tick, ask, bid) in enumerate(zip(df.timestamp, df.close, df.ask_volume, df.bid_volume)):
current_high = tick if (current_high is None or tick > current_high) else current_high
current_low = tick if (current_low is None or tick < current_low) else current_low
dist[tick] += 1
summary["high"].append(current_high)
summary["low"].append(current_low)
summary["poc"].append(max(dist, key=dist.get))
# plot the summary
fig = plt.figure()
x = range(len(summary["high"]))
plt.scatter(x, summary["high"], s=1)
plt.scatter(x, summary["low"], s=1)
plt.scatter(x, summary["poc"], s=1)
plt.legend(['high', 'low', 'poc'])
plt.savefig(f"distribution.png")
plt.close(fig)
Which would yield the following figure for today
现在,如何计算poc上下的第一个标准差?