Browse Source

使用走过的距离与实际的距离的比值

skyffire 1 year ago
parent
commit
527cc12524
1 changed files with 13 additions and 13 deletions
  1. 13 13
      src/symbol_filter.rs

+ 13 - 13
src/symbol_filter.rs

@@ -62,7 +62,7 @@ fn calc_rise_percentage(records: Value) -> Decimal {
 }
 
 // 计算 波动 / 价格变化值
-fn calc_volatility_div_price_diff(records: Value) -> Decimal {
+fn calc_volatility_div_price_diff(records: Value, rise_ratio: Decimal) -> Decimal {
     let records_array = records.as_array().unwrap();
 
     if records_array.len() < 2 {
@@ -71,19 +71,18 @@ fn calc_volatility_div_price_diff(records: Value) -> Decimal {
 
     let mut volatility = Decimal::ZERO;
     for record in records_array {
-        let record_high = Decimal::from_str(record["high"].as_str().unwrap().to_string().as_str()).unwrap();
-        let record_low = Decimal::from_str(record["low"].as_str().unwrap().to_string().as_str()).unwrap();
-        let volume = Decimal::from_str(record["volume"].as_str().unwrap().to_string().as_str()).unwrap();
-        let mid = (record_high + record_low) / Decimal::TWO;
+        let record_open = Decimal::from_str(record["open"].as_str().unwrap().to_string().as_str()).unwrap();
+        let record_close = Decimal::from_str(record["close"].as_str().unwrap().to_string().as_str()).unwrap();
+        let mid = (record_open + record_close) / Decimal::TWO;
 
-        volatility += if volume * mid <= Decimal::ONE {
-             Decimal::ZERO
-        } else {
-            (volume * mid).ln() * Decimal::ONE_HUNDRED * (record_high - record_low) / mid
-        }
+        volatility += Decimal::ONE_HUNDRED * (record_open - record_close).abs() / mid;
     }
 
-    let mut vdpd = volatility;
+    let mut vdpd = if rise_ratio.is_zero() {
+        volatility
+    } else {
+        volatility / rise_ratio
+    };
     vdpd.rescale(6);
 
     return vdpd;
@@ -235,10 +234,11 @@ pub async fn get_final_symbols(mode: &str, exchanges: &Vec<String>, minute_time_
             total_count_by_symbol = total_count_by_symbol + count_by_exchange;
 
             // 上涨幅度处理
-            rise[exchange] = json!(calc_rise_percentage(records_map[exchange][symbol].clone()));
+            let rise_ratio = calc_rise_percentage(records_map[exchange][symbol].clone());
+            rise[exchange] = json!(rise_ratio);
 
             // 波动 / 价格变化
-            vdpd[exchange] = json!(calc_volatility_div_price_diff(records_map[exchange][symbol].clone()));
+            vdpd[exchange] = json!(calc_volatility_div_price_diff(records_map[exchange][symbol].clone(), rise_ratio));
 
             // 振幅处理
             amp[exchange] = json!(calc_amplification_percentage(records_map[exchange][symbol].clone()));