I did not read carefully, but it strikes me that maybe something is wrong in the formulas (I looked only at the first one).
In variance formula, shouldn't you square the returns, and center them if using N-1, or divide by N instead of N-1 if no centering?