Last active
August 26, 2020 15:03
-
-
Save lonelyleaf/7b736c926c0dd31037cab3d81bc994f3 to your computer and use it in GitHub Desktop.
kotlin+中文变量
This file contains hidden or 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
class 放量下跌Params : RuleParams() { | |
var 下跌天数: Int = 3 | |
var 跌幅: Double = 0.07 | |
var 放量幅度: Double = 0.15 | |
} | |
class 放量下跌Rule : IRule<RuleResult, 放量下跌Params>() { | |
override fun run(request: RuleRunRequest, | |
params: 放量下跌Params, | |
stockBasic: StockBasicsEntity, | |
history: List<DailyEntity>): RuleResult? { | |
val markArea = ArrayList<MarkArea>() | |
for (i in params.下跌天数 until history.size) { | |
val result = 连续下跌且放量(history, i, params) | |
if (result.matched) { | |
val date = history[i].tradeDate!! | |
markArea.add(MarkArea(history[i - params.下跌天数].tradeDate!!, date, "放量下跌")) | |
} | |
} | |
return if (markArea.isNotEmpty()) { | |
RuleResult(RuleType.放量下跌, stockBasic, markAreas = markArea) | |
} else { | |
null | |
} | |
} | |
data class 连续下跌且放量Result( | |
val matched: Boolean | |
) | |
fun 连续下跌且放量(history: List<DailyEntity>, start: Int, params: 放量下跌Params): 连续下跌且放量Result { | |
for (i in 0 until params.下跌天数) { | |
val c1 = history[start - i].close | |
val c0 = history[start - i - 1].close | |
val v1 = history[start - i].vol | |
val v0 = history[start - i - 1].vol | |
val 满足跌幅 = (c1 - c0) / c0 <= -params.跌幅 | |
val 满足放量 = (v1 - v0) / v0 >= params.放量幅度 | |
if (满足跌幅 && 满足放量) { | |
} else { | |
return 连续下跌且放量Result(false) | |
} | |
} | |
return 连续下跌且放量Result(true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment