Reinvesting full value of portfolio after each trade

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #122206 quote
    MRTWEEK
    Participant
    New

    Hello everyone!

    I have been playing around with the following code in regards to reinvesting for my tradingsystem (I found the code somewhere here on the forum):

    1 Capital = 10000
    2 Equity = Capital + StrategyProfit
    3 Position = Max(1,Equity/Capital)

    And when for orders:

    11 buy Position contract at x stop
    12 sellshort Position contract at x stop

    However I have a problem, when I enter starting capital to lets say 10000 I get a return of 12000 for my system

    And when I enter capital as 100000 I still get the return  of 2000 (102000)

    For the record I also change the sum “initial capital” to the right of the code itself

     

    Maybe Im barking up the wrong tree here but Im looking for code that always reinvests 100% (or as close as possible to 100%) of my portfolio value at each trade..

     

    Does anyone know where I have gone wrong and/or which adjustments I could try?

    Thank you in advance!

    #122207 quote
    GraHal
    Participant
    Master

    Can the position size of your chosen market increase by fractions (1.1, 1.2. 1.3 etc) or is position size limited to integers (1,2,3 etc)?

    #122220 quote
    Nicolas
    Keymaster
    Master

    What do you mean by “I get a return of 12000 for my system”?

    If the STRATEGYPROFIT is equal to 2000, your equity variable is equal to 10.000 + 2000 = 12.000

    #122221 quote
    Vonasi
    Moderator
    Master

    You can’t invest 100% of your money because you need to keep some to cover margin otherwise you will get a margin call.

    To calculate position size for 100% you would need to divide your equity by the price of what you are buying and buy that number of shares/contracts.

    #122308 quote
    nonetheless
    Participant
    Master

    This is the Money Management i use. It’s based on the margin cost and is fully adjustable as to how much profit you want to reinvest. This is set up for the DOW and it works up to the IG 2nd margin tier, should you be so lucky as to ever get up there.

    If you set your startpositionsize based on how much of your working capital you want to use, then this will handle the strategyprofit part. You could conceivably reinvest 100% of strategyprofit but if your margin is 100% of total equity, you’ll get a margin call as soon as it moves against you.  ‘Factor’ is the variable that controls the percentage of strategyprofit. It actually works as a divisor, so it’s an inverse relation — higher the factor, lower percentage reinvested.

    You will also need to check what leverage is offered for the instrument you are trading and the max position for each tier.

    //Money Management DOW
    MM = 1 // = 0 for optimization
    if MM = 0 then
    positionsize=1
    ENDIF
    if MM = 1 then
    ONCE startpositionsize = .4
    ONCE factor = f // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
    ONCE factor2 = 20 // tier 2 factor
    ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
    ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
    ONCE tier1 = 55 // DOW €1 IG first tier margin limit
    ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
    ONCE minpositionsize = .2 // enter minimum position allowed
    IF Not OnMarket THEN
    positionsize = startpositionsize + Strategyprofit/(factor*margin)
    ENDIF
    IF Not OnMarket THEN
    IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
    positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 //incorporating tier 2 margin
    ENDIF
    IF Not OnMarket THEN
    if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
    positionsize = minpositionsize //keeps positionsize from going below allowed minimum
    ENDIF
    IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 > maxpositionsize then
    positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    SkippyTrader thanked this post
    #122311 quote
    GraHal
    Participant
    Master

    Whose code is above @nonetheless so I can credit them as being the Author in the Snippet Library … or are you now a  Coding Wizard!? 🙂

    I would add as Nonetheless (Author) or Author (N0netheless) in the Library.

    Maybe it is from the Snippet Library anyway so I need not bother?

    #122315 quote
    nonetheless
    Participant
    Master

    Whose code is above

    It is – surprise surprise – of my very own device. Happy to take snippet credit, but even better if some True Coding Wiz could double check that it’s not doing anything grievously unintended.

    #122319 quote
    GraHal
    Participant
    Master

    Link added as Log 201 in here

    Snippet Link Library

    Well done Nonetheless … the credit is all yours … please accept my apologies for doubting your ability! 🙂

    #122329 quote
    nonetheless
    Participant
    Master

    I find that ‘doubting my ability’ is a very safe starting point. I’m so rarely disappointed!

    GraHal thanked this post
    #191331 quote
    SkippyTrader
    Participant
    New

    Thanks, @nonetheless  so helpful, as the other position managements are based on position size which would not necessarily work unless the underlying value of the contract remained the same. It would only work at that one time, eg. if index 20,000 vs 10,ooo, the value of that one contract is very different.

    However i have one question, on line 16 why have you multiplied factor by margin? :

    positionsize = startpositionsize + Strategyprofit/(factor*margin)

    If factor is say 20, and leverage is 1/20, then would that not just make the denominator = the entire value of the underlying product then (without any leverage)? So if say the starting position of 1 contract that is a margin cost is $700 for 1 DAX contract currently, at a 20:1 leverage available, and a factor of 20 (as increases by 5%), and you have 100% profit = $700. Then your calculator is:

    positionsize = 1 + 700/(20)x(14000*.05)

    positionsize = 1.05 

    Instead of the positionsize = 2, which it should be.

    Would this not work better?

    IF Not OnMarket THEN
    positionsize = startpositionsize + Strategyprofit/(margin)
    ENDIF
    
    roundedpositionsize = ROUND(positionsize, 1) // need to round to one decimal place if IG, or whole numbers only depending on contracts minimums. 
    
    IF BUYCONDITIONS THEN
    BUY roundedpositionsize CONTRACT AT MARKET

    Also i added in ROUND(a, digits), as depending on the contract, IG would only accept position sizes to one decimal place, or a whole number; so need round it to the nearest. Otherwise might not be able place the trade.

    #191345 quote
    nonetheless
    Participant
    Master

    why have you multiplied factor by margin?

    because it wasn’t my intention to put all of the strategyprofit towards the new margin cost; factor of 20 means you are only reinvesting 1/20 of your gain. The factor value can be anything, depending on how aggressively you want to reinvest your profits. If you really want to use all of it then you could have a factor of 1 … but I think you’ll find that will blow up your account. Try optimising f with MM switched on, see what happens.

    I am not using that MM any more, but when I was using it I found that anything less than 10 was trouble (in real world trading). A lot will depend on your particular strategy, the WIN%, Risk/Reward ratio and the general distribution of losses.

    Rounding is definitely a good idea but I round to 2 decimal places and IG seem okay with it.

    I think that IG Oz (and most other places) have leverage of 0.05 for both tier 1 and 2 so you could simplify it by removing margin2, factor2 etc…

    SkippyTrader thanked this post
    #191359 quote
    SkippyTrader
    Participant
    New

    Hi thanks, Makes sense. Yes i backtested and had something looked almost like a bell curve lol, rapidly up BUT then rapidly down. But yeah now i understand what you were doing i will try backtest with different values for the f and see what the equity curve looks like.

    Yes your right, we only have the 20 leverage available in Australia for main indices or 10 for the other indices. So can simplify it.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Reinvesting full value of portfolio after each trade


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
MRTWEEK @mrtweek Participant
Summary

This topic contains 11 replies,
has 2 voices, and was last updated by SkippyTrader
3 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/15/2020
Status: Active
Attachments: No files
Logo Logo
Loading...