集团网站开发,wordpress源码整站,网站网站做任务佣金违法,nginx rewrite wordpress最近做的项目需要实现EMA和MACD#xff0c;但苦于网上没有具体的实现算法。所以自己尝试着编写了一套。已经和通达信等主流股票分析软件核对过结果#xff0c;并将其开源放在GitHub上#xff0c;含Junit 测试用例。GitHub地址#xff1a;https://github.com/wizardbyron/fi…最近做的项目需要实现EMA和MACD但苦于网上没有具体的实现算法。所以自己尝试着编写了一套。已经和通达信等主流股票分析软件核对过结果并将其开源放在GitHub上含Junit 测试用例。GitHub地址https://github.com/wizardbyron/finance-indicators/*** Calculate EMA,** param list* :Price list to calculatethe first at head, the last at tail.* return*/public static final Double getEXPMA(final List list, final int number) {// 开始计算EMA值Double k 2.0 / (number 1.0);// 计算出序数Double ema list.get(0);// 第一天ema等于当天收盘价for (int i 1; i list.size(); i) {// 第二天以后当天收盘 收盘价乘以系数再加上昨天EMA乘以系数-1ema list.get(i) * k ema * (1 - k);}return ema;}/*** calculate MACD values** param list* :Price list to calculatethe first at head, the last at tail.* param shortPeriod* :the short period value.* param longPeriod* :the long period value.* param midPeriod* :the mid period value.* return*/public static final HashMap getMACD(final List list, final int shortPeriod, final int longPeriod, int midPeriod) {HashMap macdData new HashMap();List diffList new ArrayList();Double shortEMA 0.0;Double longEMA 0.0;Double dif 0.0;Double dea 0.0;for (int i list.size() - 1; i 0; i--) {List sublist list.subList(0, list.size() - i);shortEMA Indicators.getEXPMA(sublist, shortPeriod);longEMA Indicators.getEXPMA(sublist, longPeriod);dif shortEMA - longEMA;diffList.add(dif);}dea Indicators.getEXPMA(diffList, midPeriod);macdData.put(DIF, dif);macdData.put(DEA, dea);macdData.put(MACD, (dif - dea) * 2);return macdData;}