|
|
@@ -1,6 +1,5 @@
|
|
|
import json
|
|
|
from decimal import Decimal, getcontext
|
|
|
-
|
|
|
import pandas as pd
|
|
|
import threading
|
|
|
from collections import deque
|
|
|
@@ -145,6 +144,31 @@ def objective_function(params, delta_max, log_lambda_hat_value, log_integral_phi
|
|
|
return np.sum(residuals)
|
|
|
|
|
|
|
|
|
+def calculate_delta_sum(gamma, sigma_squared, T_minus_t, k):
|
|
|
+ term1 = gamma * sigma_squared * T_minus_t
|
|
|
+ term2 = (2 / gamma) * np.log(1 + (gamma / k))
|
|
|
+ delta_sum = term1 + term2
|
|
|
+ return delta_sum
|
|
|
+
|
|
|
+
|
|
|
+def calculate_sigma_squared(prices, timestamps):
|
|
|
+ """
|
|
|
+ 计算 σ^2 的值
|
|
|
+ :param prices: 时间序列的价格数据
|
|
|
+ :param timestamps: 时间戳数组
|
|
|
+ :return: σ^2 的值
|
|
|
+ """
|
|
|
+ n = len(prices)
|
|
|
+ if n < 2:
|
|
|
+ return 0.0
|
|
|
+
|
|
|
+ time_diff = int(int((timestamps[-1] - timestamps[0]).total_seconds() * 1000) / 100)
|
|
|
+ price_diff_squared = [(prices[i] - prices[i - 1]) ** 2 for i in range(1, n)]
|
|
|
+ sigma_squared = np.sum(price_diff_squared) / time_diff
|
|
|
+
|
|
|
+ return sigma_squared
|
|
|
+
|
|
|
+
|
|
|
def process_depth_data():
|
|
|
global order_book_snapshots, trade_snapshots, spread_delta_snapshots
|
|
|
global k_initial, A_initial, S0
|
|
|
@@ -192,9 +216,13 @@ def process_depth_data():
|
|
|
|
|
|
if result.success:
|
|
|
A_initial, k_initial = result.x
|
|
|
+ # logger.info(f"Optimal k: {k_initial}, delta_max: {delta_max}")
|
|
|
|
|
|
- logger.info(f"Optimal k: {k_initial}, delta_max: {delta_max}")
|
|
|
- # else:
|
|
|
- # logger.error("Optimization failed")
|
|
|
+ # ========================== 计算 σ^2 ==========================
|
|
|
+ sigma_squared = calculate_sigma_squared(S_values, order_book_timestamps)
|
|
|
|
|
|
- # logger.info("log(λ(δ)): {}, log(∫ φ(k, ξ) dξ): {}".format(log_lambda_hat_value, log_integral_phi_value))
|
|
|
+ # ========================== 计算 δ^a + δ^b ==========================
|
|
|
+ gamma = 1.0
|
|
|
+ T_minus_t = 1.0
|
|
|
+ delta_sum = calculate_delta_sum(gamma, sigma_squared, T_minus_t, k_initial)
|
|
|
+ logger.info(f"δ^a + δ^b: {delta_sum}")
|