In my AP Statistics class, the coverage of Pearson's Correlation Coefficient was pretty limited. It boiled down to "it's a measure of correlation such that $\hat{z_{y}}=rz_{x}$", and he only told us that to emphasize that units don't affect the value of $r$.
Curious, I tried to derive a formula for $r$ using my Calculus knowledge, since all it is is an optimization problem, and he had told us that the goal of regression is to minimize the squared errors of each point. So, these are the steps I took: \begin{align*} \hat{z}_{y}&=rz_{x}\\ r&=\arg\min_{r}\sum_i \left(z_{y_i}-rz_{x_i}\right)^2\\ &=\arg\min_{r}\sum_i\left(z_{y_i}^2-2rz_{y_i}z_{x_i}+r^2z_{x_i}^2\right)\\ &=\arg\min_{r}\sum_i\left(z_{y_i}^2\right)-2r\sum_i\left(z_{y_i}z_{x_i}\right)+r^2\sum_i\left(z_{x_i}^2\right)\\ 0&=\frac{d}{dr}\left[\sum_i\left(z_{y_i}^2\right)-2r\sum_i\left(z_{y_i}z_{x_i}\right)+r^2\sum_i\left(z_{x_i}^2\right)\right]\\ &=2r\sum_i\left(z_{x_i}^2\right)-2\sum_i\left(z_{y_i}z_{x_i}\right)\\ r\sum_i z_{x_i}^2&=\sum_i z_{y_i}z_{x_i}\\ r&=\frac{\sum_iz_{x_i}z_{y_i}}{\sum_iz_{x_i}^2}\\ \end{align*}
But, today, my teacher put the following equation on the board, which seems inconsistent with that: \begin{equation*} r=\frac{\sum_i z_{x_i}z_{y_i}}{n-1} \end{equation*}
Am I wrong, or are these simply formulas that apply in different situations? I'm new to statistics so I could've easily made a faulty assumption somewhere