In order to calculate the overnight broker fees while testing an automated strategy, I made this little code snippet, that can be “plug” in any Probacktest code.Parameters to change are between lines 1 and 4:
“Capital”, set it accordingly to your starting balance in money (10.000€ in this case).
The “overnightfee” variable, that must be set to the correct broker’s fee (0.8€ per position in this case).
Overnight fees calculation, the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
// --- parameters Capital = 10000 // initial capital of account overnightfee = 0.8 //broker overnight fee of a position (in money) // --- equity = Capital + StrategyProfit ONCE BrokerProfit=0 FourHoursChart=5 //can be set to bar qu once countofdays=0 if not onmarket then countofdays=0 elsif onmarket and Intradaybarindex =FourHoursChart then countofdays=countofdays+1 BrokerProfit=BrokerProfit+countofdays*overnightfee*countofposition else countofdays=countofdays BrokerProfit=BrokerProfit endif trueEquity=Equity-BrokerProfit graph BrokerProfit COLOURED(255,0,0) AS "BrokerProfit" graph trueEquity COLOURED(0,0,255) AS "trueEquity" graph countofdays COLOURED(0,0,0) AS "countofdays" |
How to interpret results?
Results are displayed on chart when you run a backtest with Probacktest, they are “graphed” with 3 different curves:
- BrokerProfit in red, tell you how much are the overnight fees of the broker, for the current instrument and for the whole strategy period.
- trueEquity in blue, is the real strategy without the overnight fees, which is slightly different from the equity curve Probacktest give you (compare this blue line to the equity curve above).
- countofdays in black, is the final count of days when an overnight fees were encountered.
In this example, the calculation were made with the Pathfinder strategy, as you can see, only 6% of profit is wiped out of the whole strategy performance.
This blog post is related to the discussions of this topic: https://www.prorealcode.com/topic/brokers-overnight-interest-rate/
trueEquity in blue, is actually WITH the overnight fees, as they are deducted from the back tested equity
..and then again. With or without, I guess It’s how you look on it 🙂
Thanks very much for this. I usually make an educated guess on funding costs taking into account average position size and holding periods etc but it’s very useful to have a much more accurate way to calculate this as sometimes the costs can be significant. Cheers !
‘when does PRT provide a standard for additional (interest) costs of holding overnight positions ?
COSTS: When on market, one time per day, around 23:00 hrs, calculate interest rate/year x market exposure of the ETF contract(s) / 365 days
Great! Many thanks!