Let say I have $n$ assets and their returns over $m$ periods which are represented by a matrix $X \in \mathbb{R}^{m \times n}$, and I have some other asset with return over the same period which is represented by a vector $y \in \mathbb{R}^m$.
My objective is to find a vector of weights $w$ such that
$$w^* = \underset{w}{\arg \min} ~ \text{TE}(w)$$
where $\text{TE}(w)$ is the tracking error defined as follows:
$$\text{TE}(w) = \sqrt{\text{Var}(Xw - y)}$$
and
$$ \sum_{i=1}^n w_i =1 $$
In short, I want to replicate $y$ using a portfolio of assets $X$.
My idea was to use the exact definition of the tracking error mentioned above through an optimizer.
However, somebody suggested to use the following:
$$ w^* = \underset{w}{\arg \min} ~ \sum_{i=1}^m (Xw-y)_i^2 $$
I tried both and I get a better tracking error with the first one.
It seems clear to me that both should return exactly the same if indeed there exists some $w$ which perfectly replicates $y$.
What if it's not the case?
Is there another approach?