Australian (ASX) Stock Market Forum

Yes realistic tax handling in backtesting is not easy
I just average the return per year then remove tax due per year and start again
Provisional tax will not help especially in a draw down as any attempt to lower that provisional tax before eofy can end up in fines if there is a rebund in June..
Working agile in a prehistoric system is not easy...
 
I just average the return per year then remove tax due per year and start again
Provisional tax will not help especially in a draw down as any attempt to lower that provisional tax before eofy can end up in fines if there is a rebund in June.

One of these days, the end goal to become a non-resident will make my backtests realistic :D
 
For entertainment or maybe educational purposes here's my complete bogus system, fully disclosed.
I'm not posting performance figures - what would be the point? You've all got Amibroker.
It's run on the full ASX, not the current AllOrds including historical constituents which is popular here but a serious future leak.
See if you can work out what's wrong with it. If not, try trading it; you won't lose any money if you follow the rules.

// Bogus System
// impossible to execute
// optimized for 1/7/2010 to mid-2016
// but parameters don't matter all that much

PositionScore = Ref(ROC(C, 3), -1) ;

PosQty = 100 ; // there's nothing wrong with that
// it's a conservative form of compounding with fixed position size
PosSize = 7500 ;
BuyLimit = Ref(MA(C, 7), -2) - Ref(ATR(20), -1) * 2 ; // over-optimized
LookBack = 250 ;
AvgTurnOver = 2000000 ;

SetOption("InitialEquity", 20000);
SetOption("MaxOpenPositions", PosQty);
SetPositionSize( PosSize, spsValue);
SetOption("CommissionMode", 1);
SetOption("CommissionAmount", 0.08); // Interactive Brokers
SetOption("AllowSameBarExit", True);
SetTradeDelays (0,0,0,0);

BuySig = C < Ref(C, -1)
AND C > MA(C, LookBack)
AND MA(C * V, 60) > AvgTurnOver;

Buy = Ref(BuySig, -1) AND Low < BuyLimit;
BuyPrice = Min( Open, BuyLimit);

Sell = Close > Open;
SellPrice = Close;

// exploration

MR = BuySig;
Filter = MR AND Status("lastbarinrange");
AddColumn( Ref(MA(C, 7), -1) - ATR(20),"BuyLimit", 2.3 );
AddColumn( abs(ROC(C, 3)),"ROC", 2.3 );

// scan
AddToComposite(BuySig, "~~MANY", "V", 1);
 
How about the Low could bust the BuyLimit mid session so the backtest is picking the min. between the Open and BuyLimit?

ie: impossible to go back and buy at the Open

Also, the AB code checker doesn't pick up a problem :)
 
How about the Low could bust the BuyLimit mid session so the backtest is picking the min. between the Open and BuyLimit?

ie: impossible to go back and buy at the Open

Also, the AB code checker doesn't pick up a problem :)

No. You need to understand what the code does.
The BuyLimit is known after the close of the previous day for every potential stock that is produced by the exploration. I have included it for that reason.
On the morning of the trading day we look if we can pick up any of those stocks for a price below the limit price. So we enter a limit order just below the calculated price. If we get filled, that's fine; if we don't, that's fine too.
Sometimes we get filled at the open, sometimes mid-session and sometimes at the close. It's all the same for the Amibroker backtester.
The reason for the Min() expression is that if the Open price is below the limit price, then Amibroker would use the limit price as BuyPrice in backtests whereas in reality we were obtaining the lower Open price.

Of course the AB code checker doesn't pick up a problem, that would be too easy.
 
Sell = Close > Open;
SellPrice = Close;
If I had to guess (as I am not a programmer in the slightest) I would say using close>open sellprice=close would mean you would not get the close price as the markets would be closed. So you would be selling the next day at previous close price and it would be hit or miss if you got your price or not.
 
If I had to guess (as I am not a programmer in the slightest) I would say using close>open sellprice=close would mean you would not get the close price as the markets would be closed. So you would be selling the next day at previous close price and it would be hit or miss if you got your price or not.


You're probably not a trader either or you would know how it works.
So this is what you do: at 4 PM you look at the stocks you're holding and enter a limit sell order at one tick above the open price. You have to do this in a hurry if there are many of them, but there is nothing preventing you from having a whole bunch of sell forms ready well before 4 PM to confirm with one click on each, although some trading platform have limitations. The Open price is known almost 6 hours before the close, right? You click confirm just after 4 PM to catch the official closing price that will appear in future backtests.
Then at 4:10 PM you get filled or you don't.
I do this every day and have done for years. Yes, sometimes I get partial fills or no fill at all when I'm too far down in the queue. It doesn't need to be perfect.
 
