Kaynağa Gözat

试了一万个统计方法,还没有找到明显的可以过验证组的因子

skyffire 1 yıl önce
ebeveyn
işleme
ce4ce2ef5b
2 değiştirilmiş dosya ile 71 ekleme ve 16 silme
  1. BIN
      chart.png
  2. 71 16
      十面埋伏分析.js

BIN
chart.png


+ 71 - 16
十面埋伏分析.js

@@ -237,7 +237,7 @@ function statisticH(kLines, index) {
   return parseInt(NumKit.getSubFloat((rst / kCount - 50) * 10 + 100, 2))
 }
 
-// *******过去N天阴线数量,有一定关系
+// 过去N天阴线数量
 function statisticI(kLines, index) {
   let count = 0
   for (let i = index - 1; i >= index - 10; i--) {
@@ -266,15 +266,48 @@ function statisticJ(kLines, index) {
   return count
 }
 
+// 返回过去一共连续N天阳线
+function statisticK(kLines, index) {
+  let count = 0
+  for (let i = index - 1; i >= 0; i--) {
+    let kLine = kLines[i]
+
+    if (!kLines[i - 1]) break
+    if (kLine.Close < kLine.Open) break
+
+    count += 1
+  }
+
+  return count
+}
+
+// 返回过去一共N天涨幅超过M%
+function statisticL(kLines, index) {
+  let count = 0
+  for (let i = index - 1; i >= index - 10; i--) {
+    let kLine = kLines[i]
+
+    if (!kLines[i - 1]) break
+
+    if (100 * (kLine.Close - kLine.Open) / kLine.Open < 1) continue
+
+    count += 1
+  }
+
+  return count
+}
+
 let dataLeft = []
 let dataRight = []
-let dataY = [...Array(60).keys()]
+let tempLeft = []
+let tempRight = []
+let dataY = [...Array(30).keys()]
 function dragonAnalysis(btcKLines, kLinesMap, dragonMap, dayCount) {
   for (let symbol in dragonMap) {
     let kLines = kLinesMap[symbol]
     let index = kLines.length - (dayCount + 1)
 
-    let x = statisticJ(kLines, index)
+    let x = statisticL(kLines, index)
     let y = dragonMap[symbol].Profit
 
     // logger.info(
@@ -283,12 +316,35 @@ function dragonAnalysis(btcKLines, kLinesMap, dragonMap, dayCount) {
     //   // + `前30日平均振幅${statisticB(kLines, index)}%。`
     //   + `前30日平均(High - Close)${x}%。`
     // )
-    if (dataRight[x]) {
-      logger.info(x, dataRight[x], y)
-      dataRight[x] += y
+    // if (y > 0) {
+    //   if (dataRight[x]) {
+    //     dataRight[x] += y
+    //   } else {
+    //     dataRight[x] = y
+    //   }
+    // } else {
+    //   if (dataLeft[x]) {
+    //     dataLeft[x] += y
+    //   } else {
+    //     dataLeft[x] = y
+    //   }
+    // }
+    if (y > 0) {
+      if (tempRight[x]) {
+        tempRight[x] += y
+      } else {
+        tempRight[x] = y
+      }
     } else {
-      dataRight[x] = y
+      if (tempLeft[x]) {
+        tempLeft[x] += y
+      } else {
+        tempLeft[x] = y
+      }
     }
+    dataRight[x] = (tempLeft[x]?tempRight[x]/Math.abs(tempLeft[x]):0)
+    if (dataRight[x] > 5) dataRight[x] = 5
+    if (dataRight[x] < 0.8) dataRight[x] = 0.8
   }
 }
 
@@ -297,7 +353,7 @@ async function main() {
 
   const FIRST_FEW_DAYS = 1               // 第几天的数据,0表示今天,1表示昨天,2表示前天,以此类推
   const BUY_LIMIT_RATE = 0               // 从什么比例入场
-  const BAKE_TEST_DAYS = 10              // 一共回测多少天
+  const BAKE_TEST_DAYS = 300              // 一共回测多少天
 
 
   let btcKLines = kLinesMap['BTC_USDT']
@@ -347,16 +403,15 @@ async function main() {
     totalProfit = NumKit.getSubFloat(totalProfit, 2)
   }
 
-  // let dayProfit = NumKit.getSubFloat(totalProfit / BAKE_TEST_DAYS, 2)
-  // logger.info(`利润期望值总和:${totalProfit}%,平均日化${dayProfit}%。`)
-  // for (let symbol in fakeCountMap) {
-  //   let kLines = kLinesMap[symbol]
-  //   let startIndex = kLines.length - BAKE_TEST_DAYS
-  //   let endIndex = kLines.length - 1
-  //
-  //   logger.info(`${symbol} 盈${realCountMap[symbol]},亏${fakeCountMap[symbol]},大于5%涨幅的共有${statisticA(kLines, startIndex, endIndex)}日。`)
+  let dayProfit = NumKit.getSubFloat(totalProfit / BAKE_TEST_DAYS, 2)
+  logger.info(`利润期望值总和:${totalProfit}%,平均日化${dayProfit}%。`)
+  // let lastData = []
+  // for (let x = 0; x < dataRight.length; x++) {
+  //   lastData.push([x, dataRight[x]])
   // }
+
   let rst = 'option=' + JSON.stringify(ChartKit.printBar(dataY, dataLeft, dataRight), null, 2)
+  // let rst = 'option=' + JSON.stringify(ChartKit.printPointChart(lastData), null, 2)
   require('fs').writeFile('./data/option.txt', rst, 'utf8', (err) => {
     if (err) {
       logger.error('写入文件时发生错误:', err);