Wanted: small code snippet for reinvestment
Forums › ProRealTime English forum › ProOrder support › Wanted: small code snippet for reinvestment
- This topic has 68 replies, 7 voices, and was last updated 7 years ago by Nicolas.
-
-
01/03/2018 at 7:39 PM #5717201/03/2018 at 7:40 PM #5717301/03/2018 at 8:13 PM #57182
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.
01/04/2018 at 11:14 AM #5722801/04/2018 at 4:01 PM #57255The code I’m using for reinvestment in DAX is the following :
reinvestment of gains12345678910111213141516SP = strategyprofitpp = positionperfpprice = positionpricecp = countofpositionnumber = 1 + ((SP + pp * pprice * ABS(cp) / gain)n = round(number)If n <= 1 thenn = 1endifIf n > 500 thenn = 500endifIt 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.
01/04/2018 at 4:06 PM #57256The 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.
01/04/2018 at 4:26 PM #5725801/04/2018 at 4:38 PM #57261True. 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 :
12345678910111213141516SP = strategyprofitpp = positionperfpprice = positionpricecp = countofpositionnumber = 1 + ((SP + pp * pprice * ABS(cp)) / gain)n = round(number)If n <= 1 thenn = 1endifIf n > 500 thenn = 500endifI hope there are no more errors.
01/04/2018 at 5:38 PM #57269Thanks 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.
01/04/2018 at 6:21 PM #57282Vonasi, 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.
01/04/2018 at 6:30 PM #57283I 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.
01/04/2018 at 6:41 PM #57284Deduction 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 ?
01/04/2018 at 6:48 PM #57285Here are two answers to the issue of dividend adjustments :
https://community.ig.com/t5/Morning-Call-and-Dividend/Dividend-Adjustments-14-18-August/td-p/13439
But for the DAX, there is no dividend adjustment. At least I have never seen one.
01/04/2018 at 8:07 PM #57290Not 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.
01/04/2018 at 8:15 PM #57291Just 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.
-
AuthorPosts