Skip to content

Commit 4f2979b

Browse files
committed
修改BOLL算法
1 parent 5463f3e commit 4f2979b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/src/main/java/com/github/wangyiqian/stockchart/index/BollCalculator.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,24 @@ object BollCalculator: ICalculator {
5757

5858
sum += kEntity.getClosePrice()
5959

60-
var ma = sum / (pEnd - pFrom + 1)
61-
result[mbIdx][kEntityIdx] = ma
62-
if(pEnd - pFrom + 1 == n){
60+
if (pEnd - pFrom + 1 == n) {
61+
val ma = sum / n
62+
result[mbIdx][kEntityIdx] = ma
6363
sum -= input[pFrom].getClosePrice()
6464
pFrom += 1
65+
66+
var squareSum = 0f
67+
for (i in pEnd downTo pEnd - n + 1) {
68+
squareSum += (input[i].getClosePrice() - ma).pow(2)
69+
}
70+
val std = sqrt(squareSum / n)
71+
result[upIdx][kEntityIdx] = ma + k * std
72+
result[dnIdx][kEntityIdx] = ma - k * std
73+
} else {
74+
result[mbIdx][kEntityIdx] = null
75+
result[upIdx][kEntityIdx] = null
76+
result[dnIdx][kEntityIdx] = null
6577
}
66-
var squareSum = 0f
67-
for (i in pEnd downTo pFrom) {
68-
squareSum += (input[i].getClosePrice() - ma).pow(2)
69-
}
70-
val std = sqrt(squareSum / n)
71-
result[upIdx][kEntityIdx] = ma + k * std
72-
result[dnIdx][kEntityIdx] = ma - k * std
7378
}
7479
return result
7580
}

0 commit comments

Comments
 (0)