2 stocks, no shorting vs shorting. (concrete questions, mean-variance)

I'd appreciate help with the following questions.

Suppose there are two stocks $A$ and $B$ with expected returns $E_A, E_B >0$ and volatilities $v_A, v_B >0$, respectively . Also, suppose their correlation is $\rho_{AB} = \rho <0$. Given a dollar amount $D>0$ to invest without shorting, how should $D$ be invested in $A,B$ so that i) Expected return is maximized? ii) Overall volatility is minimized?

My second question: same questions (i) and (ii) but now with shorting allowed.

Intuitively, volatility is a standard deviation of a stock's price (or return) over a fixed period of time. Therefore (for a fixed period of time), in the case $E_A > E_B$ and $v_A>v_B$, I'd expect a 'middle-ground' determined by comparing the ratios $E_A/v_A$ with $E_B/v_B$.

Finally, how might Sharpe ratio play into these questions? (would it measure the 'strength' of a strategy?) Also, how approach this question for $n>2$ stocks $A_1,\ldots, A_n$? I would think to set $A = A_1$ and $B = A_2 +\cdots + A_n$

Concrete (mathematical) answers as well as general references to tackle these problems is appreciated.

-
Welcome to Quant.SE! Are you familiar with Mean-Variance optimization? – Bob Jansen Jul 7 '14 at 10:40
This seems like a mean-variance optimization for a portfolio of 2 stocks. "Pairs trading" in the title is misleading. – madilyn Jul 7 '14 at 12:02
@BobJansen, thanks for the tip. Looked it up and I bet the answer to my question is contained in Ch. 6 of "Modern portfolio theory..." (9 ed) by Brown et al. – user9482 Jul 7 '14 at 16:49

The concrete (general) answer to part (ii) of my question seems to be contained in Equation 8 of the following link: http://www.columbia.edu/~ks20/FE-Notes/4700-07-Notes-portfolio-I.pdf

In particular, interpreting $\sigma$ as volatility, take for example $E_A=0.10,\sigma_A=0.15,E_B=0.25,\sigma_B=0.40$ and $\rho =−0.2$.

I get that about 83 percent of the money should be invested in $A$ and 17 percent for $B$. Namely, if $D = 1000$, then about 830 into $A$ and 170 into $B$. No shorting is required in this case since $\rho <0$.

The return, as calculated from Eq. (4) in the above pdf, in this case is about $+125$ in profit.

Update. Regarding (i). Please correct me if I'm wrong, but as for "maximizing return" it seems we want to maximize the following function: $R(a) = aE_A + (1-a)E_B$. Since $R(a)$ is linear in $a$, then we see that $\max R(a)$ subject to $0\leq a \leq 1$, occurs at $a = 1$ iff $E_A\geq E_B$ or either at $a = 0$ iff $E_A < E_B$. Certainly though, the approach should be different if we are maximizing return with respect to a specified level of risk or volatility in the desired portfolio (help on this last point would be appreciated).

-

Firstly, to answer your question for part (i), this part of the question makes no sense - your expected return is unbounded and is asymptotically linear with respect to risk.

Let ${\bf w}\in\mathbb{R}^{2}$ denote your vector of weights, $\Omega$ denote the covariance matrix and $\iota$ denote a unit exposure vector (defined by $\iota_{j}:=1\ \forall j, j \in \mathbb{Z}^{*}$). We have:

$\mu_{P}={\bf w}\cdot\mu=\sum w_{i}\mu_{i}$

$\sigma_{P}^{2}={\bf w}^{T}\Omega{\bf w}=\sum_{i\neq j}w_{i}w_{j}\sigma_{i}\sigma_{j}\rho_{ij}$

$n\in\mathbb{Z}^{*}$ equality constraints of form $g_{k}\left({\bf w}\right)=c,\ c\in\mathbb{R},k=1,...,n$ are imposed. We define the Lagrangian:

$\mathcal{L}\left({\bf w},k_{1},...,k_{n}\right):=\dfrac{1}{2}{\bf w}^{T}\Omega{\bf w}+k_{1}g_{k}\left({\bf w}\right)+...k_{2}g_{k}\left({\bf w}\right)$

For example, for a single constraint that you are fully invested, you solve for the Lagrange multipliers for:

$\mathcal{L}\left({\bf w},l\right)=\dfrac{1}{2}{\bf w}^{T}\Omega{\bf w}+l\left(1-{\bf w}\cdot\iota\right)$

Then, you can find the minimum variance (volatility) portfolio:

${\bf w}_{min}=l\Omega^{-1}\iota=\dfrac{\Omega^{-1}}{\iota^{T}\Omega^{-1}\iota}$

As for your remaining question about shorting, this could be expressed as an inequality constraint ${\bf w}\geq{\bf 0}$ for ${\bf w},{\bf 0}\in\mathbb{R}^{2}$. Then, you can formulate this as a classical nonlinear programming problem and solve the first order necessary conditions (Karush-Kuhn-Tucker conditions).
Your first point seems quite odd. If the investment amount $D$ and the (average) returns $E_A, E_B$ are finite (implicit), how is it possible for a portfolio comprised solely of stocks $A$ and $B$ to have unbounded expected return? Also, what precisely do you mean by "risk" if the only input is $D, E_A, E_B, v_A, v_B$ (which are all finite)? – user9482 Jul 7 '14 at 12:44
very concretely: suppose $D = 1000$, $E_A = 0.10, v_A=0.15, E_B = 0.25, v_B = 0.40$ and $\rho = -0.2$. How do you get an unbounded expected return from investing all of $D$ into some combination of $A$ and $B$ in this situation? – user9482 Jul 7 '14 at 12:55
@user9482 Sure, if you have a budget constraint and no access to leverage, then the hyperbola will be cut off at some finite limit. But the answer that you are seeking is still at max $\sigma_{p}^2$ and should have no more than 2 trivial solutions - there seems no sensible purpose for this besides illustrating the basic tenet that "more risk, more reward". – madilyn Jul 7 '14 at 13:51