Sam J
Sam J

Reputation: 1

Momentum Score exploration AFL

I want to build Exploration AFL. Below is the scenario.

Momentum Score:

Monthly momentum values are calculated as cumulative returns over the past 12 months.

The monthly momentum is calculated in 3 steps

1) We calculate gross monthly returns by adding one to the percent monthly return. For example, from a monthly return of 5% (0.05), we get the gross monthly return value of 1.05 (0.05 + 1) while from a monthly return of -5% (-0.05) we get a gross monthly return of 0.95 (0.05 + 1.0).

2) We multiply all the gross monthly returns of past 12 months.

3) We subtract one from the resultant value from step 2 to get the net 12-month momentum score.

To illustrate this calculation, let's say AUROPHARMA (Aurobindo Pharma) stock has moved by 2%, -5%, 4.3%, 0.5%, 10.1%, -2.2%, 6%, 3.6%, 0.1%, 0.4%, 1.4%, -2.6% over the past 12 months. Then, we add 1 to monthly return, multiply all of them & subtract one from it to get the momentum score.

Momentum Score = (1.02)(0.95)(1.043)(1.05)(1.101)(0.978)(0.94)(1.036)(1.001)(1.004)(1.014)*(0.974) - 1 This will give a momentum score of 10.45% (0.1045) to the Aurobindo Pharma Stock.

Can someone please help?

Upvotes: 0

Views: 1250

Answers (2)

Prasad Rao
Prasad Rao

Reputation: 1

TimeFrameSet(inMonthly);

mclose = C;

mclose1 = Ref(C,-1);

mclose2 = Ref(C,-2);

mclose3 = Ref(C,-3);

mclose4 = Ref(C,-4);
mclose5 = Ref(C,-5);

mclose6 = Ref(C,-6);

mclose7 = Ref(C,-7);

mclose8 = Ref(C,-8);

mclose9 = Ref(C,-9);

mclose10 = Ref(C,-10);

mclose11 = Ref(C,-11);

mclose12 = Ref(C,-12);

TimeFrameRestore();

mclose = TimeFrameExpand(mclose,inMonthly, expandFirst);

mclose1 = TimeFrameExpand(mclose1,inMonthly, expandFirst);

mclose2 = TimeFrameExpand(mclose2,inMonthly, expandFirst);

mclose3 = TimeFrameExpand(mclose3,inMonthly, expandFirst);

mclose4 = TimeFrameExpand(mclose4,inMonthly, expandFirst);

mclose5 = TimeFrameExpand(mclose5,inMonthly, expandFirst);

mclose6 = TimeFrameExpand(mclose6,inMonthly, expandFirst);

mclose7 = TimeFrameExpand(mclose7,inMonthly, expandFirst);

mclose8 = TimeFrameExpand(mclose8,inMonthly, expandFirst);

mclose9 = TimeFrameExpand(mclose9,inMonthly, expandFirst);

mclose10 = TimeFrameExpand(mclose10,inMonthly, expandFirst);

mclose11= TimeFrameExpand(mclose11,inMonthly, expandFirst);

mclose12 = TimeFrameExpand(mclose12,inMonthly, expandFirst);
 
GfxTextOut("mclose = "+mclose,20,20);

GfxTextOut("Ref(C,-1) = "+Ref(C,-1),20,40) ;

GfxTextOut("Ref(C,-2) = "+Ref(C,-2),20,60) ;

GfxTextOut("Ref(C,-3) = "+Ref(C,-3),20,80) ;

GfxTextOut("Ref(C,-4) = "+Ref(C,-4),20,100) ;

GfxTextOut("Ref(C,-5) = "+Ref(C,-5),20,120) ;

GfxTextOut("Ref(C,-6) = "+Ref(C,-6),20,140) ;

GfxTextOut("Ref(C,-8) = "+Ref(C,-8),20,180) ;

GfxTextOut("Ref(C,-9) = "+Ref(C,-9),20,200) ;

GfxTextOut("Ref(C,-10) = "+Ref(C,-10),20,220) ;

