package com.strategyquant.extend.StatValues;

import com.strategyquant.lib.results.SQOrder;
import com.strategyquant.lib.results.SQOrderList;
import com.strategyquant.lib.results.SQStats;
import com.strategyquant.lib.results.StatValue;
import com.strategyquant.lib.results.StatsConst;
import com.strategyquant.lib.results.StatsTypeCombination;
import com.strategyquant.lib.settings.SQSettings;
import com.strategyquant.lib.utils.SQUtils;


public class CalmarRatioValue extends StatValue {
   
   @Override
   public String dependsOn() {
      return StatsConst.join(StatsConst.PCT_DRAWDOWN, StatsConst.CAGR);
   }
   
   @Override
   public void initCompute(SQStats stats, StatsTypeCombination combination, SQOrderList ordersList, SQSettings settings, SQStats statsLong, SQStats statsShort) throws Exception {
   }

   @Override
   public void computeForOrder(SQStats stats, StatsTypeCombination combination, SQOrder order, SQSettings settings, SQStats statsLong, SQStats statsShort) throws Exception {
   }


   @Override
   public void endCompute(SQStats stats, StatsTypeCombination combination, SQOrderList ordersList, SQSettings settings, SQStats statsLong, SQStats statsShort) throws Exception {
   
       // get already computed values of drawdown and avg profit per year
       double drawdownPct = stats.getDouble(StatsConst.PCT_DRAWDOWN); 
       double CAGR = stats.getDouble(StatsConst.CAGR); 
       
       // compute V Ratio - we are using safeDivide to avoid dividing by zero errors 
       // in case avg profit per month is 0 
       double calmarRatio = SQUtils.safeDivide(CAGR, drawdownPct); 
       
       // add the new stat value to the statistics. Each value much have its own unique key, we used CalmarRatio 
       stats.set("CalmarRatio", SQUtils.round2( calmarRatio ));      
   }
}