Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › Turnover Filter
- This topic is empty.
-
AuthorPosts
-
February 27, 2017 at 5:06 am #101614LeeDanelloParticipant
Just wondering how many use a turnover filter in their code and how they adjust the hard coded number to account for inflation in their backtesting?
Code://———————————————————————————
TOTog = ParamToggle(“Turnover Filter”,”Off|On”,0);
Turnover = CloseArray*VolumeArray;
MinTO = Param(“Minimum Turnover – $”,500000,0,10000000,1000);
TOMA = Param(“Turnover MA”,10,1,200,1);
AveTO = MA(Turnover,TOMA);
TOFilter = AveTO > MinTO AND Turnover > MinTO;
TOFilt = IIf(TOTog,TOFilter,1);
//—————————————————————————For example if you use a minimum turnover of $500,000 based on 2016 and you backtest to the year 2000, then the real figure back then might be $325,000, (for an average inflation rate of 2.5%) so strictly speaking your backtest will be forfeiting trades that it should have been taking. Maybe for simplicity we could use the lower figure in the backtesting. I’m wondering the merits of using a turnover figure as against a straight average volume filter/min volume combined with a minimum price.
February 27, 2017 at 7:45 am #106322Nick RadgeKeymasterYou can start from the old data and use an inflation figure to increase from that baseline.
I have some code somewhere – I’ll try and find it.
February 27, 2017 at 2:39 pm #106323LeeDanelloParticipantI was thinking something along these lines
Code:TOTog = ParamToggle(“Turnover Filter”,”Off|On”,0);
Turnover = CloseArray*VolumeArray;inflationRate = Param(“Average Inflation Rate %”,0,0,100,0.01);
MinTO = Param(“Minimum Turnover – $”,500000,0,10000000,1000);
NoBars = lastvalue( cum( 1 ) ) – Cum(1); //This equals total number of bars.
//It should equal to the number of bars in the analysis range.
//The formula currently counts the bars from the RHE to the start of the chartCurrentTO = MinTO*(1 – inflationRate /100/250)^NoBars;
TOMA = Param(“Turnover MA”,10,1,200,1);
AveTO = MA(Turnover,TOMA);
TOFilter = AveTO > CurrentTO AND Turnover > CurrentTO;
TOFilt = IIf(TOTog,TOFilter,1);In order to fix the above, need to determine the number of bars in the analysis date range.
February 28, 2017 at 12:31 am #106324Stephen JamesMemberThis might help
Code:TO = Volume*Close;InitialTO = Param(“Initial Turnover – $”,700000,0,10000000,1000);
StartYear = Param(“Start Year”,1995,0,2020,1);
TOInc = Param(“Turnover Increment”,1.03,0.01,10,0.01);
Inc = TOInc ^ Max(0,Year()-StartYear);
IncTO = InitialTO * Inc;February 28, 2017 at 2:36 am #106325LeeDanelloParticipantThanks Craig,
I was wondering what function Amibroker might have to extract the the number of bars in a backtest range. Maybe something like this so you don’t need to input a date range.
Code:toDate = Status(“rangetodate”);
fromDate = Status(“rangefromdate”);
Range = toDate-fromDate;Maybe this is the answer for counting bars in a portfolio backtest
Code:bars = 0;for (i = 0; i < BarCount - 1; i++) { { bars++; } }
February 28, 2017 at 1:47 pm #106326LeeDanelloParticipantI’ve come up with this so far.
Code:TOTog = ParamToggle(“Turnover Filter”,”Off|On”,0);
Turnover = CloseArray*VolumeArray;
MinTO = Param(“Minimum Turnover – $”,500000,0,10000000,1000);
TOMA = Param(“Turnover MA”,10,1,200,1);
AveTO = MA(Turnover,TOMA);
inflationRate = Param(“Average Inflation Rate %”,0,0,100,0.01);
NoBars = 0;for (i = 0; i < BarCount - 1; i++) { NoBars++; } CurrentTO = MinTO; for (i = NoBars; i < BarCount - 1; i++) { { CurrentTO[i] = MinTO*(1 - inflationRate /100/250)^( BarCount - 1 - i); } } TOFilter = AveTO > CurrentTO AND Turnover > CurrentTO;
TOFilt = IIf(TOTog,TOFilter,1);The following is another solution albeit in Metastock code
Code:{Start}
{Metastock CPI (Australia) Turover Filter – written in Metastock v9 and will need to be modified for use after 2007}
Base:=500000;{Enter minimum system turnover for 2007 eg 500000}
YEARVAL:=If(Year()=2007,Base,If(Year()=2006,Base/1.033,
If(Year()=2005,Base/1.061,If(Year()=2004,Base/1.089,
If(Year()=2003,Base/1.115,If(Year()=2002,Base/1.148,
If(Year()=2001,Base/1.184,If(Year()=2000,Base/1.253,
If(Year()=1999,Base/1.276,If(Year()<=1998,Base/1.296,Base*20))))))))));{End} {If you wish to use this filter when back-testing copy from "{Start} to {End}" inclusive and paste it at the beginning of MetaStock exploration code. You will also need to amend the Turnover Filter in the EntryTrigger to show "YEARVAL" instead of an amount, for example, Mov(V*C,21,S)>=YEARVAL;}February 28, 2017 at 10:12 pm #106327SaidBitarMemberMaurice Petterlin wrote:I’ve come up with this so far.Code:for (i = NoBars; i < BarCount - 1; i++) { { CurrentTO[i] = MinTO*(1 - inflationRate /100/250)^( BarCount - 1 - i); } } TOFilter = AveTO > CurrentTO AND Turnover > CurrentTO;
TOFilt = IIf(TOTog,TOFilter,1);maybe I am wrong but the code looks a bit weird
first the for loop
you want to start with the total number which is NoBars that is OK but this means that you need to decrement not increment so it should beCode:for(i = NoBars; i > 0; i–)in this case you will set the minTO value as per today and then it will start decreasing as you go back in history
if you want to set the MinTO for the first day in your Backtest and increase the value as you move towards the current day then
Code:for (i = 0; i < BarCount ; i++) { { CurrentTO[i] = MinTO*(1 + inflationRate /100/250)^( BarCount - 1 - i); } } TOFilter = AveTO > CurrentTO AND Turnover > CurrentTO;
TOFilt = IIf(TOTog,TOFilter,1);then you need to start from Zero and you need to add the inflation
March 1, 2017 at 12:08 am #106330LeeDanelloParticipantI think I understand what you’re saying.
Just wondering if i = 0 is the start of the quotations on the chart or the start of the backtest period?CurrentTO was meant to be a current year input so it would depend on the length of the backtest to back calculate what the turnover would be.
Code:CurrentTO[i] = MinTO*(1 – inflationRate /100/250)^( BarCount – 1 – i);The attached spreadsheet might show the logic more clearly.
March 1, 2017 at 7:57 am #106331SaidBitarMemberanother question why do you need to calculate it based on days I believe you can adapt what Craig provided earlier will give you the desired results.
and is there a difference in the backtest results with and without inflation?
March 1, 2017 at 10:52 am #106340LeeDanelloParticipantCraig’s code works. I was trying an different angle without inputting the start and end dates.
If you use a constant TO filter in your backtest, it’s not strictly correct as the value of today’s turnover is different to that of 20 years ago. I’ve just made some adjustments to Craig’s formula.Code:TO = Volume*Close;CurrentTO = Param(“Initial Turnover – $”,700000,0,10000000,1000);
StartYear = Param(“Start Year”,2010,1995,2020,1);
EndYear = Param(“End Year”,2010,1995,2020,1);
noYears = (EndYear-StartYear+1);
TOInc = Param(“Average Inflation %”,1.03,0.01,10,0.01);
startTO = CurrentTO*(1-TOInc/100)^noYears;
Inc = (1+TOInc/100) ^ Max(0,Year()-StartYear+1);
IncTO = startTO * Inc;
Plot(IncTO,”IncTO”,colorRed,styleLine); -
AuthorPosts
- You must be logged in to reply to this topic.