Sector rotation

#21
Sector rotation is one of the most important concepts in investing.

I will suggest the following two steps (hope you have amibroker):
1. Have a list of all major sectors and their important component stocks.- some other members may help you with that
2. Construct sector indices- I can help with that

This will initially take some time but very easy once you are done. Just using normal EOD databse you can compare long term charts of various sectors. And filter the stocks as per relative strength ranking.

Dear trader21,

I downloaded a trial version of amibroker and cannot find NSE or BSE exchanges. I see only NYSE and Nasdaq. Should I need to install paid full version of amibroker to do all the things mentioned by you?

Thanks
Senthil
 

1sandeepgupta

Well-Known Member
#22
The improved version of sector index creation and updating is as under

//Choose market NSE for Automatic Analysis and run scan, it will return nothing but make and update sector's composite indexes in group 253.
// n is the number of stocks in different sectors.
if(SectorID() == 0)

{

sym="~" + "Automotive";
n=57;

AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}

if(SectorID() == 1)

{

sym = "~" + "Banking & Financial Services";
n = 61;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 2)

{

sym = "~" + "Consumer Durables";
n = 2;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 3)

{

sym = "~" + "Cement and Construction";
n= 29;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 4)

{

sym = "~" + "Consumer Non-durables";
n = 13;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 5)

{

sym = "~" + "Chemicals";
n= 30;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 6)

{

sym = "~" + "Conglomer";
n= 9;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 7)

{

sym = "~" + "Engineering & Capital Goods";
n = 37;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 8)

{

sym = "~" + "Food & Beverages";
n= 23;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 9)

{

sym = "~" + "Information Technology";
n= 29;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 10)

{

sym = "~" + "Manufacturing";
n = 42;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 11)

{

sym = "~" + "Media and Entertainment";
n= 19;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 12)

{

sym = "~" + "Metals & Mining";
n = 25;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 13)

{

sym = "~" + "Oil & Gas";
n = 15;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 14)

{

sym = "~" + "Pharmaceu";
n = 36;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 15)

{

sym = "~" + "Real Estate";
n = 14;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 16)

{

sym = "~" + "Services";
n = 25;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 17)

{

sym = "~" + "Telecommunication";
n = 20;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 18)

{

sym = "~" + "Tobacco";
n = 3;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}
if(SectorID() == 19)

{

sym = "~" + "Utilities";
n = 10;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}

if(SectorID() == 20)

{

sym = "~" + "Miscellaneous";
n = 18;
AddToComposite( L/n, sym,"L");

AddToComposite( O/n, sym,"O");

AddToComposite( H/n, sym,"H");

AddToComposite( C/n, sym,"C");

AddToComposite( V/n, sym, "V");

}

Buy=Sell=Short=Cover=0;

Filter=1;
Enjoy,
Sandeep Gupta.
 

trader21

Active Member
#23
Sandeep,

As I said previously coding is the easiest part. The thing which requires effort is a good understanding of what we do. Without proper understanding, the code can only do Garbage In Garbage Out

Going back,
Have a list of all major sectors and their important component stocks
The List given by Mr. Raunk is a good start
Construct sector indices
I hope someone read the NSE FAQs link posted earlier.

We can construct Four type of index:
  1. Price weighted: easiest to code but practically useless. Why? take the sugar sector for example. BanariSug will have more than 3 times weightage than Reunka while in reality Banarisug is such a thin stock that it can be even be neglected in construction of index.
  2. Price, Volume weighted: This is again useless. The reason being there are often volume spikes in a stock. So if a stock trades double volume at particular day, its weightage in the index will suddenly double. Hence the price movements in index will be almost useless.
  3. Price, Avg. Volume weighted: Average volume over a period of time is used instead of daily volume. This is of some use. Very easy to maintain since we only need OHLC data. Check attached afl
  4. Price, Free Float Weighted: This is the methodology which NSE uses itself. To construct such we will need to maintain data of free float of each stock. If someone has the data in XL sheet, it can be easily imported to "OI" field for each stock and the index maintained easily.

What are the benefits of including free floats?

1. A Free-float index reflects the market trends more rationally as it takes into consideration only those shares that are available for trading in the market.

2. Free-float Methodology makes the index more broad-based by reducing the concentration of top few companies in Index. For example, the concentration of top five companies in SENSEX has fallen under the free-float scenario thereby making the SENSEX more diversified and broad-based.

