package com.smppw.core.reta.calc;


import com.smppw.common.pojo.dto.DateValue;
import com.smppw.common.pojo.enums.Indicator;
import com.smppw.core.reta.IndicatorFactory;
import com.smppw.core.reta.Rate;
import com.smppw.utils.DataUtil;

import java.util.List;

public class CalmarRatio extends Rate {

	@Override
	public Double calc(List<DateValue> dateValues) {
		Rate rateAnnualRet = IndicatorFactory.getInstance().get(Indicator.AnnualReturn);
		Double ratesAnnual = rateAnnualRet.calc(dateValues);

//		if (ratesAnnual == null || ratesAnnual == 0 || maxDrawdown == null || maxDrawdown == 0)
//			return null;
		
		if(null == ratesAnnual || 0 == ratesAnnual)
			return 0D;
		
		Rate rate = IndicatorFactory.getInstance().get(Indicator.MaxDrawdown);
		Double maxDrawdown = rate.calc(dateValues);
		
//		if(null == maxDrawdown || 0 == maxDrawdown) {
//			return DataUtil.handleZeroValue(ratesAnnual);
//		}
//
//		Double result = ratesAnnual / maxDrawdown;
		return DataUtil.divNearZeroValue(ratesAnnual, maxDrawdown);
	}
}
