高级程序员鉴定题:用java如何编写通达信SKDJ指标?
LOWV:=LLV(LOW,N);
HIGHV:=HHV(HIGH,N);
RSV:=EMA((CLOSE-LOWV)/(HIGHV-LOWV)*100,M);
K:EMA(RSV,M);
D:MA(K,M);
请教写个能测通的demo
结果如图,数据如下:
//000768 中航西飞 数据 2023年7月3日 SKDJ结果 K 92.81,D 90.63
//中航西飞最低价集合
public static List<BigDecimal> getLowPrices(){
List<BigDecimal> lowPrices = new ArrayList<>();
lowPrices.add(new BigDecimal(25.30));//2023-01-20
lowPrices.add(new BigDecimal(25.92));//2023-01-30
lowPrices.add(new BigDecimal(26.23));//2023-01-31
lowPrices.add(new BigDecimal(26.51));//2023-02-01
lowPrices.add(new BigDecimal(26.19));//2023-02-02
lowPrices.add(new BigDecimal(26.12));//2023-02-03
lowPrices.add(new BigDecimal(26.26));//2023-02-06
lowPrices.add(new BigDecimal(26.17));//2023-02-07
lowPrices.add(new BigDecimal(26.00));//2023-02-08
lowPrices.add(new BigDecimal(25.59));//2023-02-09
lowPrices.add(new BigDecimal(26.13));//2023-02-10
lowPrices.add(new BigDecimal(26.30));//2023-02-13
lowPrices.add(new BigDecimal(25.94));//2023-02-14
lowPrices.add(new BigDecimal(26.02));//2023-02-15
lowPrices.add(new BigDecimal(25.70));//2023-02-16
lowPrices.add(new BigDecimal(25.33));//2023-02-17
lowPrices.add(new BigDecimal(25.00));//2023-02-20
lowPrices.add(new BigDecimal(25.50));//2023-02-21
lowPrices.add(new BigDecimal(25.74));//2023-02-22
lowPrices.add(new BigDecimal(25.67));//2023-02-23
lowPrices.add(new BigDecimal(25.80));//2023-02-24
lowPrices.add(new BigDecimal(25.83));//2023-02-27
lowPrices.add(new BigDecimal(25.80));//2023-02-28
lowPrices.add(new BigDecimal(25.95));//2023-03-01
lowPrices.add(new BigDecimal(26.02));//2023-03-02
lowPrices.add(new BigDecimal(25.95));//2023-03-03
lowPrices.add(new BigDecimal(27.31));//2023-03-06
lowPrices.add(new BigDecimal(26.75));//2023-03-07
lowPrices.add(new BigDecimal(26.61));//2023-03-08
lowPrices.add(new BigDecimal(26.75));//2023-03-09
lowPrices.add(new BigDecimal(26.40));//2023-03-10
lowPrices.add(new BigDecimal(26.31));//2023-03-13
lowPrices.add(new BigDecimal(25.99));//2023-03-14
lowPrices.add(new BigDecimal(26.10));//2023-03-15
lowPrices.add(new BigDecimal(25.31));//2023-03-16
lowPrices.add(new BigDecimal(25.43));//2023-03-17
lowPrices.add(new BigDecimal(24.90));//2023-03-20
lowPrices.add(new BigDecimal(26.08));//2023-03-21
lowPrices.add(new BigDecimal(26.18));//2023-03-22
lowPrices.add(new BigDecimal(26.10));//2023-03-23
lowPrices.add(new BigDecimal(26.15));//2023-03-24
lowPrices.add(new BigDecimal(25.71));//2023-03-27
lowPrices.add(new BigDecimal(25.63));//2023-03-28
lowPrices.add(new BigDecimal(25.30));//2023-03-29
lowPrices.add(new BigDecimal(25.12));//2023-03-30
lowPrices.add(new BigDecimal(25.38));//2023-03-31
lowPrices.add(new BigDecimal(25.52));//2023-04-03
lowPrices.add(new BigDecimal(25.55));//2023-04-04
lowPrices.add(new BigDecimal(25.69));//2023-04-06
lowPrices.add(new BigDecimal(26.38));//2023-04-07
lowPrices.add(new BigDecimal(26.30));//2023-04-10
lowPrices.add(new BigDecimal(25.80));//2023-04-11
lowPrices.add(new BigDecimal(25.93));//2023-04-12
lowPrices.add(new BigDecimal(25.69));//2023-04-13
lowPrices.add(new BigDecimal(25.64));//2023-04-14
lowPrices.add(new BigDecimal(25.69));//2023-04-17
lowPrices.add(new BigDecimal(25.88));//2023-04-18
lowPrices.add(new BigDecimal(25.71));//2023-04-19
lowPrices.add(new BigDecimal(25.22));//2023-04-20
lowPrices.add(new BigDecimal(25.32));//2023-04-21
lowPrices.add(new BigDecimal(24.47));//2023-04-24
lowPrices.add(new BigDecimal(24.07));//2023-04-25
lowPrices.add(new BigDecimal(24.14));//2023-04-26
lowPrices.add(new BigDecimal(24.31));//2023-04-27
lowPrices.add(new BigDecimal(25.15));//2023-04-28
lowPrices.add(new BigDecimal(25.30));//2023-05-04
lowPrices.add(new BigDecimal(25.10));//2023-05-05
lowPrices.add(new BigDecimal(25.22));//2023-05-08
lowPrices.add(new BigDecimal(25.77));//2023-05-09
lowPrices.add(new BigDecimal(25.11));//2023-05-10
lowPrices.add(new BigDecimal(25.10));//2023-05-11
lowPrices.add(new BigDecimal(24.64));//2023-05-12
lowPrices.add(new BigDecimal(24.50));//2023-05-15
lowPrices.add(new BigDecimal(24.95));//2023-05-16
lowPrices.add(new BigDecimal(24.83));//2023-05-17
lowPrices.add(new BigDecimal(25.42));//2023-05-18
lowPrices.add(new BigDecimal(25.40));//2023-05-19
lowPrices.add(new BigDecimal(25.48));//2023-05-22
lowPrices.add(new BigDecimal(25.20));//2023-05-23
lowPrices.add(new BigDecimal(24.82));//2023-05-24
lowPrices.add(new BigDecimal(24.60));//2023-05-25
lowPrices.add(new BigDecimal(24.59));//2023-05-26
lowPrices.add(new BigDecimal(25.08));//2023-05-29
lowPrices.add(new BigDecimal(24.35));//2023-05-30
lowPrices.add(new BigDecimal(24.50));//2023-05-31
lowPrices.add(new BigDecimal(24.31));//2023-06-01
lowPrices.add(new BigDecimal(24.48));//2023-06-02
lowPrices.add(new BigDecimal(24.30));//2023-06-05
lowPrices.add(new BigDecimal(23.95));//2023-06-06
lowPrices.add(new BigDecimal(23.04));//2023-06-07
lowPrices.add(new BigDecimal(23.30));//2023-06-08
lowPrices.add(new BigDecimal(23.30));//2023-06-09
lowPrices.add(new BigDecimal(23.28));//2023-06-12
lowPrices.add(new BigDecimal(23.00));//2023-06-13
lowPrices.add(new BigDecimal(22.90));//2023-06-14
lowPrices.add(new BigDecimal(22.56));//2023-06-15
lowPrices.add(new BigDecimal(23.30));//2023-06-16
lowPrices.add(new BigDecimal(23.54));//2023-06-19
lowPrices.add(new BigDecimal(23.55));//2023-06-20
lowPrices.add(new BigDecimal(23.73));//2023-06-21
lowPrices.add(new BigDecimal(23.55));//2023-06-26
lowPrices.add(new BigDecimal(23.80));//2023-06-27
lowPrices.add(new BigDecimal(23.90));//2023-06-28
lowPrices.add(new BigDecimal(24.70));//2023-06-29
lowPrices.add(new BigDecimal(25.69));//2023-06-30
lowPrices.add(new BigDecimal(26.38));//2023-07-03
return lowPrices;
}
//中航西飞最高价集合
public static List<BigDecimal> getHighPrices(){
List<BigDecimal> highPrices = new ArrayList<>();
highPrices.add(new BigDecimal(25.80));//2023-01-20
highPrices.add(new BigDecimal(26.78));//2023-01-30
highPrices.add(new BigDecimal(26.77));//2023-01-31
highPrices.add(new BigDecimal(27.03));//2023-02-01
highPrices.add(new BigDecimal(27.17));//2023-02-02
highPrices.add(new BigDecimal(26.70));//2023-02-03
highPrices.add(new BigDecimal(26.73));//2023-02-06
highPrices.add(new BigDecimal(26.71));//2023-02-07
highPrices.add(new BigDecimal(26.50));//2023-02-08
highPrices.add(new BigDecimal(26.67));//2023-02-09
highPrices.add(new BigDecimal(26.65));//2023-02-10
highPrices.add(new BigDecimal(26.64));//2023-02-13
highPrices.add(new BigDecimal(26.36));//2023-02-14
highPrices.add(new BigDecimal(26.49));//2023-02-15
highPrices.add(new BigDecimal(26.52));//2023-02-16
highPrices.add(new BigDecimal(26.15));//2023-02-17
highPrices.add(new BigDecimal(25.64));//2023-02-20
highPrices.add(new BigDecimal(26.40));//2023-02-21
highPrices.add(new BigDecimal(26.24));//2023-02-22
highPrices.add(new BigDecimal(26.11));//2023-02-23
highPrices.add(new BigDecimal(26.65));//2023-02-24
highPrices.add(new BigDecimal(26.50));//2023-02-27
highPrices.add(new BigDecimal(26.18));//2023-02-28
highPrices.add(new BigDecimal(26.35));//2023-03-01
highPrices.add(new BigDecimal(26.60));//2023-03-02
highPrices.add(new BigDecimal(27.69));//2023-03-03
highPrices.add(new BigDecimal(28.26));//2023-03-06
highPrices.add(new BigDecimal(27.83));//2023-03-07
highPrices.add(new BigDecimal(27.56));//2023-03-08
highPrices.add(new BigDecimal(27.47));//2023-03-09
highPrices.add(new BigDecimal(27.12));//2023-03-10
highPrices.add(new BigDecimal(26.84));//2023-03-13
highPrices.add(new BigDecimal(26.86));//2023-03-14
highPrices.add(new BigDecimal(26.56));//2023-03-15
highPrices.add(new BigDecimal(26.25));//2023-03-16
highPrices.add(new BigDecimal(25.75));//2023-03-17
highPrices.add(new BigDecimal(25.74));//2023-03-20
highPrices.add(new BigDecimal(27.17));//2023-03-21
highPrices.add(new BigDecimal(26.72));//2023-03-22
highPrices.add(new BigDecimal(26.46));//2023-03-23
highPrices.add(new BigDecimal(26.39));//2023-03-24
highPrices.add(new BigDecimal(26.31));//2023-03-27
highPrices.add(new BigDecimal(26.18));//2023-03-28
highPrices.add(new BigDecimal(25.74));//2023-03-29
highPrices.add(new BigDecimal(25.58));//2023-03-30
highPrices.add(new BigDecimal(25.68));//2023-03-31
highPrices.add(new BigDecimal(26.13));//2023-04-03
highPrices.add(new BigDecimal(26.04));//2023-04-04
highPrices.add(new BigDecimal(26.84));//2023-04-06
highPrices.add(new BigDecimal(27.01));//2023-04-07
highPrices.add(new BigDecimal(26.87));//2023-04-10
highPrices.add(new BigDecimal(26.45));//2023-04-11
highPrices.add(new BigDecimal(26.32));//2023-04-12
highPrices.add(new BigDecimal(26.15));//2023-04-13
highPrices.add(new BigDecimal(25.88));//2023-04-14
highPrices.add(new BigDecimal(26.44));//2023-04-17
highPrices.add(new BigDecimal(26.78));//2023-04-18
highPrices.add(new BigDecimal(26.35));//2023-04-19
highPrices.add(new BigDecimal(25.77));//2023-04-20
highPrices.add(new BigDecimal(25.94));//2023-04-21
highPrices.add(new BigDecimal(25.40));//2023-04-24
highPrices.add(new BigDecimal(24.82));//2023-04-25
highPrices.add(new BigDecimal(24.71));//2023-04-26
highPrices.add(new BigDecimal(25.39));//2023-04-27
highPrices.add(new BigDecimal(25.86));//2023-04-28
highPrices.add(new BigDecimal(26.01));//2023-05-04
highPrices.add(new BigDecimal(25.51));//2023-05-05
highPrices.add(new BigDecimal(26.16));//2023-05-08
highPrices.add(new BigDecimal(26.85));//2023-05-09
highPrices.add(new BigDecimal(25.80));//2023-05-10
highPrices.add(new BigDecimal(25.55));//2023-05-11
highPrices.add(new BigDecimal(25.22));//2023-05-12
highPrices.add(new BigDecimal(25.40));//2023-05-15
highPrices.add(new BigDecimal(25.36));//2023-05-16
highPrices.add(new BigDecimal(25.96));//2023-05-17
highPrices.add(new BigDecimal(25.84));//2023-05-18
highPrices.add(new BigDecimal(25.98));//2023-05-19
highPrices.add(new BigDecimal(25.89));//2023-05-22
highPrices.add(new BigDecimal(25.77));//2023-05-23
highPrices.add(new BigDecimal(25.43));//2023-05-24
highPrices.add(new BigDecimal(25.10));//2023-05-25
highPrices.add(new BigDecimal(25.07));//2023-05-26
highPrices.add(new BigDecimal(26.08));//2023-05-29
highPrices.add(new BigDecimal(25.05));//2023-05-30
highPrices.add(new BigDecimal(25.13));//2023-05-31
highPrices.add(new BigDecimal(24.81));//2023-06-01
highPrices.add(new BigDecimal(24.75));//2023-06-02
highPrices.add(new BigDecimal(24.75));//2023-06-05
highPrices.add(new BigDecimal(24.38));//2023-06-06
highPrices.add(new BigDecimal(24.02));//2023-06-07
highPrices.add(new BigDecimal(23.57));//2023-06-08
highPrices.add(new BigDecimal(23.63));//2023-06-09
highPrices.add(new BigDecimal(23.63));//2023-06-12
highPrices.add(new BigDecimal(23.32));//2023-06-13
highPrices.add(new BigDecimal(23.25));//2023-06-14
highPrices.add(new BigDecimal(23.39));//2023-06-15
highPrices.add(new BigDecimal(23.71));//2023-06-16
highPrices.add(new BigDecimal(23.83));//2023-06-19
highPrices.add(new BigDecimal(24.10));//2023-06-20
highPrices.add(new BigDecimal(24.05));//2023-06-21
highPrices.add(new BigDecimal(24.20));//2023-06-26
highPrices.add(new BigDecimal(24.20));//2023-06-27
highPrices.add(new BigDecimal(24.93));//2023-06-28
highPrices.add(new BigDecimal(25.87));//2023-06-29
highPrices.add(new BigDecimal(26.88));//2023-06-30
highPrices.add(new BigDecimal(27.00));//2023-07-03
return highPrices;
}
//中航西飞收盘价集合
public static List<BigDecimal> getClosePrices(){
List<BigDecimal> closePrices = new ArrayList<>();
closePrices.add(new BigDecimal(25.62));//2023-01-20
closePrices.add(new BigDecimal(26.43));//2023-01-30
closePrices.add(new BigDecimal(26.75));//2023-01-31
closePrices.add(new BigDecimal(26.97));//2023-02-01
closePrices.add(new BigDecimal(26.34));//2023-02-02
closePrices.add(new BigDecimal(26.60));//2023-02-03
closePrices.add(new BigDecimal(26.41));//2023-02-06
closePrices.add(new BigDecimal(26.36));//2023-02-07
closePrices.add(new BigDecimal(26.06));//2023-02-08
closePrices.add(new BigDecimal(26.59));//2023-02-09
closePrices.add(new BigDecimal(26.28));//2023-02-10
closePrices.add(new BigDecimal(26.36));//2023-02-13
closePrices.add(new BigDecimal(26.18));//2023-02-14
closePrices.add(new BigDecimal(26.41));//2023-02-15
closePrices.add(new BigDecimal(25.94));//2023-02-16
closePrices.add(new BigDecimal(25.46));//2023-02-17
closePrices.add(new BigDecimal(25.57));//2023-02-20
closePrices.add(new BigDecimal(26.01));//2023-02-21
closePrices.add(new BigDecimal(25.94));//2023-02-22
closePrices.add(new BigDecimal(25.75));//2023-02-23
closePrices.add(new BigDecimal(26.30));//2023-02-24
closePrices.add(new BigDecimal(25.97));//2023-02-27
closePrices.add(new BigDecimal(26.18));//2023-02-28
closePrices.add(new BigDecimal(26.29));//2023-03-01
closePrices.add(new BigDecimal(26.12));//2023-03-02
closePrices.add(new BigDecimal(27.55));//2023-03-03
closePrices.add(new BigDecimal(27.75));//2023-03-06
closePrices.add(new BigDecimal(26.85));//2023-03-07
closePrices.add(new BigDecimal(27.33));//2023-03-08
closePrices.add(new BigDecimal(26.90));//2023-03-09
closePrices.add(new BigDecimal(26.52));//2023-03-10
closePrices.add(new BigDecimal(26.81));//2023-03-13
closePrices.add(new BigDecimal(26.49));//2023-03-14
closePrices.add(new BigDecimal(26.31));//2023-03-15
closePrices.add(new BigDecimal(25.35));//2023-03-16
closePrices.add(new BigDecimal(25.52));//2023-03-17
closePrices.add(new BigDecimal(25.42));//2023-03-20
closePrices.add(new BigDecimal(26.68));//2023-03-21
closePrices.add(new BigDecimal(26.26));//2023-03-22
closePrices.add(new BigDecimal(26.43));//2023-03-23
closePrices.add(new BigDecimal(26.30));//2023-03-24
closePrices.add(new BigDecimal(25.83));//2023-03-27
closePrices.add(new BigDecimal(25.73));//2023-03-28
closePrices.add(new BigDecimal(25.35));//2023-03-29
closePrices.add(new BigDecimal(25.53));//2023-03-30
closePrices.add(new BigDecimal(25.63));//2023-03-31
closePrices.add(new BigDecimal(26.10));//2023-04-03
closePrices.add(new BigDecimal(25.91));//2023-04-04
closePrices.add(new BigDecimal(26.75));//2023-04-06
closePrices.add(new BigDecimal(26.50));//2023-04-07
closePrices.add(new BigDecimal(26.42));//2023-04-10
closePrices.add(new BigDecimal(26.22));//2023-04-11
closePrices.add(new BigDecimal(26.20));//2023-04-12
closePrices.add(new BigDecimal(25.77));//2023-04-13
closePrices.add(new BigDecimal(25.88));//2023-04-14
closePrices.add(new BigDecimal(26.41));//2023-04-17
closePrices.add(new BigDecimal(26.28));//2023-04-18
closePrices.add(new BigDecimal(25.76));//2023-04-19
closePrices.add(new BigDecimal(25.39));//2023-04-20
closePrices.add(new BigDecimal(25.44));//2023-04-21
closePrices.add(new BigDecimal(24.66));//2023-04-24
closePrices.add(new BigDecimal(24.31));//2023-04-25
closePrices.add(new BigDecimal(24.45));//2023-04-26
closePrices.add(new BigDecimal(25.29));//2023-04-27
closePrices.add(new BigDecimal(25.80));//2023-04-28
closePrices.add(new BigDecimal(25.40));//2023-05-04
closePrices.add(new BigDecimal(25.20));//2023-05-05
closePrices.add(new BigDecimal(26.13));//2023-05-08
closePrices.add(new BigDecimal(25.84));//2023-05-09
closePrices.add(new BigDecimal(25.53));//2023-05-10
closePrices.add(new BigDecimal(25.12));//2023-05-11
closePrices.add(new BigDecimal(24.72));//2023-05-12
closePrices.add(new BigDecimal(25.30));//2023-05-15
closePrices.add(new BigDecimal(25.02));//2023-05-16
closePrices.add(new BigDecimal(25.86));//2023-05-17
closePrices.add(new BigDecimal(25.61));//2023-05-18
closePrices.add(new BigDecimal(25.64));//2023-05-19
closePrices.add(new BigDecimal(25.63));//2023-05-22
closePrices.add(new BigDecimal(25.20));//2023-05-23
closePrices.add(new BigDecimal(24.86));//2023-05-24
closePrices.add(new BigDecimal(24.96));//2023-05-25
closePrices.add(new BigDecimal(25.06));//2023-05-26
closePrices.add(new BigDecimal(25.12));//2023-05-29
closePrices.add(new BigDecimal(24.68));//2023-05-30
closePrices.add(new BigDecimal(24.77));//2023-05-31
closePrices.add(new BigDecimal(24.62));//2023-06-01
closePrices.add(new BigDecimal(24.67));//2023-06-02
closePrices.add(new BigDecimal(24.42));//2023-06-05
closePrices.add(new BigDecimal(24.03));//2023-06-06
closePrices.add(new BigDecimal(23.52));//2023-06-07
closePrices.add(new BigDecimal(23.40));//2023-06-08
closePrices.add(new BigDecimal(23.62));//2023-06-09
closePrices.add(new BigDecimal(23.30));//2023-06-12
closePrices.add(new BigDecimal(23.23));//2023-06-13
closePrices.add(new BigDecimal(22.90));//2023-06-14
closePrices.add(new BigDecimal(23.36));//2023-06-15
closePrices.add(new BigDecimal(23.66));//2023-06-16
closePrices.add(new BigDecimal(23.66));//2023-06-19
closePrices.add(new BigDecimal(23.98));//2023-06-20
closePrices.add(new BigDecimal(23.76));//2023-06-21
closePrices.add(new BigDecimal(23.87));//2023-06-26
closePrices.add(new BigDecimal(24.08));//2023-06-27
closePrices.add(new BigDecimal(24.74));//2023-06-28
closePrices.add(new BigDecimal(25.72));//2023-06-29
closePrices.add(new BigDecimal(26.75));//2023-06-30
closePrices.add(new BigDecimal(26.83));//000768 中航西飞 数据 2023年7月3日 SKDJ结果 K 92.81,D 90.63
return closePrices;
}
用一个简单的股票价格类,一个计算LLV, HHV, EMA, MA的实用类,以及一个计算SKDJ的方法。
public class StockPrice {
private final double low;
private final double high;
private final double close;
public StockPrice(double low, double high, double close) {
this.low = low;
this.high = high;
this.close = close;
}
public double getLow() {
return low;
}
public double getHigh() {
return high;
}
public double getClose() {
return close;
}
}
计算LLV, HHV, EMA, MA的实用方法:
public class IndicatorUtil {
public static double llv(List<StockPrice> prices, int n) {
return prices.stream()
.limit(n)
.mapToDouble(StockPrice::getLow)
.min()
.orElse(Double.NaN);
}
public static double hhv(List<StockPrice> prices, int n) {
return prices.stream()
.limit(n)
.mapToDouble(StockPrice::getHigh)
.max()
.orElse(Double.NaN);
}
public static double ema(List<Double> data, int n) {
double multiplier = 2.0 / (n + 1);
double ema = data.get(0);
for (int i = 1; i < data.size(); i++) {
ema = (data.get(i) - ema) * multiplier + ema;
}
return ema;
}
public static double ma(List<Double> data, int n) {
return data.stream()
.limit(n)
.mapToDouble(Double::doubleValue)
.average()
.orElse(Double.NaN);
}
}
用以上的工具类和方法来计算SKDJ指标:
public class SkdjIndicator {
public static Pair<Double, Double> calculateSkdj(List<StockPrice> prices, int n, int m) {
double lowv = IndicatorUtil.llv(prices, n);
double highv = IndicatorUtil.hhv(prices, n);
List<Double> rsvs = new ArrayList<>();
for (StockPrice price : prices) {
double rsv = (price.getClose() - lowv) / (highv - lowv) * 100;
rsvs.add(rsv);
}
double k = IndicatorUtil.ema(rsvs, m);
double d = IndicatorUtil.ma(rsvs, m);
return new Pair<>(k, d);
}
}
以下是使用Java编写的通达信SKDJ指标的代码示例:
```java
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class SKDJIndicator {
public static void main(String[] args) {
int N = 9;
int M = 3;
List<BigDecimal> lowPrices = getLowPrices();
List<BigDecimal> highPrices = getHighPrices();
List<BigDecimal> closePrices = getClosePrices();
List<BigDecimal> lowV = calculateLowV(lowPrices, N);
List<BigDecimal> highV = calculateHighV(highPrices, N);
List<BigDecimal> rsv = calculateRSV(lowV, highV, closePrices);
List<BigDecimal> k = calculateK(rsv, M);
List<BigDecimal> d = calculateD(k, M);
System.out.println("SKDJ结果 K: " + k.get(k.size() - 1) + ", D: " + d.get(d.size() - 1));
}
public static List<BigDecimal> calculateLowV(List<BigDecimal> lowPrices, int N) {
List<BigDecimal> lowV = new ArrayList<>();
for (int i = 0; i < lowPrices.size(); i++) {
if (i < N - 1) {
lowV.add(null);
} else {
BigDecimal minLow = lowPrices.get(i);
for (int j = i - N + 1; j <= i; j++) {
BigDecimal currentLow = lowPrices.get(j);
if (currentLow.compareTo(minLow) < 0) {
minLow = currentLow;
}
}
lowV.add(minLow);
}
}
return lowV;
}
public static List<BigDecimal> calculateHighV(List<BigDecimal> highPrices, int N) {
List<BigDecimal> highV = new ArrayList<>();
for (int i = 0; i < highPrices.size(); i++) {
if (i < N - 1) {
highV.add(null);
} else {
BigDecimal maxHigh = highPrices.get(i);
for (int j = i - N + 1; j <= i; j++) {
BigDecimal currentHigh = highPrices.get(j);
if (currentHigh.compareTo(maxHigh) > 0) {
maxHigh = currentHigh;
}
}
highV.add(maxHigh);
}
}
return highV;
}
public static List<BigDecimal> calculateRSV(List<BigDecimal> lowV, List<BigDecimal> highV,
List<BigDecimal> closePrices) {
List<BigDecimal> rsv = new ArrayList<>();
for (int i = 0; i < closePrices.size(); i++) {
BigDecimal currentLowV = lowV.get(i);
BigDecimal currentHighV = highV.get(i);
BigDecimal currentClose = closePrices.get(i);
if (currentLowV != null && currentHighV != null) {
BigDecimal rsvValue = (currentClose.subtract(currentLowV))
.divide(currentHighV.subtract(currentLowV), 4, BigDecimal.ROUND_HALF_UP)
.multiply(BigDecimal.valueOf(100));
rsv.add(rsvValue);
} else {
rsv.add(null);
}
}
return rsv;
}
public static List<BigDecimal> calculateK(List<BigDecimal> rsv, int M) {
List<BigDecimal> k = new ArrayList<>();
for (int i = 0; i < rsv.size(); i++) {
if (i < M - 1)
.
通达信改良SKDJ指标公式
讲的非常详细,可以参考下
https://blog.csdn.net/m0_74754828/article/details/129990787