|
@@ -6,6 +6,7 @@ use rust_decimal::Decimal;
|
|
|
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
|
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
|
|
use rust_decimal_macros::dec;
|
|
use rust_decimal_macros::dec;
|
|
|
use serde_json::{json, Value};
|
|
use serde_json::{json, Value};
|
|
|
|
|
+use tracing::info;
|
|
|
use crate::db_connector::{get_simple_depths_json, get_trades_json};
|
|
use crate::db_connector::{get_simple_depths_json, get_trades_json};
|
|
|
use crate::params_utils::{get_str, parse_str_to_decimal};
|
|
use crate::params_utils::{get_str, parse_str_to_decimal};
|
|
|
use crate::server::{Response, SimpleDepth, Trade};
|
|
use crate::server::{Response, SimpleDepth, Trade};
|
|
@@ -183,26 +184,26 @@ pub fn generate_msv_by_trades(mut trades: Vec<Trade>, mills_back: Decimal, simpl
|
|
|
|
|
|
|
|
// 计算差值
|
|
// 计算差值
|
|
|
let diff = Decimal::ONE - flag_trade.price / next_trade.price;
|
|
let diff = Decimal::ONE - flag_trade.price / next_trade.price;
|
|
|
- total_right += diff * diff;
|
|
|
|
|
|
|
+ total_right += diff.abs();
|
|
|
|
|
|
|
|
sigma_index = sigma_index - 1;
|
|
sigma_index = sigma_index - 1;
|
|
|
}
|
|
}
|
|
|
- let mut sigma = if t_first == t_last {
|
|
|
|
|
- if sigma_index + 100 > index {
|
|
|
|
|
- Decimal::ZERO
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ let mut sigma = if sigma_index + 100 > index {
|
|
|
|
|
+ Decimal::ZERO
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if t_first == t_last {
|
|
|
let time_diff = dec!(0.001);
|
|
let time_diff = dec!(0.001);
|
|
|
- (Decimal::ONE / time_diff) + total_right
|
|
|
|
|
|
|
+ (Decimal::ONE / time_diff) * total_right
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let time_diff = (t_last - t_first) / Decimal::ONE_THOUSAND;
|
|
|
|
|
+ (Decimal::ONE / time_diff) * total_right
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- let time_diff = (t_last - t_first) / Decimal::ONE_THOUSAND;
|
|
|
|
|
- (Decimal::ONE / time_diff) + total_right
|
|
|
|
|
};
|
|
};
|
|
|
sigma.rescale(6);
|
|
sigma.rescale(6);
|
|
|
sigma_data.push(vec![trade.time, sigma]);
|
|
sigma_data.push(vec![trade.time, sigma]);
|
|
|
|
|
|
|
|
- let last_price = trade.price;
|
|
|
|
|
// ==================== 波动逻辑计算 ====================
|
|
// ==================== 波动逻辑计算 ====================
|
|
|
|
|
+ let last_price = trade.price;
|
|
|
let mut rate = Decimal::ONE_HUNDRED * (last_price - ref_price) / ref_price;
|
|
let mut rate = Decimal::ONE_HUNDRED * (last_price - ref_price) / ref_price;
|
|
|
rate.rescale(2);
|
|
rate.rescale(2);
|
|
|
// 去除小数位之后,可以忽略一些太小的波动,减少图表生成压力
|
|
// 去除小数位之后,可以忽略一些太小的波动,减少图表生成压力
|
|
@@ -288,11 +289,11 @@ pub fn generate_msv_by_trades(mut trades: Vec<Trade>, mills_back: Decimal, simpl
|
|
|
max_msv_data = msv_d;
|
|
max_msv_data = msv_d;
|
|
|
max_msv_qty_data = msv_qty_data;
|
|
max_msv_qty_data = msv_qty_data;
|
|
|
max_epr_data = epr_d;
|
|
max_epr_data = epr_d;
|
|
|
- }
|
|
|
|
|
- // 波动率sigma
|
|
|
|
|
- if max_sigma_data.abs() < sigma_d {
|
|
|
|
|
max_sigma_data = sigma_d;
|
|
max_sigma_data = sigma_d;
|
|
|
}
|
|
}
|
|
|
|
|
+ // // 波动率sigma
|
|
|
|
|
+ // if max_sigma_data.abs() < sigma_d {
|
|
|
|
|
+ // }
|
|
|
// 下标步近
|
|
// 下标步近
|
|
|
msv_index = msv_index + 1;
|
|
msv_index = msv_index + 1;
|
|
|
}
|
|
}
|
|
@@ -350,7 +351,13 @@ pub fn generate_msv_by_trades(mut trades: Vec<Trade>, mills_back: Decimal, simpl
|
|
|
final_epr_data.push(vec![index_timestamp, Decimal::ZERO]);
|
|
final_epr_data.push(vec![index_timestamp, Decimal::ZERO]);
|
|
|
final_volume_data.push(vec![index_timestamp, Decimal::ZERO]);
|
|
final_volume_data.push(vec![index_timestamp, Decimal::ZERO]);
|
|
|
|
|
|
|
|
- // 说明在这个时间范围内是有数据存在的,将推动行情的流动性放入副图
|
|
|
|
|
|
|
+ if final_sigma_data.len() > 0 {
|
|
|
|
|
+ final_sigma_data.push(final_sigma_data[final_sigma_data.len() - 1].clone());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ final_sigma_data.push(vec![index_timestamp, Decimal::ZERO]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 说明在这个时间范围内是有数据存在的,将各类副图放置完全
|
|
|
} else {
|
|
} else {
|
|
|
final_msv_data.push(vec![index_timestamp, max_msv_data, max_msv_qty_data]);
|
|
final_msv_data.push(vec![index_timestamp, max_msv_data, max_msv_qty_data]);
|
|
|
final_epr_data.push(vec![index_timestamp, max_epr_data]);
|
|
final_epr_data.push(vec![index_timestamp, max_epr_data]);
|
|
@@ -358,8 +365,9 @@ pub fn generate_msv_by_trades(mut trades: Vec<Trade>, mills_back: Decimal, simpl
|
|
|
let mut final_qty = max_msv_qty_data / Decimal::ONE_THOUSAND;
|
|
let mut final_qty = max_msv_qty_data / Decimal::ONE_THOUSAND;
|
|
|
final_qty.rescale(2);
|
|
final_qty.rescale(2);
|
|
|
final_volume_data.push(vec![index_timestamp, final_qty]);
|
|
final_volume_data.push(vec![index_timestamp, final_qty]);
|
|
|
|
|
+
|
|
|
|
|
+ final_sigma_data.push(vec![index_timestamp, max_sigma_data]);
|
|
|
}
|
|
}
|
|
|
- final_sigma_data.push(vec![index_timestamp, max_sigma_data]);
|
|
|
|
|
|
|
|
|
|
// ====================================== 时间步进处理 ======================================
|
|
// ====================================== 时间步进处理 ======================================
|
|
|
// 对时间进行步近
|
|
// 对时间进行步近
|