Skip to main content
Tweeted twitter.com/StackStats/status/1003313084268797953
Edit based on a comment
Source Link

I'm trying to find variance minimizing currency hedge ratios $\mathbf{h}$ for $m$ currency exposures constrained between $0$ (no hedge) and $1$ (full hedge). We have weights $\mathbf{w}$ for $n$ assets and $m$ related foreign currency exposures $\mathbf{v}$. As an asset can be domestic, it holds that $m \leq n$. The weight vectors are

\begin{equation} \mathbf{w}=\begin{bmatrix} w_{1} \\ w_{2} \\ \vdots \\ {w}_{n} \end{bmatrix}, \quad \mathbf{v}=\begin{bmatrix} v_{1} \\ v_{2} \\ \vdots \\ v_{m} \end{bmatrix}, \end{equation}

where $\mathbf{1}^{T}\mathbf{w} = 1$ and $\mathbf{w} \geq 0$, i.e. all the funds are invested and the portfolio is long-only.

We also have covariance matrix $C$ $(n+m)\times(n+m)$. This matrix can be expressed as partitioned matrix of asset-asset, asset-currency and currency-currency return covariances:

\begin{equation} \mathbf{C}=\begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{ww}}\\ \end{bmatrix} \end{equation}

The objective function (i.e. portfolio variance) is

\begin{equation} min \quad f(\mathbf{h}) = \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h} \end{bmatrix}^{T} \begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{vv}}\\ \end{bmatrix} \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h}\\ \end{bmatrix} \end{equation}

subject to \begin{equation}\mathbf{h} \leq 0, \quad \mathbf{- v - h} \leq 0, \\\end{equation} i.e. hedging positions are short and we cannot "overhedge" the currency exposures by short positions that are larger than the hedged exposures in absolute terms. The objective function is approximate but its not the concern here.

When I try to solve this in R using solnl in NlcOptim-package for non-linear optimization problems, the solution is relatively much dependent on initial guess for $\mathbf{h}$. How should I determine the initial guess? Do you know any potential alternatives to NlcOptim?

The R code:

h0 <- 1 * (-v) # initial guess for optimum hedge ratios is now 1

# objective function
f_obj = function(h){
  return( t(c(w, v+h)) %*% cov_mat %*% c(w, v+h) )
}

# constraining functions
f_con = function(h){
  f = NULL # no NULLs allowed in the solution
  f = rbind(f, -(v+h)) # i.e. -(v+h) <= 0
  f = rbind(f, h) # i.e. h <= 0
  return(list(ceq=NULL,c=f)) # c --> use of inequality const. only
}

h_optim <- solnl(h0, objfun=f_obj, confun=f_con)[1] # printsave solution only

EDIT based on a helpful comment by Mark L. Stone:

My quick try to use solve.qp instead of solnl seems to work better. Solving $\mathbf{v + h}$ instead of $\mathbf{h}$:

lw <- length(w) # no. of assets
lv <- length(v) # no. of currency exposures

# one equality constraint for each asset and two inequality constraints for 
# each currency exposure which are "v+h" from the objective function
mata <- rbind(diag(lw), matrix(0, lv, lw)
matc <- rbind(matrix(0, lw, 2*lv), cbind(diag(lv), -diag(lv)))
Amat <- cbind(mata, matc)
bvec <- c(w, rep(0, lv, -v)

h_optim <- solve.QP(cov_mat, rep(0, lw+lv), Amat, bvec, meq = lw)$solution

I'm trying to find variance minimizing currency hedge ratios $\mathbf{h}$ for $m$ currency exposures constrained between $0$ (no hedge) and $1$ (full hedge). We have weights $\mathbf{w}$ for $n$ assets and $m$ related foreign currency exposures $\mathbf{v}$. As an asset can be domestic, it holds that $m \leq n$. The weight vectors are

\begin{equation} \mathbf{w}=\begin{bmatrix} w_{1} \\ w_{2} \\ \vdots \\ {w}_{n} \end{bmatrix}, \quad \mathbf{v}=\begin{bmatrix} v_{1} \\ v_{2} \\ \vdots \\ v_{m} \end{bmatrix}, \end{equation}

where $\mathbf{1}^{T}\mathbf{w} = 1$ and $\mathbf{w} \geq 0$, i.e. all the funds are invested and the portfolio is long-only.

We also have covariance matrix $C$ $(n+m)\times(n+m)$. This matrix can be expressed as partitioned matrix of asset-asset, asset-currency and currency-currency return covariances:

\begin{equation} \mathbf{C}=\begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{ww}}\\ \end{bmatrix} \end{equation}

The objective function (i.e. portfolio variance) is

\begin{equation} min \quad f(\mathbf{h}) = \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h} \end{bmatrix}^{T} \begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{vv}}\\ \end{bmatrix} \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h}\\ \end{bmatrix} \end{equation}

subject to \begin{equation}\mathbf{h} \leq 0, \quad \mathbf{- v - h} \leq 0, \\\end{equation} i.e. hedging positions are short and we cannot "overhedge" the currency exposures by short positions that are larger than the hedged exposures in absolute terms. The objective function is approximate but its not the concern here.

When I try to solve this in R using solnl in NlcOptim-package for non-linear optimization problems, the solution is relatively much dependent on initial guess for $\mathbf{h}$. How should I determine the initial guess? Do you know any potential alternatives to NlcOptim?

The R code:

h0 <- 1 * (-v) # initial guess for optimum hedge ratios is now 1

# objective function
f_obj = function(h){
  return( t(c(w, v+h)) %*% cov_mat %*% c(w, v+h) )
}

# constraining functions
f_con = function(h){
  f = NULL # no NULLs allowed in the solution
  f = rbind(f, -(v+h)) # i.e. -(v+h) <= 0
  f = rbind(f, h) # i.e. h <= 0
  return(list(ceq=NULL,c=f)) # c --> use of inequality const. only
}

h_optim <- solnl(h0, objfun=f_obj, confun=f_con)[1] # print solution only

I'm trying to find variance minimizing currency hedge ratios $\mathbf{h}$ for $m$ currency exposures constrained between $0$ (no hedge) and $1$ (full hedge). We have weights $\mathbf{w}$ for $n$ assets and $m$ related foreign currency exposures $\mathbf{v}$. As an asset can be domestic, it holds that $m \leq n$. The weight vectors are

\begin{equation} \mathbf{w}=\begin{bmatrix} w_{1} \\ w_{2} \\ \vdots \\ {w}_{n} \end{bmatrix}, \quad \mathbf{v}=\begin{bmatrix} v_{1} \\ v_{2} \\ \vdots \\ v_{m} \end{bmatrix}, \end{equation}

where $\mathbf{1}^{T}\mathbf{w} = 1$ and $\mathbf{w} \geq 0$, i.e. all the funds are invested and the portfolio is long-only.

We also have covariance matrix $C$ $(n+m)\times(n+m)$. This matrix can be expressed as partitioned matrix of asset-asset, asset-currency and currency-currency return covariances:

\begin{equation} \mathbf{C}=\begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{ww}}\\ \end{bmatrix} \end{equation}

The objective function (i.e. portfolio variance) is

\begin{equation} min \quad f(\mathbf{h}) = \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h} \end{bmatrix}^{T} \begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{vv}}\\ \end{bmatrix} \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h}\\ \end{bmatrix} \end{equation}

subject to \begin{equation}\mathbf{h} \leq 0, \quad \mathbf{- v - h} \leq 0, \\\end{equation} i.e. hedging positions are short and we cannot "overhedge" the currency exposures by short positions that are larger than the hedged exposures in absolute terms. The objective function is approximate but its not the concern here.

When I try to solve this in R using solnl in NlcOptim-package for non-linear optimization problems, the solution is relatively much dependent on initial guess for $\mathbf{h}$. How should I determine the initial guess? Do you know any potential alternatives to NlcOptim?

The R code:

h0 <- 1 * (-v) # initial guess for optimum hedge ratios is now 1

# objective function
f_obj = function(h){
  return( t(c(w, v+h)) %*% cov_mat %*% c(w, v+h) )
}

# constraining functions
f_con = function(h){
  f = NULL # no NULLs allowed in the solution
  f = rbind(f, -(v+h)) # i.e. -(v+h) <= 0
  f = rbind(f, h) # i.e. h <= 0
  return(list(ceq=NULL,c=f)) # c --> use of inequality const. only
}

h_optim <- solnl(h0, objfun=f_obj, confun=f_con)[1] # save solution only

EDIT based on a helpful comment by Mark L. Stone:

My quick try to use solve.qp instead of solnl seems to work better. Solving $\mathbf{v + h}$ instead of $\mathbf{h}$:

lw <- length(w) # no. of assets
lv <- length(v) # no. of currency exposures

# one equality constraint for each asset and two inequality constraints for 
# each currency exposure which are "v+h" from the objective function
mata <- rbind(diag(lw), matrix(0, lv, lw)
matc <- rbind(matrix(0, lw, 2*lv), cbind(diag(lv), -diag(lv)))
Amat <- cbind(mata, matc)
bvec <- c(w, rep(0, lv, -v)

h_optim <- solve.QP(cov_mat, rep(0, lw+lv), Amat, bvec, meq = lw)$solution
Changed title
Link

Initial guess How to choose initial value in non-linearconstrained portfolio optimization?

Source Link

Initial guess in non-linear portfolio optimization

I'm trying to find variance minimizing currency hedge ratios $\mathbf{h}$ for $m$ currency exposures constrained between $0$ (no hedge) and $1$ (full hedge). We have weights $\mathbf{w}$ for $n$ assets and $m$ related foreign currency exposures $\mathbf{v}$. As an asset can be domestic, it holds that $m \leq n$. The weight vectors are

\begin{equation} \mathbf{w}=\begin{bmatrix} w_{1} \\ w_{2} \\ \vdots \\ {w}_{n} \end{bmatrix}, \quad \mathbf{v}=\begin{bmatrix} v_{1} \\ v_{2} \\ \vdots \\ v_{m} \end{bmatrix}, \end{equation}

where $\mathbf{1}^{T}\mathbf{w} = 1$ and $\mathbf{w} \geq 0$, i.e. all the funds are invested and the portfolio is long-only.

We also have covariance matrix $C$ $(n+m)\times(n+m)$. This matrix can be expressed as partitioned matrix of asset-asset, asset-currency and currency-currency return covariances:

\begin{equation} \mathbf{C}=\begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{ww}}\\ \end{bmatrix} \end{equation}

The objective function (i.e. portfolio variance) is

\begin{equation} min \quad f(\mathbf{h}) = \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h} \end{bmatrix}^{T} \begin{bmatrix} \mathbf{C_{ww}} & \mathbf{C_{wv}}\\ \mathbf{C_{vw}} & \mathbf{C_{vv}}\\ \end{bmatrix} \begin{bmatrix} \mathbf{w}\\ \mathbf{v + h}\\ \end{bmatrix} \end{equation}

subject to \begin{equation}\mathbf{h} \leq 0, \quad \mathbf{- v - h} \leq 0, \\\end{equation} i.e. hedging positions are short and we cannot "overhedge" the currency exposures by short positions that are larger than the hedged exposures in absolute terms. The objective function is approximate but its not the concern here.

When I try to solve this in R using solnl in NlcOptim-package for non-linear optimization problems, the solution is relatively much dependent on initial guess for $\mathbf{h}$. How should I determine the initial guess? Do you know any potential alternatives to NlcOptim?

The R code:

h0 <- 1 * (-v) # initial guess for optimum hedge ratios is now 1

# objective function
f_obj = function(h){
  return( t(c(w, v+h)) %*% cov_mat %*% c(w, v+h) )
}

# constraining functions
f_con = function(h){
  f = NULL # no NULLs allowed in the solution
  f = rbind(f, -(v+h)) # i.e. -(v+h) <= 0
  f = rbind(f, h) # i.e. h <= 0
  return(list(ceq=NULL,c=f)) # c --> use of inequality const. only
}

h_optim <- solnl(h0, objfun=f_obj, confun=f_con)[1] # print solution only