Explorar el Código

公平价格(仿真)以及它的ema,fix8

skyffire hace 10 meses
padre
commit
79ee2bfb1a
Se han modificado 1 ficheros con 11 adiciones y 1 borrados
  1. 11 1
      src/msv.rs

+ 11 - 1
src/msv.rs

@@ -113,7 +113,17 @@ pub fn generate_msv_by_trades(mut trades: Vec<Trade>, mills_back: Decimal, simpl
     let mut fair_price_simulation_ema = Decimal::ZERO;
 
     const GAMMA: Decimal = dec!(0.5);
-    let gamma_fair: Decimal = Decimal::ONE / Decimal::from_i64(trades.len().to_i64().unwrap() / (end_time - start_time)).unwrap();
+    // 多少分钟
+    let a = (end_time - start_time) / 1000;
+    // 多少笔
+    let b = trades.len().to_i64().unwrap();
+    // 一分钟多少笔
+    let c = if a == 0 {
+        b
+    } else {
+        b / a
+    };
+    let gamma_fair: Decimal = Decimal::ONE / Decimal::from_i64(c).unwrap();
 
     // ================== 计算每个点的具体波动率以及回溯幅度 ===================
     trades.sort_by(|a, b| Decimal::from_str(a.id.as_str()).unwrap().cmp(&Decimal::from_str(b.id.as_str()).unwrap()));