More accurate equity curve with overnight fees deducted
Forums › ProRealTime English forum › ProOrder support › More accurate equity curve with overnight fees deducted
- This topic has 9 replies, 3 voices, and was last updated 5 years ago by Finning.
-
-
07/26/2018 at 9:54 AM #76772
I thought I would share this bit of code. You can add it to the bottom of any strategy that trades on an index and it will calculate a equity curve that takes into account any overnight fees so that our analysis of a strategies actual profit is a little more accurate,
There are some limitations as the Libor rate used in the calculation of overnight fees changes and we can only use a fixed value – but we have to work with the cards that we are dealt.
Everything is explained in the code but you will need to change some of the values depending on the time frame of the chart being used. It does not work on time frames slower than weekly.
Hopefully someone will find it useful.
12345678910111213141516171819202122232425262728293031323334//Indices Strategy Profit Minus Overnight Fees Calculator//By Vonasi//26 July 2018//Use on Indices only//Add the code to the bottom of your strategy.//If using on intraday charts then you will need to adjust the time used in line 23 to match the open time of the last candle of the day on your chart on Friday afternoon.//If using on intraday charts then there must be a candle at 220000.//It does not work on time frames slower than weekly.Capital = 10000 //Initial starting capitalPositionSize = 1 //Stake sizeBrokerFee = 2.5 //Brokers fee in % for overnight calculation.Libor = 0.4728 // The current Libor overnight rate in %DaysInBar = 1 // Daily or faster time frame = 1 Weekly time frame = 7IntraDay = 1 // Daily or Weekly chart = 0 Faster than daily chart = 1Equity = Capital + StrategyProfitLongFee = Round(((PositionSize * close) * (((BrokerFee/100) + (Libor/100))/365))*100)/100If IntraDay and OnMarket and time = 220000 thenCost = Cost + (countofposition * (LongFee * DaysInbar))endifIf IntraDay and OnMarket and opentime = 230000 and opendayofweek = 5 then //Change time to open time of last candle of the day on FridayCost = Cost + ((countofposition * (LongFee * DaysInbar)) * 2)endifIf not IntraDay and OnMarket thenCost = Cost + (countofposition * (LongFee * DaysInbar))ENDIFProfits = Equity - CostGraph ProfitsHere is an example of it used on a weekly strategy. It can be seen that the standard equity curve is showing a strategy balance of £65499 and the adjusted for fees curve is showing £60174 balance so over the years we have paid £5325 in overnight fees (had the Libor rate and brokers fees and spread stayed level).
Please note that I have not tested it on intraday strategies very much as I don’t really trade them any more. If you find a problem please point it out.
07/28/2018 at 12:51 PM #7696807/29/2018 at 5:09 PM #77018I had some time to test out the above code and realised that it is full of errors and a total pile of poop! Ignore the above code and try this new one that should work properly:
123456789101112131415161718192021222324252627282930313233343536//Indices Strategy Profit Minus Overnight Fees Calculator v2//By Vonasi//29 July 2018//Use on Indices only//Add the code to the bottom of your strategy.//If using on intraday charts then you will need to adjust the time used in line 23 to match the open time of the last candle of the day on your chart on Friday afternoon.//If using on intraday charts then there must be a candle at 220000.Capital = 10000 //Initial starting capitalBrokerFee = 2.5 //Brokers fee in % for overnight calculation.Libor = 0.4728 // The current Libor overnight rate in %DaysInBar = 1 // Daily or lower timeframe=1 Weekly timeframe=7IntraDay = 1 // Weekly chart=0 Daily=1 Faster than daily=2Equity = Capital + StrategyProfitLongFee = Round(((CountofPosition * close) * (((BrokerFee/100) + (Libor/100))/365))*100)/100If IntraDay = 2 and OnMarket and time = 220000 thenCost = Cost + (LongFee * DaysInbar)endifIf IntraDay = 2 and OnMarket and opentime = 230000 and opendayofweek = 5 then //Change time to open time of last candle of the day on FridayCost = Cost +((LongFee * DaysInbar) * 2)endifIf (IntraDay = 0 or IntraDay = 1) and OnMarket thenCost = Cost + (LongFee * DaysInbar)ENDIFIf IntraDay = 1 and OnMarket and opendayofweek = 5 thenCost = Cost + (LongFee * DaysInbar)ENDIFProfits = Equity - CostGraph Profits1 user thanked author for this post.
02/06/2019 at 7:10 AM #90573Hi Vonasi,
just a quick question. For line 17 above – should it be (as below) to factor in pip value/pip size?
1LongFee = Round(((CountofPosition*pipsize*pipvalue * close) * (((BrokerFee/100) + (Libor/100))/365))*100)/100Thanks for the code to copy/play with.
Cheers
Finning.
02/06/2019 at 9:21 AM #90575Very possibly but my understanding of the use of PIPVALUE and PIPSIZE is very limited so I am probably not the best person to answer this question. I spread bet with IG and have never found the need to use either instruction in any of my strategies and they have always worked just fine. I know that Roberto uses it a lot so maybe he can be more helpful on this subject.
02/06/2019 at 9:32 AM #9057602/06/2019 at 9:48 AM #90579No, Countofposition is the number of shares traded and has nothing to do with Pip calculations.
CLOSE might be used sometimes for this kind of conversion, not in this case, though.
Moreover you used twice the conversion, which would yield erroneous results.
PIPVALUE (or PIPSIZE) must be used to convert a number of pips to price by multiplying it by that number, while converting a price into pips requires division.
12PipsGained = (Tradeprice - close) / pipsise //Price —-> PipsStopLoss = tradeprice - (20 * pipsize) //Pips —-> Price1 user thanked author for this post.
02/06/2019 at 10:45 PM #90655Hi Roberto,
I was looking at the same instrument with different contract values (e.g. – and index with $1 or $25 per point), and I wasn’t sure if it was accounted for in the initial formula above.
I was trying to define pipsize = 1.0 pip/point (an index) and pipvalue = $1.0 per pip/point (a mini contract).
Just thought you needed a total trade value to apply the fee % to.
Was looking at this for indexes – https://www.ig.com/au/help-and-support/cfds/fees-and-charges/why-is-overnight-funding-charged-and-how-is-it-calculated-
And I thought that the Trade size was (number of pips x pip size x value of pips) x (close) x (interest rates/365).
Cheers,
Finning
02/07/2019 at 2:20 AM #90663Sorry for some confusion on my side, PIPSIZE and POINTSIZE are equivalent and refer to the size of 1 pip (usually 1/10000th for FX pairs), while PIPVALUE and POINTVALUE should be equivalent and refer to the value of each pip, but as you can see from my pic (Dax, h1) this is not always true, so it seems that POINTVALUE is the recommended keyword to use.
So there was no double multiplication.
Still CLOSE has to be divided by PipSize to get the correct number of pips, then you correctly multiply that by PointValue and CountOfPosition to get the total value p/Pip of your positions (contracts or shares). The correct formula you posted should read:
1LongFee = Round(((CountofPosition * ((close / pipsize) * pointvalue)) * (((BrokerFee/100) + (Libor/100))/365))*100)/100(close / pipsize) = converts price into Pips
(Pips * pointvalue) = value of 1 position
(Value of 1 position * CountofPosition) = value of all positions
1 user thanked author for this post.
02/07/2019 at 4:28 AM #90665 -
AuthorPosts
Find exclusive trading pro-tools on