Calculating overnight fees, interest, and dividends
Forums › ProRealTime English forum › General trading discussions › Calculating overnight fees, interest, and dividends
- This topic has 3 replies, 3 voices, and was last updated 3 months ago by
GraHal.
-
-
02/12/2025 at 8:47 PM #243755
We add spread to our systems in the PRT platform, but what about overnight broker fees, interest, and the impact of dividends?
I’ve developed some code that calculates the cost of overnight fees, interest, and the impact of dividends. I use it across all my systems since these factors can really add up over time.
Below, you’ll find the code based on the DAX 40. It should be simple to integrate into your own systems and customise as needed. The code is designed to work on any intraday time frame, you’ll just need to adjust the
CurrentTime = 220000
to match the fee application time in your own time zone.This version is designed for the UK, with IG, and assumes an interest rate of 4.75% plus a broker fee of 3.0%. It also includes an approximate calculation for dividends (accounting for both positive values for longs and negatives for shorts). It then plots the results on a graph, and if a position is held on a Friday night, the fee is calculated as three times the standard value.
12345678910111213141516171819202122232425262728293031323334353637IF CurrentTime=220000 AND OpenDayOfWeek>0 thenSONIArate=4.75if longonmarket thenint = (3 + SONIArate) * 0.01myrate = - (abs(countoflongshares) * close * int)endifif shortonmarket thenint = (3 - SONIArate) * 0.01myrate = - (abs(countofshortshares) * close * int)endifif onmarket thenmymonthrate = myrate / 12mydayrate = myrate / 365mytotalint=mytotalint+mydayrateif opendayofweek=5 thenmytotalint=mytotalint+(mydayrate*2)endifendif// DAX dividend adjustmentif longonmarket thenmydiv=(countoflongshares*close*0.0225)/260mytotaldiv=mytotaldiv+mydivendifif shortonmarket thenmydiv=-(countofshortshares*close*0.0225)/260mytotaldiv=mytotaldiv+mydivendif// Plot graphsgraph mytotalint coloured(100,40,100) AS "Interest"graph mytotaldiv coloured(100,60,100) AS "Dividends"graph mytotalint+mytotaldiv coloured(100,80,100) AS "Combined"ENDIF5 users thanked author for this post.
02/12/2025 at 9:33 PM #243756Link to above added as Log 393 here …
Snippet Link Library2 users thanked author for this post.
02/16/2025 at 3:52 PM #243918Thanks for this nice code.
But, it is hard to get accurate results over time as SOFR% (or LIBOR rates) changes every day…
Also, note that in IG Markets i found 2 different formula :
Sometimes it is written : Nights held x (market closing price x trade size x ( relevant interest rate benchmark+/- admin fee*)) / 365.
And sometimes : Number of contracts x value per contract x price x (3% admin fee+/-SOFR%*) ÷ 360What is the value of the contrat ?
Also for the week end it is written in french IG Markets website that 3 days of interest are applied for the week end, not only 2…
“Veuillez noter que les positions maintenues ouvertes après 23h (heure de Paris) le vendredi seront ajustées pour trois jours de financement afin de couvrir le week-end.”02/16/2025 at 7:04 PM #2439263 days of interest are applied for the week end, not only 2…
Friday overnight, Sat overnight and Sun overnight.
What is the value of the contract ?
Mid-price x 1? E.g. Value of 1 Contract on DJI is currently 44503 (DJI mid-price is 44503 as of Friday close).
-
AuthorPosts
Find exclusive trading pro-tools on