package com.strategyquant.extend.MonteCarloValues;

import com.strategyquant.lib.fitness.FitnessFunction;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.snippets.MonteCarloSim.MCStatsConst;
import com.strategyquant.lib.snippets.MonteCarloSim.MCValueComputer;
import com.strategyquant.lib.snippets.MonteCarloSim.MonteCarloStatValues;
import com.strategyquant.lib.utils.SQUtils;

public class MCAvgPctProfitByYear extends MCValueComputer {

	public MCAvgPctProfitByYear() {
		super(MCStatsConst.AVG_PCT_PROFIT_BY_YEAR, FitnessFunction.MAXIMIZE);
		
		setColumnName(L.t("AR %"));		
		setColumnWidth(60);
		setTooltip(L.t("Annual Percentage Return (higher is better)"));
	}

	@Override
	protected double compute(MonteCarloStatValues statValues, double initialCapital, double[] orders, double avgTradesPerMonth) throws Exception {
		double pctNetProfit = statValues.getDouble(MCStatsConst.PCT_NET_PROFIT);
		
		return SQUtils.safeDivide(pctNetProfit, orders.length)*avgTradesPerMonth*12f;
	}

	@Override
	public String formatValue(double value) {
		return SQUtils.d2(value)+" %";
	}
	
	@Override
	public String dependsOn() {
		return MCStatsConst.PCT_NET_PROFIT;
	}
}
