MATLAB: How to retrieve all of the index member names from Bloomberg using the Datafeed Toolbox

500datafeedDatafeed Toolboxfetchindicessp

I am looking for a way to display something like the S&P500 index members in MATLAB using the Datafeed Toolbox.

Best Answer

The following code demonstrates how you may display the S&P500 members in MATLAB using the Datafeed Toolbox.
B = bloomberg
D = fetch(B,'SPX Index','GETDATA','INDX_MEMBERS');
D.INDX_MEMBERS{:}
This returns the securities that make up the S&P500 index.
Here is an example of the override parameter to return the securities for a particular date.
B = bloomberg
d = fetch(B,'SPX Index','GETDATA','INDX_MWEIGHT',{'END_DT'},{'20080919'});
Please note that the 'END_DT' override is not a valid override for the 'INDX_MEMBERS' field. Thus, adding this override to your request does not change the content of 'INDX_MEMBERS'. If you would like the index members for a particular date, the following code illustrates how to accomplish this with 'INDX_MWEIGHT':
B = bloomberg
d = fetch(B,'SPX Index','GETDATA','INDX_MWEIGHT',{'END_DT'},{'20080919'});
members = d.INDX_MWEIGHT{1};