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.MathUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class RangeReturn extends Rate {

	@Override
	public Double calc(List<CompoundRet> list, Frequency frequency, boolean ifAnnualized) {
		List<Double> rets = getFundRetList(list);
		List<String> dateList = list.stream().filter(Objects::nonNull).map(CompoundRet::getEndDate).collect(Collectors.toList());;
		return MathUtils.getAnnualReturn(rets,dateList,  ifAnnualized);
	}

	public static List<Double> getFundRetList(List<CompoundRet> list) {
		List<Double> doubleList = new ArrayList<>();
		for (CompoundRet value : list) {
			if (value.getRetOfFund() != null) {
				doubleList.add(value.getRetOfFund());
			}
		}
		return doubleList;
	}
}
