package com.smppw.core.reta.calc;


import com.smppw.constants.Consts;
import com.smppw.common.pojo.dto.CompoundRet;
import com.smppw.common.pojo.enums.Frequency;
import com.smppw.common.pojo.enums.Indicator;
import com.smppw.core.reta.IndicatorFactory;
import com.smppw.core.reta.Rate;
import com.smppw.utils.FunctionUtil;

import java.util.List;

/**
 * @author zhengsongliang
 * @datetime 2017年7月25日 上午10:15:37
 */
public class SMDDCVaR extends Rate {

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		List<Double> a = FunctionUtil.getFundRetList(list);
		Double sum = 0D;
		for (Double unit : a) {
			if (unit == null) {
				continue;
			}
			sum += unit;
		}
		if (sum == 0)
			return null;
		LPM.LPMFunction lpm1Fun = new LPM.LPMFunction(FunctionUtil.getFundRetList(list), new SMDDLPM1());
		Double VaR = IndicatorFactory.getInstance().get(Indicator.SMDDVaR).calc(list, frequency, ifAnnualized);
		return VaR == null ? null : VaR + lpm1Fun.value(VaR) / Consts.PROB;

	}

}
