package com.strategyquant.extend.MonteCarloValues;

import com.strategyquant.lib.fitness.FitnessFunction;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.results.StatsConst;
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 MCRetDDRatio extends MCValueComputer {

	public MCRetDDRatio() {
		super(MCStatsConst.RET_DD_RATIO, FitnessFunction.MAXIMIZE);
		
		setColumnName(L.t("Ret/DD"));		
		setColumnWidth(100);
		setTooltip(L.t("Return / Drawdown ratio (higher is better)"));
	}

	@Override
	protected double compute(MonteCarloStatValues statValues, double initialCapital, double[] orders, double avgTradesPerMonth) throws Exception {
		double maxDD  = statValues.getDouble(MCStatsConst.MAX_DD);
		double netProfit  = statValues.getDouble(MCStatsConst.NET_PROFIT);

		return SQUtils.safeDivide(netProfit, maxDD);
	}

	@Override
	public String formatValue(double value) {
		return SQUtils.d2(value);
	}
	
	@Override
	public String dependsOn() {
		return StatsConst.join(MCStatsConst.MAX_DD, MCStatsConst.NET_PROFIT);
	}
}
