Almost all calculations in finance involve using log returns rather than % returns. There are a number of reasons why log returns are preferred. Estimating beta doesn’t seem like a special case.

But when you go through the math, something doesn’t quite add up.

Because we want to zero out market risk, so want to solve for $w$ such that $r_{M}$ is no longer in the equation below.

After going through this, the math quickly gets very messy.

If we use % returns, the math is alot cleaner.

After some basic algebra, we find that $w = \beta \frac{S_0}{M_0}$.

So there you have it. Time to change some code.