# Recovering index weights via least squares regression on components

As an exercise, I wanted to re-construct the index weights for the Nasdaq-100 (^NDX) via linear regression. For these purposes I got the daily adjusted close of its 103 components from alphavantage.co (NFLX example link), and did a least-squares linear regression on the index adjusted close (for this I used one of two sources: alphavantage.co's QQQ which tracks the NDX, as well as Yahoo's NDX from here). I used data for 168 market days approximately Mar-Oct 2019.

I tried the regression on: the raw adjusted price, the daily returns, and the daily price differences; but every time I got the wrong answer, by comparing my results to the weights given here; in particular, BKNG comes up quite high in my results (1st or 2nd) in spite its actual weight not being large.

Should I be able to recover index weights via this method, i.e. is what I'm doing theoretically sound and I have a bug in my code? Could it be a data issue? Or if not, could you please direct me towards the correct method for doing that? Or explain why it's impossible?

• Your method seems inherently inaccurate. You are estimating 103 coefficients with only 168 observations (1.6 obs per coeff). You could improve accuracy by using many times more observations, but even so I am not sure the accuracy will be sufficient for practical use. What is the uncertainty (standard deviation) of your coefficient estimates? Dec 12, 2019 at 19:06
• Isn't the nasdaq just a market-cap weighted index so assuming the number of share in issue remains constant in the last 103 days you have the linear system $$P w \propto I \quad \implies w \propto P^{-1}I$$ where P is last 103 days of stock prices, I is the index price vector and w is weights?
– Attack68
Dec 12, 2019 at 21:09
• @Attack68 number of shares is definitely NOT constant, but you're right, if you know the components, the weights are proportional to market cap Dec 13, 2019 at 1:44
• Thanks a lot guys! I needed the confirmation to keep at it and I found my bug -- I was solving A = BX instead of AX = B -- now that's fixed and I get an average absolute deviation of 0.005% between true and estimated index prices. The big weights are mostly right, small ones are a bit off, with some negative, but that's what you get when there exist multiple accurate explanations. Thanks again!
– Gabi
Dec 14, 2019 at 0:30