-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleRunner.kt
264 lines (233 loc) · 11.7 KB
/
ExampleRunner.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package velkonost.technical.analysis.example
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.api.cast
import org.jetbrains.kotlinx.dataframe.api.getColumn
import org.jetbrains.kotlinx.dataframe.io.ColType
import org.jetbrains.kotlinx.dataframe.io.readCSV
import velkonost.technical.analysis.example.items.CsvColumn
import velkonost.technical.analysis.indicator.base.Indicator
import velkonost.technical.analysis.indicator.base.IndicatorName
import velkonost.technical.analysis.indicator.momentum.*
import velkonost.technical.analysis.indicator.momentum.ppo.Ppo
import velkonost.technical.analysis.indicator.momentum.ppo.PpoHist
import velkonost.technical.analysis.indicator.momentum.ppo.PpoSignal
import velkonost.technical.analysis.indicator.momentum.pvo.Pvo
import velkonost.technical.analysis.indicator.momentum.pvo.PvoHist
import velkonost.technical.analysis.indicator.momentum.pvo.PvoSignal
import velkonost.technical.analysis.indicator.momentum.stoch.Stoch
import velkonost.technical.analysis.indicator.momentum.stoch.StochSignal
import velkonost.technical.analysis.indicator.momentum.stochrsi.StochRsi
import velkonost.technical.analysis.indicator.momentum.stochrsi.StochRsiD
import velkonost.technical.analysis.indicator.momentum.stochrsi.StochRsiK
import velkonost.technical.analysis.indicator.other.CumulativeReturnIndicator
import velkonost.technical.analysis.indicator.other.DailyLogReturnIndicator
import velkonost.technical.analysis.indicator.other.DailyReturnIndicator
import velkonost.technical.analysis.indicator.trend.DpoIndicator
import velkonost.technical.analysis.indicator.trend.MassIndex
import velkonost.technical.analysis.indicator.trend.STCIndicator
import velkonost.technical.analysis.indicator.trend.TrixIndicator
import velkonost.technical.analysis.indicator.trend.aroon.AroonDown
import velkonost.technical.analysis.indicator.trend.aroon.AroonIndicator
import velkonost.technical.analysis.indicator.trend.aroon.AroonUp
import velkonost.technical.analysis.indicator.trend.ema.EmaFast
import velkonost.technical.analysis.indicator.trend.ema.EmaSlow
import velkonost.technical.analysis.indicator.trend.ichimoku.IchimokuA
import velkonost.technical.analysis.indicator.trend.ichimoku.IchimokuB
import velkonost.technical.analysis.indicator.trend.ichimoku.IchimokuBaseLine
import velkonost.technical.analysis.indicator.trend.ichimoku.IchimokuConversionLine
import velkonost.technical.analysis.indicator.trend.kst.Kst
import velkonost.technical.analysis.indicator.trend.kst.KstDiff
import velkonost.technical.analysis.indicator.trend.kst.KstSignal
import velkonost.technical.analysis.indicator.trend.macd.Macd
import velkonost.technical.analysis.indicator.trend.macd.MacdDiff
import velkonost.technical.analysis.indicator.trend.macd.MacdSignal
import velkonost.technical.analysis.indicator.trend.sma.SmaFast
import velkonost.technical.analysis.indicator.trend.sma.SmaSlow
import velkonost.technical.analysis.indicator.trend.vortex.VortexDiff
import velkonost.technical.analysis.indicator.trend.vortex.VortexNegative
import velkonost.technical.analysis.indicator.trend.vortex.VortexPositive
import velkonost.technical.analysis.indicator.volatility.AverageTrueRange
import velkonost.technical.analysis.indicator.volatility.UlcerIndex
import velkonost.technical.analysis.indicator.volatility.bollingerBands.*
import velkonost.technical.analysis.indicator.volatility.donchianChannel.*
import velkonost.technical.analysis.indicator.volatility.keltnerChannel.*
import velkonost.technical.analysis.indicator.volume.*
import java.io.File
import java.io.FileNotFoundException
import java.math.BigDecimal
import java.nio.file.Paths
object ExampleRunner {
fun start(
resultFilePath: String = "/results.csv",
) {
val inputStream = this::class.java.getResourceAsStream(resultFilePath)
?: throw FileNotFoundException("Ресурс '$resultFilePath' не найден.")
val dataframe = DataFrame.readCSV(
stream = inputStream,
colTypes = CsvColumn.entries.associate { it.name to it.type }
+ IndicatorName.entries.associate { it.title to ColType.BigDecimal }
)
val highColumn: DataColumn<BigDecimal> = dataframe.getColumn(CsvColumn.High.name).cast()
val closeColumn: DataColumn<BigDecimal> = dataframe.getColumn(CsvColumn.Close.name).cast()
val lowColumn: DataColumn<BigDecimal> = dataframe.getColumn(CsvColumn.Low.name).cast()
val volumeColumn: DataColumn<BigDecimal> = dataframe.getColumn(CsvColumn.Volume_BTC.name).cast()
val indicators = mutableListOf<Indicator>()
indicators.testVolume(highColumn, closeColumn, lowColumn, volumeColumn)
indicators.testVolatility(highColumn, closeColumn, lowColumn)
indicators.testTrend(highColumn, closeColumn, lowColumn)
indicators.testMomentum(highColumn, closeColumn, lowColumn, volumeColumn)
indicators.testOther(highColumn, closeColumn, lowColumn, volumeColumn)
indicators.forEach { it.isEqual(dataframe) }
}
private fun MutableList<Indicator>.testVolume(
highColumn: DataColumn<BigDecimal>,
closeColumn: DataColumn<BigDecimal>,
lowColumn: DataColumn<BigDecimal>,
volumeColumn: DataColumn<BigDecimal>
) {
AccDistIndexIndicator(
high = highColumn,
close = closeColumn,
low = lowColumn,
volume = volumeColumn,
fillna = true
).also { add(it) }
OnBalanceVolumeIndicator(
close = closeColumn,
volume = volumeColumn
).also { add(it) }
ChaikinMoneyFlowIndicator(
high = highColumn,
low = lowColumn,
close = closeColumn,
volume = volumeColumn
).also { add(it) }
ForceIndexIndicator(
close = closeColumn,
volume = volumeColumn,
).also { add(it) }
EaseOfMovementIndicator(
high = highColumn,
low = lowColumn,
volume = volumeColumn
).also { add(it) }
SmaEaseOfMovementIndicator(
high = highColumn,
low = lowColumn,
volume = volumeColumn
).also { add(it) }
VolumePriceTrendIndicator(
close = closeColumn,
volume = volumeColumn,
fillna = true
).also { add(it) }
VolumeWeightedAveragePrice(
high = highColumn,
low = lowColumn,
close = closeColumn,
volume = volumeColumn
).also { add(it) }
MFIIndicator(
high = highColumn,
low = lowColumn,
close = closeColumn,
volume = volumeColumn,
).also { add(it) }
NegativeVolumeIndexIndicator(
close = closeColumn,
volume = volumeColumn
).also { add(it) }
}
private fun MutableList<Indicator>.testVolatility(
highColumn: DataColumn<BigDecimal>,
closeColumn: DataColumn<BigDecimal>,
lowColumn: DataColumn<BigDecimal>,
) {
BollingerBandsMavg(close = closeColumn).also { add(it) }
BollingerBandsHband(close = closeColumn).also { add(it) }
BollingerBandsLband(close = closeColumn).also { add(it) }
BollingerBandsWband(close = closeColumn).also { add(it) }
BollingerBandsPband(close = closeColumn).also { add(it) }
BollingerBandsHbandIndicator(close = closeColumn).also { add(it) }
BollingerBandsLbandIndicator(close = closeColumn).also { add(it) }
KeltnerChannelMband(highColumn, lowColumn, closeColumn).also { add(it) }
KeltnerChannelHband(highColumn, lowColumn, closeColumn).also { add(it) }
KeltnerChannelLband(highColumn, lowColumn, closeColumn).also { add(it) }
KeltnerChannelWband(highColumn, lowColumn, closeColumn).also { add(it) }
KeltnerChannelPband(highColumn, lowColumn, closeColumn).also { add(it) }
KeltnerChannelHbandIndicator(highColumn, lowColumn, closeColumn).also { add(it) }
KeltnerChannelLbandIndicator(highColumn, lowColumn, closeColumn).also { add(it) }
DonchianChannelLband(highColumn, lowColumn, closeColumn).also { add(it) }
DonchianChannelHband(highColumn, lowColumn, closeColumn).also { add(it) }
DonchianChannelMband(highColumn, lowColumn, closeColumn).also { add(it) }
DonchianChannelWband(highColumn, lowColumn, closeColumn).also { add(it) }
DonchianChannelPband(highColumn, lowColumn, closeColumn).also { add(it) }
AverageTrueRange(highColumn, lowColumn, closeColumn, window = 10).also { add(it) }
UlcerIndex(closeColumn).also { add(it) }
}
private fun MutableList<Indicator>.testTrend(
highColumn: DataColumn<BigDecimal>,
closeColumn: DataColumn<BigDecimal>,
lowColumn: DataColumn<BigDecimal>,
) {
Macd(closeColumn).also { add(it) }
MacdSignal(closeColumn).also { add(it) }
MacdDiff(closeColumn).also { add(it) }
SmaFast(closeColumn).also { add(it) }
SmaSlow(closeColumn).also { add(it) }
EmaFast(closeColumn).also { add(it) }
EmaSlow(closeColumn).also { add(it) }
VortexPositive(highColumn, lowColumn, closeColumn).also { add(it) }
VortexNegative(highColumn, lowColumn, closeColumn).also { add(it) }
VortexDiff(highColumn, lowColumn, closeColumn).also { add(it) }
TrixIndicator(closeColumn).also { add(it) }
MassIndex(highColumn, lowColumn).also { add(it) }
DpoIndicator(closeColumn).also { add(it) }
Kst(closeColumn).also { add(it) }
KstSignal(closeColumn).also { add(it) }
KstDiff(closeColumn).also { add(it) }
IchimokuConversionLine(highColumn, lowColumn).also { add(it) }
IchimokuBaseLine(highColumn, lowColumn).also { add(it) }
IchimokuA(highColumn, lowColumn).also { add(it) }
IchimokuB(highColumn, lowColumn).also { add(it) }
STCIndicator(closeColumn).also { add(it) }
AroonUp(highColumn, lowColumn).also { add(it) }
AroonDown(highColumn, lowColumn).also { add(it) }
AroonIndicator(highColumn, lowColumn).also { add(it) }
}
private fun MutableList<Indicator>.testMomentum(
highColumn: DataColumn<BigDecimal>,
closeColumn: DataColumn<BigDecimal>,
lowColumn: DataColumn<BigDecimal>,
volumeColumn: DataColumn<BigDecimal>
) {
RsiIndicator(closeColumn).also { add(it) }
StochRsi(closeColumn).also { add(it) }
StochRsiK(closeColumn).also { add(it) }
StochRsiD(closeColumn).also { add(it) }
TsiIndicator(closeColumn).also { add(it) }
UltimateOscillator(highColumn, lowColumn, closeColumn).also { add(it) }
Stoch(highColumn, lowColumn, closeColumn).also { add(it) }
StochSignal(highColumn, lowColumn, closeColumn).also { add(it) }
WilliamsRIndicator(highColumn, lowColumn, closeColumn).also { add(it) }
AwesomeOscillatorIndicator(highColumn, lowColumn).also { add(it) }
ROCIndicator(closeColumn).also { add(it) }
Ppo(closeColumn).also { add(it) }
PpoSignal(closeColumn).also { add(it) }
PpoHist(closeColumn).also { add(it) }
Pvo(volumeColumn).also { add(it) }
PvoSignal(volumeColumn).also { add(it) }
PvoHist(volumeColumn).also { add(it) }
}
private fun MutableList<Indicator>.testOther(
highColumn: DataColumn<BigDecimal>,
closeColumn: DataColumn<BigDecimal>,
lowColumn: DataColumn<BigDecimal>,
volumeColumn: DataColumn<BigDecimal>
) {
DailyReturnIndicator(closeColumn).also { add(it) }
DailyLogReturnIndicator(closeColumn).also { add(it) }
CumulativeReturnIndicator(closeColumn).also { add(it) }
}
}