GfxTextOut("Ref(C,-11) = "+Ref(C,-11),20,240) ;

GfxTextOut("Ref(C,-12) = "+Ref(C,-12),20,260) ;

Change1 = Prec((((mclose -mclose1) /mclose1)+1),2) ;

GfxTextOut("Change1  "+Change1,250,40);

Change2 = Prec((((mclose1 - mclose2) /mclose2)+1 ),2) ;

GfxTextOut("Change2  "+Change2,250,60);


Change3 = Prec((((mclose2 - mclose3) /mclose3)+1 ),2) ;

GfxTextOut("Change3  "+Change3,250,80);

Change4 =  Prec((((mclose3 - mclose4) /mclose4)+1 ),2) ;

GfxTextOut("Change4  "+Change4,250,100);

Change5 =  Prec((((mclose4 - mclose5) /mclose5)+1 ),2) ;

GfxTextOut("Change5  "+Change5,250,120);

Change6 =  Prec((((mclose5 - mclose6) /mclose6)+1 ),2) ;

GfxTextOut("Change6  "+Change6,250,140);

Change7 =  Prec((((mclose6 - mclose7) /mclose7)+1 ),2) ;

GfxTextOut("Change7  "+Change7,250,160);

Change8 =  Prec((((mclose7 - mclose8) /mclose8)+1 ),2) ;

GfxTextOut("Change8  "+Change8,250,180);

Change9 =  Prec((((mclose8 - mclose9) /mclose9)+1 ),2) ;

GfxTextOut("Change9  "+Change9,250,200);

Change10 =  Prec((((mclose9 - mclose10) /mclose10)+1 ),2) ;

GfxTextOut("Change10  "+Change10,250,220);

Change11 =  Prec((((mclose10 - mclose11) /mclose11)+1 ),2) ;

GfxTextOut("Change11  "+Change11,250,240);

Change12 =  Prec((((mclose11 - mclose12) /mclose12)+1 ),2) ;

GfxTextOut("Change12  "+Change12,250,260);


MOMENTUM_SCORE_3MONTHS = Prec(((Change1 * Change2 * Change3) - 1)*100,2);

GfxTextOut("MOMENTUM_SCORE_3MONTHS  "+MOMENTUM_SCORE_3MONTHS+ " %  ",400,20);


MOMENTUM_SCORE_6MONTHS = Prec(((Change1 * Change2 * Change3 * Change4 * Change5  * Change6) - 1)*100,2);

GfxTextOut("MOMENTUM_SCORE_6MONTHS  "+MOMENTUM_SCORE_6MONTHS+ " %  ",400,40);

MOMENTUM_SCORE_12MONTHS = Prec(((Change1 * Change2 * Change3 * Change4 * Change5  * Change6 * Change7 * Change8 * Change9 * Change10 * Change11  * Change12) - 1)*100,2);

GfxTextOut("MOMENTUM_SCORE_12MONTHS  "+MOMENTUM_SCORE_12MONTHS+ " %  ",400,60);



_SECTION_END();

Filter  =   MOMENTUM_SCORE_12MONTHS ;

AddColumn(MOMENTUM_SCORE_12MONTHS ,"MOMENTUM_SCORE_12MONTHS ",1, colorBlack, colorLavender,40);

AddTextColumn( IndustryID( 1 ), "INDUSTRY",1, colorAqua, colorBlue,250 );

AddTextColumn( SectorID( 1 ), "SECTOR" ,1, colorAqua, colorBlue,100 );

Upvotes: 0

Surendar suren
Surendar suren

Reputation: 1

TimeFrameSet(inMonthly);
TtD_Change = 100 * (Close - Ref(Close, -12) ) / Ref(Close, -12);

_SECTION_BEGIN("Explorer");

Filter = 1;

AddColumn(TtD_Change,"Momentum",1.2,IIf(TtD_Change>0,colorGreen,colorRed));

_SECTION_END();

Upvotes: -1

Related Questions