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 java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author zhengsongliang
 */
public class MaxContinuouslyDrawdownCount extends Rate {
	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		List<Integer> continuouslyDrawdownCounts = new ArrayList<Integer>();
		int count = 0;
		for (CompoundRet cpRet : list) {
			if (cpRet.getRetOfFund() != null) {
				if (cpRet.getRetOfFund() < 0)
					count++;
				else {
					continuouslyDrawdownCounts.add(count);
					count = 0;
				}
			}
		}
		continuouslyDrawdownCounts.add(count);
		if (!continuouslyDrawdownCounts.isEmpty())
			return Double.valueOf(Collections.max(continuouslyDrawdownCounts).doubleValue());
		return null;
	}
}