You're probably not a trader either or you would know how it works.
So this is what you do: at 4 PM you look at the stocks you're holding and enter a limit sell order at one tick above the open price. You have to do this in a hurry if there are many of them, but there is nothing preventing you from having a whole bunch of sell forms ready to confirm with one click on each well before 4 PM, although some trading platform have limitations. The Open price is known almost 6 hours before the close, right? You confirm just after 4 PM to catch the official closing price that's in the backtest.
Then at 4:10 PM you get filled or you don't.
I do this every day and have done for years. Yes, sometimes I get partial fills or no fill at all when I'm too far down in the queue. It doesn't need to be perfect.
Yeah I personally couldn't care less about waiting 2mins before close as that's not my style but hey what ever works for you. Just thought I would join in the convo and have a poke at the answer as it is interesting to see what other people get up to in their trading.
 
So we enter a limit order just below the calculated price.

OK don't know the future leak is but a couple of things...

There is no code to exit expired stocks so your going to lock up capital when running a backtest (especially using historical constituents). Norgate has code to fix this.

Secondly running an exploration, there's a whopping load of stocks to add limit orders to unless your using an API with IB.

Something like this: https://www.theportfoliotrader.com/downloads/automated-trader-for-the-chartist/
Edit: using that, you can also limit your PosQty
 
Last edited:
OK don't know the future leak is but a couple of things...

There is no code to exit expired stocks so your going to lock up capital when running a backtest (especially using historical constituents). Norgate has code to fix this.

True, I didn't even think of that. But that is not a future leak, just wasted resources in the backtest. It would reduce returns.
I don't know why you mention historical constituents. I've specifically said that I use ALL ASX tickers.

Secondly running an exploration, there's a whopping load of stocks to add limit orders to unless your using an API with IB.

Something like this: https://www.theportfoliotrader.com/downloads/automated-trader-for-the-chartist/
Edit: using that, you can also limit your PosQty

Excellent point. But it doesn't make it impossible to execute, only difficult. There are bigger problems.

The purpose of my original post was to show how subtle logic errors can give wildly optimistic results. Admittedly, there is some smart arse grandstanding involved because I was curious to see if anyone here could figure out where the logic errors were. But it might be educational too. I mean it's a bit of a worry if you don't pick up future leaks in the code. Mind you, after a week or so of trading the bogus system you would see the problems.
 
One of these days, the end goal to become a non-resident will make my backtests realistic :D
Not sure if you are pulling a leg but this is indeed my aim
I can not afford Australian tax on pure investment returns for the next 10y just to reach the official pension age
 
Not sure if you are pulling a leg but this is indeed my aim

No, definitely not. Been planning for a long time but only learned the tax ramifications the past few years.

Here, you need a good cash buffer to cover provisional tax without busting the system (selling to pay tax).
 
I haven't tried this system on daily or weekly timeframes yet. My original desire was for a monthly system as I currently trade daily and weekly systems so that hasn't been a focus for me yet. Correct, I'll paper trade to see how some of the initial trades compare to a few characteristics of my sims.

Back on topic!
Besides modifying system parameters to suit a daily system (in order to paper trade quicker) you could also run Explorations and check against your Charting and step through numerous trades using Bar Replay to see if there is anything unexpected ...like moving buy signals :)

If anyone super keen, could do that with the above Bogus System too.
 
Back on topic!
Besides modifying system parameters to suit a daily system (in order to paper trade quicker) you could also run Explorations and check against your Charting and step through numerous trades using Bar Replay to see if there is anything unexpected ...like moving buy signals :)

Thanks. I recently did a similar thing by randomly selecting a few trades from the Explorer list and manually "calculated" by entries and exits based on the charts alone and these seem to match the corresponding selected trades from the Explorer. I might give your suggested technique a go just to double check.
 
'Morning All,
This post is a little overdue, but ran my first Explore for entries on 31 Dec. No Entries flagged so my paper account is still 100% cash at $50k. I'll be running my next scan at the end of Jan.
 
Hi All,
Meant to post Feb positions over the weekend, but been distracted. So here it is: my system entered 3 positions at the start of Feb, which are CAT, PNV and RUL. These are the first buy signals generated by my system since I started paper trading it at the beginning of the year. As mentioned in my original post my position sizing is very simple: max of 20 open positions with each position being 5% of portfolio value. So the positions of CAT, PNV and RUL will each be approximately $2.5k given I have a theoretical $50k portfolio value (currently all cash and no open positions). I'll try and do a fancy table with position details soon, but in the meantime this will have to do.
Cheers all.
 
Hi MovingAverage, how long are you going to paper trade?
My initial thoughts were to paper trade for about 6 months, but being monthly I'm now starting to think that may not be long enough so I'm thinking I might paper trade for the entire CY.
 
2019 was an interesting year to paper trade as the first half did well then went sideways, going back through it and paper trading would be worthwhile.
 
Top