2

我在 spring-boot 应用程序中使用带有 Java 的 ta-lib 计算 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
]
4

1 回答 1

1

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

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

于 2019-02-02T18:25:15.890 回答