Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

money management

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

    money management

    Dear NinjaTraders,

    I am working on a multi-instrument strategy. In order to figure out how to allocate money to the various instruments, I need some functionality to keep track of the
    * current total account value, including cash and stocks
    * the fill prices for execution of entry and exit orders

    Right now, I am doing this manually, by looping through my BarsArray during OnBarUpdate and by looking at the order objects during OnExecution.

    Does NinjaTrader provide any more elegant method to do this?


    Thank you,
    best regards, Felix

    #2
    ... the reason why I ask is of course that I am facing difficulties. Here is what I am trying to do:

    Code:
           protected override void OnBarUpdate() {
    			if (BarsInProgress != 0) return;
    ...
    			for (int j = startBar; j < BarsArray.Length; j++) {
    						int quantity = Convert.ToInt32 (TotalValue() / BarsArray[j].GetClose(0));
    I have convinced myself that TotalValue() works... but the closing price I am using to determine the quantity is far off the mark.

    I am wondering now: are all closing prices already updated when OnBarUpdate is called for BIP == 0? Or is there another event I should use, to go through all the stocks in my multi-instrument strategy?

    Comment


      #3
      Hello Felix,

      Thank you for your post.

      You can use the TradeCollection GetTrades() method for pulling the various instruments performance values: http://www.ninjatrader.com/support/h.../gettrades.htm

      Please let me know if you have any questions.

      Comment


        #4
        Hi Patrick,

        thank you for your response. My question was aimed at something else though. For my multi-instrument strategy, I need to know at any given point of time how much cash I have and how much money I have in any given stock.

        I tried to use GetAccountValue, but it seems that has a value of 0 during backtesting a strategy. Do I really need to keep track of my portfolio value manually, or does Ninjatrader provide any functionality for this (that can be used during backtesting)?

        When are the closing prices of all the bars in my strategy updated? Can I safely assume that all are updated, when OnBarUpdate is called with BIP == 0?

        Thank you,
        best regards, Felix

        Comment


          #5
          Hi Felix, correct the account value would be expected at 0 in backtesting. You would need to cumulate to have a evolving value to work with.

          In real time the bars will update whenever they closing bars condition would call for it, in backtesting it's synched per timestamp / order of adding.

          Comment


            #6
            Hi Bertrand,

            I am a bit stuck here. I have implemented my own money management, to calculate my account value and how many shares I am able/ willing to trade.

            What I notice, is that the backtesting result does not match my simulation. That's probably no surprise, as the backtesting engine does not know how much money my strategy is playing with. How do I tell the backtesting engine? It seems that AccountSize has no relevance to backtesting? What is the initial value, the backtester would play with?

            What puzzles me the most is that I can't even get the reported performance of my backtesting to change... regardless of the value I assign to my 'internal' account value. Another way to look at this question would be: how does the backtester even determine trading performance?


            Thank you,
            best regards, Felix

            PS: did I mention that NinjaTrader support is absolutely awesome?
            Last edited by fbertram; 10-06-2014, 08:00 PM.

            Comment


              #7
              Felix, thanks for the kind words. AccountSize will have no bearing on that, correct. It's purpose is solely to allow inputting a static account size used to calculate position size dynamically against when using the ByAccountSize property for the strategy order qty parameter.

              You can set your own tracking variable for an account value to start with and then cumulate your strategy's trade results into it to know how the developing account size would look, which you could in turn use for your bar by bar money management calculations to arrive at an order size to use for each trade.

              Comment


                #8
                Hi Bertrand,

                thank you for your note. I have set up my own tracking of account value, that's not my concern here. The problem I see, is a bit different: In order to test my strategy, I need to use NinjaTrader's built-in backtesting and review the reports generated thereby. What I am looking for, is for these reports to match the actual performance of my strategy. Right now this is not the case, at least not for the relative performance in percent. Instead, the backtester reports 170% P&L, while my strategy has only gained about 24% in the same period. The difference stems from the fact that the backtester does not seem to know the account size I am operating with in my strategy. I see 2 options:

                (1) how to tell NinjaTrader what the account size of my strategy is. As you point out, AccountSize has no meaning in my case, so this is not an option.

                (2) make sure my strategy matches the assumptions that NinjaTrader's backtester makes for account size. This is where I am stuck. I have tried to change the account size, but the backtester always reports the same P&L. I might need more detailed information how the backtester is calculating P&L (relative, in percent). Any information you can give me here would be appreciated.

                Thank you,
                best regards, Felix

                Comment


                  #9
                  Felix, the backtester is not working on a set account size as starting level. It will cumulate your returns in the individual trades taken. For the differences in the percentage mode you see > this is due to the percentage mode reinvesting returns seen over the span of the backtesting and therefore it would be expected to see the deviation from your manual summing of the individual percentages without this figured in.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  561 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  325 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  547 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  547 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X