Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Calmar Ratio Optimizer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Calmar Ratio Optimizer

    Hey guys - I need a bit of help with implementing an OptimizationFitness for the Calmar ratio. The basic methods have been written:

    Code:
        public static double AnnualReturns(double[] returns) {
            double num_years = returns.Length / 252.0;
            double cum_ret_final = (returns.Select(r => r + 1).Aggregate((a, b) => a * b));
            return Math.Pow(cum_ret_final, 1.0 / num_years) - 1.0;
        }
    
        public static double Calmar(double[] returns) {
            double max_dd = MaxDrawdown(CumulativeReturns(returns));
            if (max_dd < 0) {
                return AnnualReturns(returns) / Math.Abs(max_dd);
            }
            return double.NaN;
        }
    I omitted CumulativeReturns and MaxDrawdowns as I assume that the platform already has those values.

    How do I fold the code above into OnCalculatePerformanceValue()? I understand that I have to set the return Value but need a bit of help putting it together.

    Thanks in advance.

    #2
    Hello molecool,

    Thanks for your post.

    I have moved your forum thread over to the General Development section of the NinjaTrader Forums since it is not specifically related to making a NinjaScript strategy.

    That said, an OptimizationFitness allows one to create a data point (Value) to optimize a strategy on (min or max). So if there is some formula that a trader wants to optimize on they can calculate it in an OptimizationFitness.

    You would need to iterate through the SystemPerformance.AllTrades TradeCollection to calculate your metric within the OptimizationFitness script. Currently, a custom PerformanceMetric will not be added to the TradesPerformance class because custom performance metrics do not tie into this class.

    We are tracking interest for this in a feature request and I have added your vote. This request is being tracked under the number SFT-4723.

    As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

    Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

    The OptimizationFitness scripts that come default with NinjaTrader could be used to see how this is done. To view an OptimizationFitness NInjaScript, open a New > NinjaScript Editor window, open the OptimizationFitness folder, and double-click on the file that you want to view.

    See the help guide documentation below for more information.

    Value: https://ninjatrader.com/support/help...ness_value.htm
    OnCalculatePerformanceValue(): https://ninjatrader.com/support/help...lue.htm​
    SystemPerformance.AllTrades: https://ninjatrader.com/support/help.../alltrades.htm

    See this forum thread as well for more information on this topic and sample code: https://forum.ninjatrader.com/forum/...ess-metric-nt8
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by TraderBCL, Today, 04:38 AM
    2 responses
    14 views
    0 likes
    Last Post TraderBCL  
    Started by martin70, 03-24-2023, 04:58 AM
    14 responses
    105 views
    0 likes
    Last Post martin70  
    Started by Radano, 06-10-2021, 01:40 AM
    19 responses
    607 views
    0 likes
    Last Post Radano
    by Radano
     
    Started by KenneGaray, Today, 03:48 AM
    0 responses
    4 views
    0 likes
    Last Post KenneGaray  
    Started by thanajo, 05-04-2021, 02:11 AM
    4 responses
    471 views
    0 likes
    Last Post tradingnasdaqprueba  
    Working...
    X