日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

和軟件的macD的值進行對比過,數值是一樣的,不過我這個版本小數點后面更精確,軟件的是四舍五入的。這個版本支持增量更新,更加方便。

使用需要單例模式,如果多并發請自行修改代碼。默認是12,26,9

特別注意,網站上的和軟件的MACD有時候并不一致,本文的計算結果以軟件為準!!!

廢話不多說,直接開干!

import JAVA.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

@Component("macdUtils")
public class MacdUtils {

	static int fastSet = 12;
	static int slowSet = 26;
	static int deaSet = 9;

	static int emaFastFast = fastSet - 1;
	static int emaFastSlow = 2;
	static int emaFastBase = fastSet + 1;
	static int emaSlowFast = slowSet - 1;
	static int emaSlowSlow = 2;
	static int emaSlowBase = slowSet + 1;
	static int deaFast = deaSet - 1;
	static int deaSlow = 2;
	static int deaBase = deaSet + 1;

	public void init(int fastSetNum, int slowSetNum, int deaSetNum) {
		fastSet = fastSetNum;
		slowSet = slowSetNum;
		deaSet = deaSetNum;
		emaFastFast = fastSet - 1;
		emaFastSlow = 2;
		emaFastBase = fastSet + 1;
		emaSlowFast = slowSet - 1;
		emaSlowSlow = 2;
		emaSlowBase = slowSet + 1;
		deaFast = deaSet - 1;
		deaSlow = 2;
		deaBase = deaSet + 1;
	}

	public Map<String, BigDecimal> firstMACD(BigDecimal yestodayClose, BigDecimal nowClose) {
		Map<String, BigDecimal> macdInfoMap = new HashMap<>();
		BigDecimal EMA12Fast = yestodayClose.multiply(BigDecimal.valueOf(emaFastFast)).divide(BigDecimal.valueOf(emaFastBase), 6, RoundingMode.DOWN);
		BigDecimal EMA12Slow = nowClose.multiply(BigDecimal.valueOf(emaFastSlow)).divide(BigDecimal.valueOf(emaFastBase), 6, RoundingMode.DOWN);
		BigDecimal EMA12 = EMA12Fast.add(EMA12Slow);
		BigDecimal EMA26Fast = yestodayClose.multiply(BigDecimal.valueOf(emaSlowFast)).divide(BigDecimal.valueOf(emaSlowBase), 6, RoundingMode.DOWN);
		BigDecimal EMA26Slow = nowClose.multiply(BigDecimal.valueOf(emaSlowSlow)).divide(BigDecimal.valueOf(emaSlowBase), 6, RoundingMode.DOWN);
		BigDecimal EMA26 = EMA26Fast.add(EMA26Slow);
		BigDecimal DIF = EMA12.subtract(EMA26);
		BigDecimal DEA = BigDecimal.ZERO.multiply(BigDecimal.valueOf(deaFast)).divide(BigDecimal.valueOf(deaBase), 6, RoundingMode.DOWN)
				.add(DIF.multiply(BigDecimal.valueOf(2)).divide(BigDecimal.valueOf(deaBase), 6, RoundingMode.DOWN));
		BigDecimal MACD = DIF.subtract(DEA);
		macdInfoMap.put("EMA12", EMA12);
		macdInfoMap.put("EMA26", EMA26);
		macdInfoMap.put("DIF", DIF);
		macdInfoMap.put("DEA", DEA);
		macdInfoMap.put("MACD", MACD);
		return macdInfoMap;
	}

	public Map<String, BigDecimal> makeMACD(BigDecimal yesterdayEMA12, BigDecimal yesterdayEMA26, BigDecimal yesterdayDEA, BigDecimal nowClose) {
		Map<String, BigDecimal> macdInfoMap = new HashMap<>();
		BigDecimal EMA12Fast = yesterdayEMA12.multiply(BigDecimal.valueOf(emaFastFast)).divide(BigDecimal.valueOf(emaFastBase), 6, RoundingMode.DOWN);
		BigDecimal EMA12Slow = nowClose.multiply(BigDecimal.valueOf(emaFastSlow)).divide(BigDecimal.valueOf(emaFastBase), 6, RoundingMode.DOWN);
		BigDecimal EMA12 = EMA12Fast.add(EMA12Slow);
		BigDecimal EMA26Fast = yesterdayEMA26.multiply(BigDecimal.valueOf(emaSlowFast)).divide(BigDecimal.valueOf(emaSlowBase), 6, RoundingMode.DOWN);
		BigDecimal EMA26Slow = nowClose.multiply(BigDecimal.valueOf(emaSlowSlow)).divide(BigDecimal.valueOf(emaSlowBase), 6, RoundingMode.DOWN);
		BigDecimal EMA26 = EMA26Fast.add(EMA26Slow);
		BigDecimal DIF = EMA12.subtract(EMA26);
		BigDecimal DEA = yesterdayDEA.multiply(BigDecimal.valueOf(deaFast)).divide(BigDecimal.valueOf(deaBase), 6, RoundingMode.DOWN)
				.add(DIF.multiply(BigDecimal.valueOf(2)).divide(BigDecimal.valueOf(deaBase), 6, RoundingMode.DOWN));
		BigDecimal MACD = DIF.subtract(DEA);
		macdInfoMap.put("EMA12", EMA12);
		macdInfoMap.put("EMA26", EMA26);
		macdInfoMap.put("DIF", DIF);
		macdInfoMap.put("DEA", DEA);
		macdInfoMap.put("MACD", MACD);
		return macdInfoMap;
	}

}

分享到:
標簽:JAVA
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定