AddComposite & MarketCap Weighting

Does anyone have some example code to weight a stock by its marketcap when adding to an index composite?

To create market-cap weighted composite just multiply close by number of shares before adding to the composite. You can divide by million to get more ‘resonable’ number.

marketcapdata = Close * GetFnData("SharesOut") * 1e-6; // in Millions of dollars cap
AddToComposite( marketcapdata , "~~~COMP", "X" );
1 Like

How would this be further formulated to select only the top x by market cap weight for inclusion into the comp? Percentile only seems to work on a single-security array and not a vector of multiple security’s market caps.

Nevermind, I have figured it out with the StaticVarGenerateRanks.