how to hard code initial capital

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #236561 quote
    borderlineJim
    Participant
    Senior

    Good morning to the PRT community!

     

    Can anyone help me with hard coding the initial capital that is to be allocated to a trading system?

    I assume one has to do this if they plan to use a % based profit target or stop loss, other wise a specified % will be based on the total capital.  Is this correct?

    It would also be interesting to experiment with a trailing % based stop loss, but maybe that is for another topic.

     

    Best regards

     

    J

    #236562 quote
    phoentzs
    Participant
    Master

    The percentages of stop loss, take profit and trailing refer to the underlying value, i.e. the index such as DAX, NASDAQ etc.

    borderlineJim thanked this post
    #236566 quote
    JS
    Participant
    Senior
    Hi,

    Stop loss, take profit and trailing are all calculated from the (average) position price…

    Simple example:

    Initial capital = 10,000 euros

    Risk 1% (of the initial capital) =100 euros

    (Index point value=1, number of contracts=1)

    SL=100 (1% of initial capital)

    Set Stop pLoss SL

    Or in percentages:

    SL=Risk/PositionPrice*100

    Set Stop %Loss SL

    If you want to make use of your total equity:

    Equity=Capital + StrategyProfit

    Risk 1% (of the Equity) = (Capital + StrategyProfit) * 1/100

    Etc…

    robertogozzi and borderlineJim thanked this post
    #236567 quote
    robertogozzi
    Moderator
    Master
    You can’t allocate different slices of your Capital among strategies, as they are unaware of each other. You need to manage that allocation within your code. In this example I assume this strategy has an initial Capital allocated of 10K euros (or whatever currency unit it is), no matter if your account has more, and I have set a 10% treshold, so that when my loss reaches that treshold, my strategy is stopped with QUIT:
    ONCE myCapital  = 10000
    ONCE myTreshold = myCapital * 0.9  //Exit when only 10% of my initial Capital is left
    IF StrategyProfit <= -myTreshold THEN
       QUIT
    ENDIF
    Sma10 = average[20,0](close)
    Xup   = close CROSSES OVER  Sma10
    Xdn   = close CROSSES UNDER Sma10
    IF Not OnMarket THEN
       IF Xup THEN
          BUY 1 CONTRACT AT MARKET
       ELSIF Xdn THEN
          SELLSHORT 1 CONTRACT AT MARKET
       ENDIF
       SET STOP   pLOSS   100
       SET TARGET pPROFIT 200
    ENDIF
    it’s just the first 5 lines that you need to use at the beginning of your code.
    borderlineJim thanked this post
    #236568 quote
    robertogozzi
    Moderator
    Master
    As I always say “two is better than none!” 🙂
    JS and borderlineJim thanked this post
    #236591 quote
    JS
    Participant
    Senior

    For the sake of clarity:

    Roberto, of course, meant 0.1 instead of 0.9

    ONCE myThreshold=myCapital*0.1

    Before someone is stuck with a DD of 9000 euros 😉

    #236592 quote
    robertogozzi
    Moderator
    Master
    No JS, I actually meant 0.9, as it will be turned negative in line 3, so after a -9000 losses (thus 1000 left on the account), it will QUIT.
    JS thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

how to hard code initial capital


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by robertogozzi
1 year, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/21/2024
Status: Active
Attachments: No files
Logo Logo
Loading...