Skip to content

Commit

Permalink
更新BOLL算法
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Aug 31, 2022
1 parent 4b27618 commit ad2f169
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,19 @@ object BollCalculator: ICalculator {

sum += kEntity.getClosePrice()

if (pEnd - pFrom + 1 == n) {
val ma = sum / n
result[mbIdx][kEntityIdx] = ma
var ma = sum / (pEnd - pFrom + 1)
result[mbIdx][kEntityIdx] = ma
if(pEnd - pFrom + 1 == n){
sum -= input[pFrom].getClosePrice()
pFrom += 1

var squareSum = 0f
for (i in pEnd downTo pEnd - n + 1) {
squareSum += (input[i].getClosePrice() - ma).pow(2)
}
val std = sqrt(squareSum / n)
result[upIdx][kEntityIdx] = ma + k * std
result[dnIdx][kEntityIdx] = ma - k * std
} else {
result[mbIdx][kEntityIdx] = null
result[upIdx][kEntityIdx] = null
result[dnIdx][kEntityIdx] = null
}
var squareSum = 0f
for (i in pEnd downTo pFrom) {
squareSum += (input[i].getClosePrice() - ma).pow(2)
}
val std = sqrt(squareSum / n)
result[upIdx][kEntityIdx] = ma + k * std
result[dnIdx][kEntityIdx] = ma - k * std
}
return result
}
Expand Down

0 comments on commit ad2f169

Please sign in to comment.