package com.strategyquant.extend.FitnessFunctions;

import com.strategyquant.lib.fitness.FitnessFunction;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.results.SQResultsGroup;
import com.strategyquant.lib.results.StatsConst;
import com.strategyquant.lib.settings.SQConst;
import com.strategyquant.lib.utils.SQUtils;

public class PctStagnation extends FitnessFunction {
	
	public PctStagnation() {
		super();
		
		name = L.t("% Stagnation");
		type = FitnessFunction.MINIMIZE;
	}

	@Override
	public synchronized double computeFitness(SQResultsGroup resultsGroup, String sampleType) throws Exception {
		double fitness = resultsGroup.getResult(SQConst.SYMBOL_PORTFOLIO).getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, sampleType).getDouble(StatsConst.STAGNATION_PERIOD_PCT);
		
		return fitness;
	}
	
	@Override
	public String printFitness(SQResultsGroup resultsGroup) throws Exception {
		double fitness = resultsGroup.getFitness();
		
		return SQUtils.d2WithPlType(fitness, SQConst.PL_IN_PCT);
	}
}
