Wanted: small code snippet for reinvestment

Viewing 15 posts - 16 through 30 (of 69 total)
  • Author
    Posts
  • #57172 quote
    JohnScher
    Participant
    Veteran

    Can you put the much more better version in the library post?

    #57173 quote
    JohnScher
    Participant
    Veteran

    and before try with TP 2.4% maybe

    #57182 quote
    Vonasi
    Moderator
    Master

    A quick optimization seems to show that holding out for more profit is better than cutting it down to 2.4%. Around 3.75% has been the optimum over the test period that I am able to test on. Less trades obviously but far more profitable and hit rate very similar.

    I’ll post it in the library post for you with that setting.

    Screenshot_1.png Screenshot_1.png Screenshot_2.png Screenshot_2.png Screenshot_3.png Screenshot_3.png
    #57228 quote
    Vonasi
    Moderator
    Master

    Position opened by this strategy on my demo account this morning. Seems to be going well but then again so are all my DAX long strategies in this new year start rally!

    #57255 quote
    verdi55
    Participant
    Veteran

    The code I’m using for reinvestment in DAX is the following :

    SP = strategyprofit
    pp = positionperf
    pprice = positionprice
    cp = countofposition
    
    number = 1 + ((SP + pp * pprice * ABS(cp) / gain)
    
    n = round(number)
    
    If n <= 1 then
    n = 1
    endif
    
    If n > 500 then
    n = 500
    endif
    

    It also considers the gain or loss of currently open positions, whereas strategyprofit alone only considers closed positions.

    n is the number of contracts you are going to buy or sellshort.

    Thus, when “gain” is set to 500, the system will open one additional contract for every 500 Euros earned.

    #57256 quote
    verdi55
    Participant
    Veteran

    The last three lines limit the maximum number of contracts. When this limit is reached, growth will stop, as you cannot trade, e.g. 20.000 DAX mini contracts in one lot.

    The code is to be used with care, as it is very easy to become rich quickly on paper using an optimized backtest, but reality will look very different.

    #57258 quote
    Vonasi
    Moderator
    Master

    I think you may have typed an error in the code

    number = 1 + ((SP + pp * pprice * ABS(cp) / gain)
    
    should be 
    
    number = 1 + (SP + (pp * pprice * ABS(cp)) / gain)
    verdi55 thanked this post
    #57261 quote
    verdi55
    Participant
    Veteran

    True. I deleted one bracket too much from a more complex code, sorry.

    The correct code for this line is :

     

    number= 1 + ((SP + pp * pprice * ABS(cp)) / gain)

    So, once again, the complete snippet :

    SP = strategyprofit
    pp = positionperf
    pprice = positionprice
    cp = countofposition
     
    number = 1 + ((SP + pp * pprice * ABS(cp)) / gain)
     
    n = round(number)
     
    If n <= 1 then
    n = 1
    endif
     
    If n > 500 then
    n = 500
    endif
    

    I hope there are no more errors.

    #57269 quote
    Vonasi
    Moderator
    Master

    Thanks for sharing that (now corrected!) code verdi55. I think I still prefer the gradual increasing of position size as profits are actually banked rather than increasing  position size based on a profit that could just as easily disappear and leave us with too small a real bank to cope with all the big bets that we opened based on money that we didn’t actually have. I’m sure your money management strategy would lead to bigger profits but unfortunately bigger profits from bigger risk. Nothing in life is free.

    At the end of the day StrategyProfit is a fantasy number anyway as it fails to take into account fees – so it is best to stop a strategy every now and then and reset the starting capital number to bring everything back into the real world.

    #57282 quote
    verdi55
    Participant
    Veteran

    Vonasi, when you switch a long to a short position in the same bar, for example, you may want to take the gain of the currently open position into account. Strategyprofit, in this case, only calculates with the previous closed position, but not with the currently open long position that is to be switched to short ! When the long position is closed, the gain is fixed and in your account in this moment. But in strategyprofit, the gain appears  only at the end of the next bar, not in this one, when the position is to be closed and the next short position with a new position size is to be opened !

    Also, strategyprofit takes into account all fees (spread and brokerage), with the exception of overnight fees, as far as I see it.

    #57283 quote
    Vonasi
    Moderator
    Master

    I had not thought of that but then again I don’t have any strategies running at the moment that would immediately close a position and enter in the opposite direction – but I’ll certainly bear it in mind now if I ever do.

    With the DFB spread betting that I do the the overnight fees (and it was these fees that I was meaning) can make quite some difference between StrategyProfit and the real world. We also have to consider the addition and deduction of dividend payments on indices.

    #57284 quote
    verdi55
    Participant
    Veteran

    Deduction of dividend payments is an interesting issue. For DAX, as it is a performance index, I think there are no such adaptations. I know that the Nikkei at IG markets is regularly corrected for dividends. But how about other indices ? DOW, NASDAQ 100, S&P 500 ? Dow Jones and NASDQ 100 are price indices, but S&P 500 is a performance index. So, is there no correction for dividends in S&P 500, but in the two others, there is one ?

    #57285 quote
    verdi55
    Participant
    Veteran
    #57290 quote
    Vonasi
    Moderator
    Master

    Not read those links yet but a quick check back through my account shows dividend adjustments on US500, Wall Street, Spain 35,Techmark, EU Stocks50 and FTSE100. I’ve not traded every index overnight though! Then there are the many commodity overnight base adjustments that need to be considered too.

    #57291 quote
    Vonasi
    Moderator
    Master

    Just checked your links and that reminded me that I receive a weekly ‘The week ahead’ email from IG and in it there is a link that takes you to a page with the attached image in it.

    https://www.ig.com/uk/week-ahead

    Screenshot_4.png Screenshot_4.png
Viewing 15 posts - 16 through 30 (of 69 total)
  • You must be logged in to reply to this topic.

Wanted: small code snippet for reinvestment


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
JohnScher @johnscher Participant
Summary

This topic contains 68 replies,
has 7 voices, and was last updated by Nicolas
8 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/31/2017
Status: Active
Attachments: 23 files
Logo Logo
Loading...