gpt4 book ai didi

java - 如何使用 Java 中的 ta-lib 修复 RSI 计算输出中的零?

转载 作者:行者123 更新时间:2023-11-30 10:06:49 26 4
gpt4 key购买 nike

我在 spring-boot 应用程序中使用 ta-lib 和 Java 计算 RSI。在花了一些时间弄清楚函数调用参数后,我设法从计算中得到了一个输出。但是,rsi 函数一直在输出数组中返回零值。为什么它返回零?

我正在从 Binance 的 API 获取烛台数据,尝试计算给定时间段的 RSI。我已经尝试了 stochasticRSI 和 RSI,但两者都在输出数组中返回零。

public double[] calculateRsi() {
int OPT_IN_TIME_PERIOD = 14;

double closePrices[] = {3553.06005859375,3572.5,3555.070068359375,3589.02001953125,3590.219970703125,3576.39990234375,3591.840087890625,3574.590087890625,3584.0,3579.56005859375,3597.6201171875,3604.949951171875,3616.2099609375,3600.8701171875,3604.010009765625,3599.010009765625,3610.679931640625,3587.909912109375,3594.8701171875,3606.1298828125,3604.39990234375,3695.3798828125,3685.739990234375,3686.530029296875,3665.300048828125,3680.719970703125,3678.8701171875,3580.0,3524.6298828125,3518.0,3539.280029296875,3530.949951171875,3526.830078125,3545.050048828125,3528.169921875,3528.820068359375,3526.89990234375,3523.0,3515.699951171875,3535.14990234375,3577.320068359375,3578.4599609375,3570.929931640625,3581.31005859375,3561.72998046875,3577.800048828125,3549.070068359375,3533.39990234375,3552.820068359375,3532.570068359375,3546.330078125,3563.22998046875,3553.409912109375,3574.929931640625,3569.6201171875,3568.06005859375,3568.47998046875,3541.969970703125,3566.919921875,3553.2099609375};

MInteger outBegIdx = new MInteger();
MInteger outNbElement = new MInteger();
double[] outReal = new double[closePrices.length];
int startIdx = 0;
int endIdx = closePrices.length - 1;

talibCore.rsi(startIdx, endIdx, closePrices, OPT_IN_TIME_PERIOD, outBegIdx, outNbElement, outReal);

return outReal;
}

我希望计算的输出是一个包含首选 RSI 值的数组,但实际输出是以下数组:

[
55.50236554101884,
48.4420340522227,
48.936642078369324,
39.61167139428769,
39.308159841569264,
42.58440044993444,
43.68867735156312,
50.14296711032441,
50.83654805452586,
50.79841825933019,
50.311807765799145,
45.53568823545641,
43.2867452256146,
43.38390663365912,
41.2894895311203,
41.133921783119135,
41.957983467430424,
34.6763182163226,
29.239623192248875,
43.73473552102837,
39.70980937294976,
38.722071869417974,
33.91981286332463,
40.415256033334316,
39.967050108741674,
30.237053069193013,
47.24515019760144,
48.09365697810791,
47.397062335425126,
47.919330703443016,
48.50051589076493,
45.588023453959245,
41.35162036615853,
39.976389434938056,
41.79568536987075,
36.94666938984934,
40.95986916491035,
38.21570616480444,
38.538139356924304,
39.93113081247877,
39.69620754900941,
38.9256798286741,
34.87273047865816,
43.210471567071465,
37.873988767931046,
35.92186113528669,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
]

最佳答案

您应该再读一遍有关函数参数的内容。您已指定期间 = 14,并且已返回 N-14 个结果,因为前 14 天的 RSI 未定义。因为它需要 OPT_IN_TIME_PERIOD 收盘值来计算第一个 RSI 值。结果总是从 0 元素开始存储,所以最后是 0。同样在调用函数之后,outBegIdx 将包含当天的索引,它实际上对应于输出中的第一个结果。在你的情况下应该是 13 或 14,不记得它是否基于 0。此外,outNbElement 将在 outReal (N-14) 中返回有意义值的实际数量。

事实上,对于 RSI 和所有其他指标,应该有一个 *Lookback 函数,允许预先找到给定 OPT_IN_TIME_PERIOD 和其他 OPT_ 参数的结果数组的大小。因此,您可以将精确大小传递给 double[] outReal = new double[M] 以使用最小内存。我猜 RSI Lookback 函数将等于 closePrices.length - OPT_IN_TIME_PERIOD 但对于其他指标可能更复杂

关于java - 如何使用 Java 中的 ta-lib 修复 RSI 计算输出中的零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54486167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com