File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed
lib/src/main/java/com/github/wangyiqian/stockchart/index Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments