Portfolio Optimization

Modern or mean-variance portfolio theory (MPT) is a major cornerstone of financial theory. Based on this theoretical breakthrough the Nobel Prize in Economics was awarded to its inventor, Harry Markowitz, in 1990. Although formulated in the [1950s,][1] it is still a theory taught to finance students and applied in practice today (often with some minor or major modifications). This section illustrates the fundamental principles of the theory.

Mathematical model assumption

Risk and expected return

[MPT][2] 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 be the same for all investors, but 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 volatility is a function of the correlations ρij of the component assets, for all asset pairs (i, j).

Diversification

An investor can reduce portfolio risk simply by holding combinations of instruments that are not perfectly positively correlated (correlation coefficient$ -1\leq \rho _{ij}<1)$. In other words, investors can reduce their exposure to individual asset risk by holding a diversified portfolio of assets. Diversification may allow for the same portfolio expected return with reduced risk. These ideas have been started with Markowitz and then reinforced by other economists and mathematicians such as Andrew Brennan who have expressed ideas in the limitation of variance through portfolio theory. If all the asset pairs have correlations of 0—they are perfectly uncorrelated—the portfolio's return variance is the sum over all assets of the square of the fraction held in the asset times the asset's return variance (and the portfolio standard deviation is the square root of this sum). If all the asset pairs have correlations of 1, i.e. they are perfectly positively correlated, then the portfolio's volatility is the sum of each asset's volatility weighted by its fraction held in the portfolio. This is the maximum volatility the portfolio of these assets would reach.

Optimization basic theory

Quadratic function

In algebra, a quadratic function, a quadratic polynomial, a polynomial of degree 2, or simply a quadratic, is a polynomial function in one or more variables in which the highest-degree term is of the second degree. For example, a quadratic function in three variables x, y, and z contains exclusively terms x2, y2, z2, xy, xz, yz, x, y, z, and a constant:

$$ f(x,y,z)=ax^{2}+by^{2}+cz^{2}+dxy+exz+fyz+gx+hy+iz+j,$$

with at least one of the coefficients a, b, c, d, e, or f of the second-degree terms being non-zero.

Quadratic programming

Quadratic programming (QP) is the process of solving a special type of mathematical optimization problem—specifically, a (linearly constrained) quadratic optimization problem, that is, the problem of optimizing (minimizing or maximizing) a quadratic function of several variables subject to linear constraints on these variables. Quadratic programming is a particular type of nonlinear programming.

Nonlinear programming

the process of solving an optimization problem defined by a system of equalities and inequalities, collectively termed constraints, over a set of unknown real variables, along with an objective function to be maximized or minimized, where some of the constraints or the objective function are nonlinear.

Loss function

In mathematical optimization, statistics, econometrics, decision theory, machine learning and computational neuroscience, a loss function or cost function is a function that maps an event or values of one or more variables onto a real number intuitively representing some "cost" associated with the event. An optimization problem seeks to minimize a loss function. An objective function is either a loss function or its negative (in specific domains, also variously called a reward function, a profit function, a utility function, a fitness function, etc.), in which case it is to be maximized. In statistics, typically a loss function is used for parameter estimation, and the event in question is some function of the difference between estimated and true values for an instance of data. The concept, as old as Laplace, was reintroduced in statistics by Abraham Wald in the middle of the 20th century. In the context of economics, for example, this is usually economic cost or regret. In classification, it is the penalty for an incorrect classification of an example. In actuarial science, it is used in an insurance context to model benefits paid over premiums, particularly since the works of Harald Cramér in the 1920s. In optimal control the loss is the penalty for failing to achieve a desired value. In financial risk management the function is mapped to a monetary loss.

Constraint

In mathematics, a constraint is a condition of an optimization problem that the solution must satisfy. There are several types of constraints—primarily equality constraints, inequality constraints, and integer constraints. The set of candidate solutions that satisfy all constraints is called the feasible set.

example

The following is a simple optimization problem: ${\displaystyle \min f({\mathbf {x}})=x_{1}^{2}+x_{2}^{4}}$ subject to ${\displaystyle x_{1}\geq 1}$ and ${\displaystyle x_{2}=1,}$ where x denotes the vector (x1, x2).

Equality constraints

Quadratic programming is particularly simple when Q is positive definite and there are only equality constraints; specifically, the solution process is linear. By using Lagrange multipliers and seeking the extremum of the Lagrangian, it may be readily shown that the solution to the equality constrained problem $${\text{Minimize}}\quad {\tfrac {1}{2}}\mathbf {x} ^{\mathrm {T} }Q\mathbf {x} +\mathbf {c} ^{\mathrm {T} }\mathbf {x} {\text{ subject to}}\quad E\mathbf {x} =\mathbf {d}$$

is given by the linear system

$${\begin{bmatrix}Q&E^{T}\\E&0\end{bmatrix}}{\begin{bmatrix}\mathbf {x} \\\lambda \end{bmatrix}}={\begin{bmatrix}-\mathbf {c} \\\mathbf {d} \end{bmatrix}}$$

where ${\displaystyle \lambda }$ is a set of Lagrange multipliers which come out of the solution alongside ${\displaystyle \mathbf {x} }$ .

Quadratically constrained quadratic program

In mathematical optimization, a quadratically constrained quadratic program (QCQP) is an optimization problem in which both the objective function and the constraints are quadratic functions. It has the form$${\begin{aligned}&{\text{minimize}}&&{\tfrac 12}x^{{\mathrm {T}}}P_{0}x+q_{0}^{{\mathrm {T}}}x\\&{\text{subject to}}&&{\tfrac 12}x^{{\mathrm {T}}}P_{i}x+q_{i}^{{\mathrm {T}}}x+r_{i}\leq 0\quad {\text{for }}i=1,\dots ,m,\\&&&Ax=b,\end{aligned}}$$ where P0, … Pm are n-by-n matrices and x ∈ Rn is the optimization variable. If P0, … Pm are all positive semidefinite, then the problem is convex. If these matrices are neither positive nor negative semidefinite, the problem is non-convex. If P1, … Pm are all zero, then the constraints are in fact linear and the problem is a quadratic program.

Data

position_limit: int maximum position number selected.

risk model: dictionary Risk factor exposure: DataFrame 所有股票在因子上暴露的值,p.s. 如有8个因子,就有8个DataFrame, 得把所有8个因子某一天所有值先取出来得到一个n*k的矩阵.n为股票,k为因子 Specific Risk: DataFrame 用来组成对角矩阵Delta.

asset_return: Dataframe, OTV, asset return for all symbols. index=date, O: asset names, V: asset return.

asset_weight: Dataframe, OOTV T=date, O: asset names, O: group names, V: asset weight. weight bound of each asset. Default is equal weight.

target_return: double Target return for portfolio respected to benchmark.

target_risk: double Portfolio risk tolerance whose objective is maximum return.

target_date: Timestamp Specific date.

asset_constraint: OVV input asset constraint, V1: lower boundary, V2: upper boundary.

group constraint: OVV input group constraint, V1: lower boundary, V2: upper boundary.

exposure constraint: OVV input factor exposure constraint, V1: lower boundary, V2: upper boundary.

alpha_return: double coefficient number to adjust target return. target_return = target_return * alpha_return

lambda_risk: double coefficient number to adjust target risk target_risk = target_risk * lambda_risk

beta_tranaction: double multi-period transaction cost adjustment number.

Portfolio Optimization Algorithms

There are four types of objective functions in this optimization. In order to reach our target objectives, we need to set the parameters respectively.

  • Max expected return

  • Min risk

  • Min risk subject to target expected return

  • Max expected return subject to target tolerance risk

Quadratic Programming algorithm

In order to solve the quadratic programming, we used the [CVXOPT][3] library. The function qp is an interface to coneqp for quadratic programs. It also provides the option of using the quadratic programming solver from MOSEK.

cvxopt.solvers.qp(P, q[, G, h[, A, b[, solver[, initvals]]]]) Solves the pair of primal and dual convex quadratic programs

\begin{array}[t]{ll} \mbox{minimize} & (1/2) x^TPx + q^T x \\ \mbox{subject to} & Gx \preceq h \\ & Ax = b \end{array}

Output

The output data is our optimized weight according to our objective function and constraints.

[1]: Cf. Markowitz, Harry (1952): “Portfolio Selection.” Journal of Finance, Vol. 7, 77-91.