Extract the formulas in math latex markdown format to calculate the portfolio return and variance in Modern Portfolio Theory https://en.wikipedia.org/wiki/Modern_portfolio_theory

MPT assumes that investors are risk averse, meaning that given two portfolios that offer the same expected return, investors will prefer the less risky one. Thus, an investor will take on increased risk only if compensated by higher expected returns. Conversely, an investor who wants higher expected returns must accept more risk. The exact trade-off will not be the same for all investors. Different investors will evaluate the trade-off differently based on individual risk aversion characteristics. The implication is that a rational investor will not invest in a portfolio if a second portfolio exists with a more favorable risk-expected return profile—i.e., if for that level of risk an alternative portfolio exists that has better expected returns.

Under the model:

Portfolio return is the proportion-weighted combination of the constituent assets' returns.
Portfolio return volatility 
\sigma _{p} is a function of the correlations ρij of the component assets, for all asset pairs (i, j). The volatility gives insight into the risk which is associated with the investment. The higher the volatility, the higher the risk.

- Expected return:
$$
\mathrm{E}\left(R_p\right)=\sum_i w_i \mathrm{E}\left(R_i\right)
$$
where $R_p$ is the return on the portfolio, $R_i$ is the return on asset $i$ and $w_i$ is the weighting of component asset $i$ (that is, the proportion of asset "i" in the portfolio, so that $\sum_i w_i=1$ ).
- Portfolio return variance:
$$
\sigma_p^2=\sum_i w_i^2 \sigma_i^2+\sum_i \sum_{j \neq i} w_i w_j \sigma_i \sigma_j \rho_{i j}
$$
where $\sigma_i$ is the (sample) standard deviation of the periodic returns on an asset $i$, and $\rho_{i j}$ is the correlation coefficient between the returns on assets $i$ and $j$. Alternatively the expression can be written as:
$$
\sigma_p^2=\sum_i \sum_j w_i w_j \sigma_i \sigma_j \rho_{i j}
$$
where $\rho_{i j}=1$ for $i=j$, or
$$
\sigma_p^2=\sum_i \sum_j w_i w_j \sigma_{i j}
$$
where $\sigma_{i j}=\sigma_i \sigma_j \rho_{i j}$ is the (sample) covariance of the periodic returns on the two assets, or alternatively denoted as $\sigma(i, j)$, $\operatorname{cov}{ }_{i j}$ or $\operatorname{cov}(i, j)$.
- Portfolio return volatility (standard deviation):
$$
\sigma_p=\sqrt{\sigma_p^2}
$$
For a two-asset portfolio:
- Portfolio return: 
$$\mathrm{E}\left(R_p\right)=w_A \mathrm{E}\left(R_A\right)+w_B \mathrm{E}\left(R_B\right)=w_A \mathrm{E}\left(R_A\right)+\left(1-w_A\right) \mathrm{E}\left(R_B\right)$$

- Portfolio variance: 
$$\sigma_p^2=w_A^2 \sigma_A^2+w_B^2 \sigma_B^2+2 w_A w_B \sigma_A \sigma_B \rho_{A B}$$
For a three-asset portfolio:
- Portfolio return: 
$$\mathrm{E}\left(R_p\right)=w_A \mathrm{E}\left(R_A\right)+w_B \mathrm{E}\left(R_B\right)+w_C \mathrm{E}\left(R_C\right)$$
- Portfolio variance: 
$$\sigma_p^2=w_A^2 \sigma_A^2+w_B^2 \sigma_B^2+w_C^2 \sigma_C^2+2 w_A w_B \sigma_A \sigma_B \rho_{A B}+2 w_A w_C \sigma_A \sigma_C \rho_{A C}+2 w_B w_C \sigma_B \sigma_C \rho_{B C}$$