Skip to content

Commit

Permalink
修改BOLL算法
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Sep 1, 2022
1 parent 5463f3e commit 94c2883
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ allprojects {
```
```groovy
dependencies {
implementation 'com.github.wangyiqian:StockChart:1.1.8'
implementation 'com.github.wangyiqian:StockChart:1.1.9'
}
```
### 2. 布局文件加入StockChart布局
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,24 @@ object BollCalculator: ICalculator {

sum += kEntity.getClosePrice()

var ma = sum / (pEnd - pFrom + 1)
result[mbIdx][kEntityIdx] = ma
if(pEnd - pFrom + 1 == n){
if (pEnd - pFrom + 1 == n) {
val ma = sum / n
result[mbIdx][kEntityIdx] = ma
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
2 changes: 1 addition & 1 deletion samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ dependencies {
implementation 'com.google.android:flexbox:2.0.1'

// implementation project(':lib')
implementation 'com.github.wangyiqian:StockChart:1.1.8'
implementation 'com.github.wangyiqian:StockChart:1.1.9'
}

0 comments on commit 94c2883

Please sign in to comment.