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

Investment amount based on dollars to invest rather than a fixed number of shares

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

    Investment amount based on dollars to invest rather than a fixed number of shares

    Hello,

    I am wanting to be able to run back tests / optimizations off of a $ amount and not a specific number of shares. Is this possible?

    I am pretty sure I would need to declare a starting amount, calculate how many shares can be purchased with said amount, calculate profitability/loss once my position exits, add/sub my profit or loss from the starting amount, and then start the process all over. Has this been done before? Is there some example code out there which could help me with this?

    I do not like the fixed number of shares approach because that does not allow you to factor in the compounding effect of your gains or losses (ex. if you invest 100k and lose 5k you can't repurchase 100k again. You need to determine your investment amount off of 95k at that point).

    Any help would be appreciated.

    Kenson

    #2
    Hello Kensonprib,

    Thank you for your post.

    Pretty much you've nailed what would be required to calculate how many shares to buy based on your account value.

    You should confirm with your broker the formula for calculating the funds required for each trade or contract.

    In general the formula would be the AccountSize divided by Margin.

    The AccountItem.CashValue can be found from an account with Account.Get().

    https://ninjatrader.com/support/help...ccountitem.htm

    This example from our help guide illustrates getting the Realized PnL for trades:



    It should be noted that when backtesting there is no means to set the values of the account. You would instead implement internal calculations in your strategy to calculate and track your own custom values for the desired account values, such as CashValue.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      I always use internal values of the strategy and not the account value. Why? I want to use the compounding effect, but avoid "cross-funding" between multiple strategies.
      Let's assume, you have 50K starting capital, 10 different strategies and each of them shall be equally weighted. 8 strats do very well, 2 are losers.
      Should you increase your position size for the loser strats only because the others perform well and thereby even risk ruining the others? Likely not.
      If you allocate a separate starting capital to each strat, 5K in this example, you will never have issues with i) backtesting, ii) cross-ruining.
      With that, every strat is its own little "business".
      For proper compounding, consider to add a tax calculation to the strat and deduct taxes from the "available amount" as they become due.
      Two things are certain: Death and taxes !!!
      NT-Roland

      Comment


        #4
        Thanks everyone, I figured it out. It is now working perfectly

        Comment


          #5
          Your method sounds good to me. Investing an amount based on dollars rather than a specific number of shares is clever because the trading process becomes easier. You don’t need to calculate how many shares you can purchase with the money, leaving you to decide how much you want to invest. You can buy stocks or even ETFs based on a dollar amount. In addition, it reduces the impact of price volatility and saves money by lowering the average price per share. If you are unsure how to start this process, you can consult a financial advisor. Nowadays, some financial advisors offer information about alternative investments to inexperienced investors. You can check altinvestor.net for more information.
          Last edited by darrylrose; 01-13-2023, 10:10 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by MarianApalaghiei, Today, 10:49 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by love2code2trade, Yesterday, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          7 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          45 views
          0 likes
          Last Post bill2023  
          Working...
          X