the turning point test If $y_1, \ldots, y_n$ is a sequence of observations, we say that there is a turning point at time $i$, $1 < i < n$, if $y_{i−1} < y_i$ and $y_i > y_{i+1}$, or if $y_{i−1} > y_i$ and $y_i < y_{i+1}$.
If $T$ is the number of turning points of an iid sequence of length $n$, then the expected value of $T$ is
$$E(T)= 2(n − 2)/3.$$
It can also be shown for an iid sequence that the variance of $T$ is
$$\text{Var}(T)= (16n − 29)/90.$$
Can anyone tell me how we compute the expected value and the variance, please?
 A: This assumes the distribution of $y_i$ is absolutely continuous. 
For sequence of length $n$, let $X_i$ denote the indicator random variable that there is a turning point on $i,i+1,i+2$. Then the number of turning points is: $T_n=X_1+\cdots+X_{n-2}$. Focus on $X_1$. The chance of a turning point on $1,2,3$ is equivalent to the order statistics $y_1<y_2$ and $y_3<y_2$ or $y_1>y_2$ and $y_3>y_2$. Since order statistics for iid absolutely continuous random variables are the same as order statistics for uniform permutations, there are only four permutations that contribute: $132$,$231$,$312$,$213$, giving $4/3!=2/3$ probability:
$$E[T_n]=(n-2)E[X_1]=\frac{2(n-2)}{3}.$$
For calculating the variance, it will suffice to find $E[T_n^2]$. Notice that $X_i,X_j$ are independent for $|i-j|\geq 2$. So break the covariances into $E[X_iX_j]$ for $|i-j|<2$ and otherwise. For say $X_1,X_2$, there are two options: \ / \ and / \ / which contribute, so there are 8 permutations: $4132,4231,3142,3241,\cdots$
$$E[X_1X_2]=\frac{8}{4!}=1/3.$$
Thus:
\begin{align*}
E[T_n^2]&=\sum_{i=1}^{n-2} E[X_1^2]+2\sum_{i<j,|i-j|\geq 2}E[X_iX_j]+2\sum_{i=1}^{n-3}E[X_iX_{i+1}]\\
&=\frac{2}{3}(n-2)+[(n-2)^2-(n-2)-(n-3)]E[X_1]^2+(n-3)\frac{2}{3},
\end{align*}
simplifying which gives:
$$E[T_n^2]-E[T_n]^2=\frac{2}{9}(2n^2-10n+13).$$
Double check the above arithmetic. I think your variance is wrong because if you plug in $n=3$, you get $19/90$, whereas I get $2/9$, and for $n=3$ there's only $X_1$:
$$E[X_1^2]-E[X_1]^2=2/3-(2/3)^2=2/9$$
A: I think the solution provided by Alex is incorrect. 
I cheat a bit and used R help. First we will write a program to evaluate the different probabilites of the sequences. 
> findMifne <- function(x) { 
+   d.x <- sign(diff(x))
+   n <- length(d.x)
+   temp.vec <- rep(F, n + 1)
+   for (i in 2:n) { 
+     temp.vec[i] <- ifelse(d.x[i] == d.x[i-1],F,T)
+   }
+   return(temp.vec)
+ }
> 
> temp.list <- do.call('rbind', permn(1:5))
> mat.logic <- t(apply(temp.list, 1, findMifne))
> mean(mat.logic[,2] + mat.logic[,4] == 2)
[1] 0.45
> 
> 
> temp.list <- do.call('rbind', permn(1:4))
> mat.logic <- t(apply(temp.list, 1, findMifne))
> mean((mat.logic[,2] + mat.logic[,3]) == 2)
[1] 0.4166667

So $X_i$ and $X_{i+2}$ are correlated. $P(X_{i+2} * X_{i} = 1) = 54 / 120$ and $Cov(X_{i+2} * X_{i}) = \frac{1}{180}$, $P(X_{i+1} * X_{i} = 1) = 10 / 24$, and covariance $Cov(X_{i+1} * X_{i}) = -\frac{1}{36}$.
We are left to find the variance of the summation:
$Var(T) = (n-2)Var(I_i) + 2(n-3)Cov(I_i,I_{i+1}) + 2(n-4)Cov(I_i,I_{i+2}) = \frac{2n-4}{9} -\frac{n-3}{18}+\frac{n-4}{90}=\frac{16n-29}{90}$
