package com.smppw.core.reta.calc;


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:30:32
 */
public class DownsideDeviation 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;
		Double LPM2 = IndicatorFactory.getInstance().get(Indicator.SMDDLPM2).calc(list, frequency, ifAnnualized);
		return LPM2 == null ? null : Math.sqrt(LPM2);
	}

}
