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

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        53 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        5 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        19 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        6 views
        0 likes
        Last Post cre8able  
        Working...
        X