3. A Free-float index aids both active and passive investing styles. It aids active managers by enabling them to benchmark their fund returns vis--vis an investable index. This enables an apple-to-apple comparison thereby facilitating better evaluation of performance of active managers. Being a perfectly replicable portfolio of stocks, a Free-float adjusted index is best suited for the passive managers as it enables them to track the index with the least tracking error.

4. Free-float Methodology improves index flexibility in terms of including any stock from the universe of listed stocks. This improves market coverage and sector coverage of the index. For example, under a Full-market capitalization methodology, companies with large market capitalization and low free-float cannot generally be included in the Index because they tend to distort the index by having an undue influence on the index movement. However, under the Free-float Methodology, since only the free-float market capitalization of each company is considered for index calculation, it becomes possible to include such closely held companies in the index while at the same time preventing their undue influence on the index movement.

5. Globally, the Free-float Methodology of index construction is considered to be an industry best practice and all major index providers like MSCI, FTSE, S&P and STOXX have adopted the same. MSCI, a leading global index provider, shifted all its indices to the Free-float Methodology in 2002. The MSCI India Standard Index, which is followed by Foreign Institutional Investors (FIIs) to track Indian equities, is also based on the Free-float Methodology. NASDAQ-100, the underlying index to the famous Exchange Traded Fund (ETF) - QQQ is based on the Free-float Methodology.

Dear trader21,

I downloaded a trial version of amibroker and cannot find NSE or BSE exchanges. I see only NYSE and Nasdaq. Should I need to install paid full version of amibroker to do all the things mentioned by you?

Thanks
Senthil
I dont think all people using here amibroker have its paid version. Also, if you understand the logic, the coding can be done in many software.
 

trader21

Active Member
#24
/*AFL for constructing volume weighted sector indices. It uses average daily volume in weighting
which is a good proxy for market capitalisation weighted index.
1. You will need a neat and clean EOD database to use the same. Incorrect data can skew the index values
2. Sector studies recommended for use on atlast 5 years data
3. In "Automatic Analysis" window, pick this afl and set n=1 in range. Then hit "scan" button to create index.
4. Say NO to scam and spam. Join free thetradersforum.net
*/

Buy = 0; // required by scan mode
Sell= 0;

sym="~"+SectorID(1);
AddToComposite( MA(V,100), sym, "V" );
AddToComposite( 1, sym, "I" );
AddToComposite(C*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"C");
AddToComposite(O*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"O");
AddToComposite(H*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"H");
AddToComposite(L*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"L");

//This part is only for checking index values in Exploration
Filter= SectorID(1)== "Transportation";
AddColumn(Foreign( sym, "C" ), "C");
AddColumn(Foreign( sym, "V" ), "V");
AddColumn(Foreign( sym, "I" ), "I", 1.0);
AddTextColumn(SectorID(1), "sector");
 
Last edited:
#26
/*AFL for constructing volume weighted sector indices. It uses average daily volume in weighting
which is a good proxy for market capitalisation weighted index.
1. You will need a neat and clean EOD database to use the same. Incorrect data can skew the index values
2. Sector studies recommended for use on atlast 5 years data
3. In "Automatic Analysis" window, pick this afl and set n=1 in range. Then hit "scan" button to create index.
4. Say NO to scam and spam. Join free thetradersforum.net
*/

Buy = 0; // required by scan mode
Sell= 0;

sym="~"+SectorID(1);
AddToComposite( MA(V,100), sym, "V" );
AddToComposite( 1, sym, "I" );
AddToComposite(C*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"C");
AddToComposite(O*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"O");
AddToComposite(H*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"H");
AddToComposite(L*(MA(V,100)/Foreign( sym, "V" ))/Foreign( sym, "I" ),sym ,"L");

//This part is only for checking index values in Exploration
Filter= SectorID(1)== "Transportation";
AddColumn(Foreign( sym, "C" ), "C");
AddColumn(Foreign( sym, "V" ), "V");
AddColumn(Foreign( sym, "I" ), "I", 1.0);
AddTextColumn(SectorID(1), "sector");

Hi Trader21,

Thanks for highlighting the important of volume weighted average for Index. However, In the above program, I could not able to understand dividing again by Foreign("sym",I) as you have already divided MA volume of stock to Total Volume. Second. Whenever I scan the program, the value of "OHCL" changes with each scan.I have tried everything but I could not able to understand why it is happening. Pl help.
 

Similar threads