package com.smppw.core.reta.calc;


import com.smppw.common.pojo.dto.CompoundRet;
import com.smppw.common.pojo.enums.Frequency;
import com.smppw.core.reta.Rate;
import com.smppw.utils.DataUtil;

import java.util.List;

public class DownCaptureRatio extends Rate {

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		int countX = 0;
		Double UCRX = 1.0;

		for (CompoundRet value : list) {
			if (value.getRetOfBmk() == null) {
				continue;
			}
			if (value.getRetOfBmk() < 0) {
				countX++;
				UCRX *= value.getRetOfBmk() + 1;
			}
		}
		if (countX == 0) {
			return null;
		}
		UCRX = Math.pow(UCRX, 1.0 / countX) - 1;
		Double UCRY = new DownCaptureReturn().calc(list, frequency, ifAnnualized);

//		if (UCRX == null || UCRY == null) {
//			return null;
//		} else if (UCRX == 0) {
//			return DataUtil.handleZeroValue(UCRY);
//		}
//
//		Double result = UCRY / UCRX;
		return DataUtil.divNearZeroValue(UCRY, UCRX);
	}

}
