Australian (ASX) Stock Market Forum

Rotational backtesting - buying a stock every third month

xxx

Joined
21 October 2016
Posts
31
Reactions
0
Hi, I'm a beginner in using amibroker.
I would like to use rotaitonal trading. My problem is that I would like to buy the 5 best stocks every third month. But I do not know how to do that. Is there anybody who could help me with this.
 
Hi, I'm a beginner in using amibroker.
I would like to use rotaitonal trading. My problem is that I would like to buy the 5 best stocks every third month. But I do not know how to do that. Is there anybody who could help me with this.

Hi XXX star....:D

You need to start by quantifying WHAT IS A BEST STOCK. For example, is a best stock based on a fundamental filter? Or is it based on a momentum filter? Also, i'm not sure that the 5 best stocks is an adequate diversification of the capital....perhaps the 10 or 20 best stocks....

Thats my :2twocents
 
Hi XXX star....:D

You need to start by quantifying WHAT IS A BEST STOCK. For example, is a best stock based on a fundamental filter? Or is it based on a momentum filter? Also, i'm not sure that the 5 best stocks is an adequate diversification of the capital....perhaps the 10 or 20 best stocks....

Thats my :2twocents



Well, I said that I would like to buy the 5 best stocks according to the best performance every third month.

my code:
newMonth = Month() != Ref(Month(), -1);

Nmonths = 3;

rotate = newMonth AND Cum(newmonth) % Nmonths == 0


Does it work like that?
 
Well, I said that I would like to buy the 5 best stocks according to the best performance every third month.

my code:
newMonth = Month() != Ref(Month(), -1);

Nmonths = 3;

rotate = newMonth AND Cum(newmonth) % Nmonths == 0


Does it work like that?

http://www.amibroker.com/kb/2016/04/17/long-only-rotational-back-test/

Set the AA window to backtest on monthly periodicity,
then something like this will be getting close.

SetBacktestMode( backtestRotational );
SetOption("MaxOpenPositions",5);
SetOption("WorstRankHeld",5);
SetPositionSize( 20, spsPercentOfEquity );
PositionScore = ROC( Close, 3); // highest 3 month ROC

You'll want to run this on say ASX50, not across the whole market. afaik, you can't specify turnover as a condition in rotational trading.
 
http://www.amibroker.com/kb/2016/04/17/long-only-rotational-back-test/

Set the AA window to backtest on monthly periodicity,
then something like this will be getting close.

SetBacktestMode( backtestRotational );
SetOption("MaxOpenPositions",5);
SetOption("WorstRankHeld",5);
SetPositionSize( 20, spsPercentOfEquity );
PositionScore = ROC( Close, 3); // highest 3 month ROC

You'll want to run this on say ASX50, not across the whole market. afaik, you can't specify turnover as a condition in rotational trading.


thank you very much for your answer.
What does SetPosistionSize(20,spsPercentOfEquity) do?

this is my code - could you reread it?


_SECTION_BEGIN("TTTT");


SetTradeDelays (0,0,0,0);

SetBacktestMode(backtestRotational);

SetOption("UsePrevBarEquityForPosSizing", True); // use previous bar opening equity to perform position sizing
SetOption("MinShares", 1); // minimum number of shares required to open the position in the backtester
SetOption("AllowPositionShrinking", True);
SetOption("AccountMargin",100); // Gewinnmarge 100 = keine Begrenzung

MaxOpenPositions = 5;
SetOption("WorstRankHeld", MaxOpenPositions ); // worst rank of symbol to be held in trading mode
SetOption("MaxOpenPositions", MaxOpenPositions);
SetOption("SeparateLongShortRank", True );
SetOption("MaxOpenLong", 5); // 5 beste Aktien raussuchen
SetOption("MaxOpenPositions",5);

newMonth = Month() != Ref(Month(), -1);


Nmonths = 3;

rotate = newMonth AND Cum(newmonth) % Nmonths==0;

perf = TimeFrameGetPrice("O", inMonthly, -1); // get monthly Open price 1 month ago
perf1 = TimeFrameGetPrice("O", inMonthly, -2); // get monthly Open price 2 month ago


score= 100*((perf- perf1)/perf1) + 100;

PositionSize = -100/MaxOpenPositions;

PositionScore = IIf(rotate,PositionScore,scoreNoRotate);
// scoreNoRotate = already open trades should be kept and no new trades entered
 
thank you very much for your answer.
What does SetPosistionSize(20,spsPercentOfEquity) do?

positionsize is set to 20% of available equity.

see: https://www.amibroker.com/guide/afl/setpositionsize.html

Not sure about the rest of it. I've never had much luck with rotational trading, but there are some quite advanced threads on 'AB Yahoo Groups forum'.

11pm Saturday night and I'm answering a forum question ... :bonk:
 
Top