calculate_shannon_entropy_change
描述
计算价格变化后的香农熵变
函数签名
calculate_shannon_entropy_change(exchtime, order, volume, price, window_seconds, top_k) -> None
参数
交易时间数组,纳秒时间戳,类型为float64
订单机构ID数组,类型为int64
成交量数组,类型为float64
价格数组,类型为float64
计算香农熵变的时间窗口,单位为秒
如果提供,则只计算价格最高的k个点的熵变,默认为None(计算所有价格创新高点)
返回值
numpy.ndarray 香农熵变数组,类型为float64。只在价格创新高时计算熵变,其他时刻为NaN。 熵变值表示在价格创新高时,从当前时刻到未来window_seconds时间窗口内, 交易分布的变化程度。正值表示分布变得更分散,负值表示分布变得更集中。
示例:
import numpy as np from rust_pyfunc import calculate_shannon_entropy_change
创建测试数据
exchtime = np.array([1e9, 2e9, 3e9, 4e9], dtype=np.float64) # 时间戳(纳秒) order = np.array([100, 200, 300, 400], dtype=np.int64) # 机构ID volume = np.array([10.0, 20.0, 30.0, 40.0], dtype=np.float64) price = np.array([100.0, 102.0, 101.0, 103.0], dtype=np.float64)
计算3秒窗口的香农熵变
entropy_changes = calculate_shannon_entropy_change(exchtime, order, volume, price, 3.0) print(entropy_changes) # 只有价格为100.0、102.0和103.0的位置有非NaN值
示例
暂无示例
Python使用示例
import numpy as np
from rust_pyfunc import calculate_shannon_entropy_change
# 使用示例
# 请参考文档中的参数说明使用此函数