股票K线图指标之RSI-java源码 android源码示例

RSI:

SMA(C,N,M) = (M*C+(N-M)*Y’)/N

LC := REF(CLOSE,1);

RSI$1:SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;

/**
     * SMA(C,N,M) = (M*C+(N-M)*Y')/N
     * LC := REF(CLOSE,1);
     * RSI$1:SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;
     */
    public static List countRSIdatas(List list, int days) {
        List rsiList = new ArrayList();
        if (list == null)
            return null;
        if (days > list.size())
            return null;

        double smaMax = 0, smaAbs = 0;//默认0
        double lc = 0;//默认0
        double close = 0;
        double rsi = 0;
        for (int i = 1; i < list.size(); i++) {
            KCandleObj entity = list.get(i);
            lc = list.get(i - 1).getClose();
            close = entity.getClose();
            smaMax = countSMA(Math.max(close - lc, 0d), days, 1, smaMax);
            smaAbs = countSMA(Math.abs(close - lc), days, 1, smaAbs);
            rsi = smaMax / smaAbs * 100;
            rsiList.add(new KCandleObj(rsi));
        }
        Log.v(TAG, "rsiList.size()=" + rsiList.size());

        int size = list.size() - rsiList.size();
        for (int i = 0; i < size; i++) {
            rsiList.add(0, new KCandleObj());
        }
        return rsiList;
    }

/**
     * SMA(C,N,M) = (M*C+(N-M)*Y')/N
     * C=今天收盘价-昨天收盘价    N=就是周期比如 6或者12或者24, M=权重,其实就是1
     *
     * @param c   今天收盘价-昨天收盘价
     * @param n   周期
     * @param m   1
     * @param sma 上一个周期的sma
     * @return
     */
    public static double countSMA(double c, double n, double m, double sma) {
        return (m * c + (n - m) * sma) / n;
    }
分享到:

评论已关闭