-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c504f4
commit d10cb97
Showing
8 changed files
with
586 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
371 changes: 371 additions & 0 deletions
371
lib/src/main/java/com/github/wangyiqian/stockchart/childchart/rskchart/RsiChart.kt
Large diffs are not rendered by default.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
lib/src/main/java/com/github/wangyiqian/stockchart/childchart/rskchart/RsiChartConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.github.wangyiqian.stockchart.childchart.rskchart | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.Color | ||
import android.view.View | ||
import com.github.wangyiqian.stockchart.* | ||
import com.github.wangyiqian.stockchart.childchart.base.BaseChildChartConfig | ||
import com.github.wangyiqian.stockchart.childchart.base.HighlightLabelConfig | ||
import com.github.wangyiqian.stockchart.index.Index | ||
import com.github.wangyiqian.stockchart.listener.OnHighlightListener | ||
|
||
/** | ||
* @author wangyiqian E-mail: wangyiqian9891@gmail.com | ||
* @version 创建时间: 2023/3/9 | ||
*/ | ||
class RsiChartConfig( | ||
height: Int = DEFAULT_CHILD_CHART_HEIGHT, | ||
marginTop: Int = DEFAULT_CHILD_CHART_MARGIN_TOP, | ||
marginBottom: Int = DEFAULT_CHILD_CHART_MARGIN_BOTTOM, | ||
onHighlightListener: OnHighlightListener? = null, | ||
chartMainDisplayAreaPaddingTop: Float = DEFAULT_CHART_MAIN_DISPLAY_AREA_PADDING_TOP, | ||
chartMainDisplayAreaPaddingBottom: Float = DEFAULT_CHART_MAIN_DISPLAY_AREA_PADDING_BOTTOM, | ||
// 长按时高亮线左侧标签配置 | ||
var highlightLabelLeft: HighlightLabelConfig? = null, | ||
// 长按时高亮线右侧标签配置 | ||
var highlightLabelRight: HighlightLabelConfig? = null, | ||
// 指标线的颜色 | ||
var indexColors: List<Int> = listOf( | ||
Color.parseColor("#F5EC58"), | ||
Color.parseColor("#FF7CE5"), | ||
Color.parseColor("#9EC7FE"), | ||
Color.parseColor("#fb0606"), | ||
Color.parseColor("#a003fa"), | ||
Color.parseColor("#02cefa"), | ||
Color.parseColor("#02fa88"), | ||
Color.parseColor("#fa6b02") | ||
), | ||
// 指标线宽度 | ||
var lineStrokeWidth: Float = 3f, | ||
// 虚线颜色 | ||
var dashLineColor: Int = Color.LTGRAY, | ||
// 需要展示的指标配置 | ||
var index: Index? = Index.RSI(), | ||
// 指标头文字背景色 | ||
var indexStarterBgColor: Int = Color.TRANSPARENT, | ||
// 指标头文字背景水平内间距 | ||
var indexStarterBgPaddingHorizontal: Float = 0f, | ||
// 指标头文字右侧图标 | ||
var indexStarterRightIcon: Bitmap? = null, | ||
// 指标头文字点击事件 | ||
var indexStarterClickListener: ((View) -> Unit)? = null | ||
) : BaseChildChartConfig( | ||
height, | ||
marginTop, | ||
marginBottom, | ||
onHighlightListener, | ||
chartMainDisplayAreaPaddingTop, | ||
chartMainDisplayAreaPaddingBottom | ||
) |
13 changes: 13 additions & 0 deletions
13
lib/src/main/java/com/github/wangyiqian/stockchart/childchart/rskchart/RsiChartFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.wangyiqian.stockchart.childchart.rskchart | ||
|
||
import com.github.wangyiqian.stockchart.IStockChart | ||
import com.github.wangyiqian.stockchart.childchart.base.AbsChildChartFactory | ||
|
||
/** | ||
* @author wangyiqian E-mail: wangyiqian9891@gmail.com | ||
* @version 创建时间: 2023/3/9 | ||
*/ | ||
class RsiChartFactory(stockChart: IStockChart, childChartConfig: RsiChartConfig) : | ||
AbsChildChartFactory<RsiChartConfig>(stockChart, childChartConfig) { | ||
override fun createChart() = RsiChart(stockChart, childChartConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
lib/src/main/java/com/github/wangyiqian/stockchart/index/RSICalculator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.github.wangyiqian.stockchart.index | ||
|
||
import com.github.wangyiqian.stockchart.entities.FLAG_EMPTY | ||
import com.github.wangyiqian.stockchart.entities.IKEntity | ||
import com.github.wangyiqian.stockchart.entities.containFlag | ||
import kotlin.math.max | ||
import kotlin.math.min | ||
|
||
/** | ||
* @author wangyiqian E-mail: wangyiqian9891@gmail.com | ||
* @version 创建时间: 2023/3/9 | ||
*/ | ||
object RSICalculator : ICalculator { | ||
override fun calculate(param: String, input: List<IKEntity>): List<List<Float?>> { | ||
val paramList = param.split(",") | ||
val periodList = paramList.map { it.toInt() } | ||
val result = MutableList(periodList.size) { MutableList<Float?>(input.size) { 0f } } | ||
val preAvgRiseList = MutableList(periodList.size) { 0f } | ||
val preAvgDownList = MutableList(periodList.size) { 0f } | ||
var preNotEmptyEntityCount = 0 | ||
var preKEntity: IKEntity? = null | ||
input.forEachIndexed { kEntityIdx, kEntity -> | ||
if (kEntity.containFlag(FLAG_EMPTY)) { | ||
preNotEmptyEntityCount = 0 | ||
preKEntity = null | ||
periodList.forEachIndexed { periodListIdx, _ -> | ||
preAvgRiseList[periodListIdx] = 0f | ||
preAvgDownList[periodListIdx] = 0f | ||
result[periodListIdx][kEntityIdx] = null | ||
} | ||
return@forEachIndexed | ||
} | ||
|
||
periodList.forEachIndexed { periodListIdx, period -> | ||
val changeAmount = | ||
if (kEntityIdx == 0) 0f else kEntity.getClosePrice() - (preKEntity?.getClosePrice() | ||
?: 0f) | ||
val n = min(preNotEmptyEntityCount + 1, period) | ||
val preAvgRise = if (kEntityIdx == 0) 0f else preAvgRiseList[periodListIdx] | ||
val preAvgDown = if (kEntityIdx == 0) 0f else preAvgDownList[periodListIdx] | ||
val avgRise = | ||
((if (n == 1) 0f else (preAvgRise * (n - 1))) + max(changeAmount, 0f)) / n | ||
val avgDown = | ||
((if (n == 1) 0f else (preAvgDown * (n - 1))) + max(-changeAmount, 0f)) / n | ||
result[periodListIdx][kEntityIdx] = | ||
if (kEntityIdx == 0 || avgRise + avgDown == 0f) 0f else 100 * avgRise / (avgRise + avgDown) | ||
preAvgRiseList[periodListIdx] = avgRise | ||
preAvgDownList[periodListIdx] = avgDown | ||
} | ||
preKEntity = kEntity | ||
preNotEmptyEntityCount++ | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters