Hi,
I am new to using R for optimisation and I am trying to set up a simple portfolio minimum variance optimisation with turnover constraints, but am having some difficulty setting up the problem correctly. I would really appreciate any help. I am trying two approaches one using the Rsolnp library and the other using the the parma library, but am having trouble with both.
Using Rsolnp I am having trouble getting the optimisation to converge, but this may be that the problem is poorly conditioned but please advise if the formulation seems correct.
ineq.fun.turnover <- function (x, sigma, wInit)
{
return(sum(abs(x - wInit)))
}
obj.fun <- function(x, sigma, wInit)
{
return(as.numeric(x%*%sigma%*%x))
}
eq.fun <- function(x,sigma,wInit)
{
return(sum(x))
}
tst <- solnp(initWeights, fun=obj.fun, eqfun=eq.fun, eqB = 1.0, ineqfun = ineq.fun.turnover,
ineqLB = 0.0, ineqUB = 0.2, LB = rep(0,numberOfSecurities), UB = rep(0.1,numberOfSecurities),
sigma = covarMatx, wInit = initWeights)
Where initWeights is a vector of length numberOfSecurities, and the covarMatx is a covariance Matrix (generated from a factor model) of dimensions numberOfSecurities by numberOfSecurities.
Using parma, I cannot seem to get parmaspec to recognise the turnover constraint inequality functions (using the custom ones in the library), so I am guessing I am using incompatible parameters.... ?
servars = list()
uservars$turnover <- 0.2
uservars$wold <- initWeights
spec2 <- parmaspec(S = covarMatx, LB = lowerBounds, UB = upperBounds,
risk = "EV", riskType = "minrisk",
ineqfun = list(ineqfun.turnover.min), ineqgrad = list(ineqjac.turnover.min), uservars = uservars)
It simply tries to solve the QP min risk problem ignoring the turnover inequality.
Thank you,
Graham.
Graham Ewen
BlueCrest Capital Management (UK) LLP
40 Grosvenor Place, London, SW1X 7AW, United Kingdom
T +44 20 3180 3530
graham.ewen at bluecrestcapital.com<mailto:graham.ewen at bluecrestcapital.com>
[Description: Description: Description: Description: Description: Description: Description: aaaBlueCrest Capital Management (UK) LLP Logo]
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. Any market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of BlueCrest Capital Management (UK) LLP, its subsidiaries or affiliates.
BlueCrest Capital Management (UK) LLP is authorised and regulated by the Financial Conduct Authority. BlueCrest Capital Management (UK) LLP is registered in England and Wales with registered number OC349662. Registered Office: 40 Grosvenor Place, London SW1X 7AW, United Kingdom.
Please see the important information at www.bluecrestcapital.com/disclaimer.
Tel: +44 (0)20 3180 3000 Fax: +44 (0)20 3180 3001 www.bluecrestcapital.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20150410/30a104db/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 6616 bytes
Desc: image001.png
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20150410/30a104db/attachment.png>
Portfolio Min Variance Optimisation with Turnover Constraints
3 messages · Alexios Ghalanos, Graham Ewen
Hi Graham, The reason it ignores the turnover constraint is because it is an NLP constraint (scenario based), _not_ a QP constraint. From the documentation: "Provides a number of custom constraints and their jacobians for use with the NLP representation (both minimum risk and the fractional problem)." As to the lack of convergence of the solnp formulation you describe, I am guessing that it is because of the bounds placed on the ineqUB (0.2) for the turnover constraint and the presence of the absolute function which is not smooth. To solve this as a QP problem, the abs function would require that you represent it as a second order cone problem and solve it with an SOCP solver. Alternatively, if you can write out the gradients of your functions, you _may_ have better luck with the nloptr solver (see ineqjac.turnover.min for an example). Regards, Alexios
On 10/04/2015 19:54, Graham Ewen wrote:
Hi,
I am new to using R for optimisation and I am trying to set up a simple
portfolio minimum variance optimisation with turnover constraints, but
am having some difficulty setting up the problem correctly. I would
really appreciate any help. I am trying two approaches one using the
Rsolnp library and the other using the the parma library, but am having
trouble with both.
Using Rsolnp I am having trouble getting the optimisation to converge,
but this may be that the problem is poorly conditioned but please advise
if the formulation seems correct.
ineq.fun.turnover <- function (x, sigma, wInit)
{
return(sum(abs(x - wInit)))
}
obj.fun <- function(x, sigma, wInit)
{
return(as.numeric(x%*%sigma%*%x))
}
eq.fun <- function(x,sigma,wInit)
{
return(sum(x))
}
tst <- solnp(initWeights, fun=obj.fun, eqfun=eq.fun, eqB = 1.0, ineqfun
= ineq.fun.turnover,
ineqLB = 0.0, ineqUB = 0.2, LB = rep(0,numberOfSecurities),
UB = rep(0.1,numberOfSecurities),
sigma = covarMatx, wInit = initWeights)
Where initWeights is a vector of length numberOfSecurities, and the
covarMatx is a covariance Matrix (generated from a factor model) of
dimensions numberOfSecurities by numberOfSecurities.
Using parma, I cannot seem to get parmaspec to recognise the turnover
constraint inequality functions (using the custom ones in the library),
so I am guessing I am using incompatible parameters?. ?
servars = list()
uservars$turnover <- 0.2
uservars$wold <- initWeights
spec2 <- parmaspec(S = covarMatx, LB = lowerBounds, UB = upperBounds,
risk = "EV", riskType = "minrisk",
ineqfun = list(ineqfun.turnover.min), ineqgrad =
list(ineqjac.turnover.min), uservars = uservars)
It simply tries to solve the QP min risk problem ignoring the turnover
inequality.
Thank you,
Graham.
*Graham Ewen*
BlueCrest Capital Management (UK) LLP
40 Grosvenor Place, London, SW1X 7AW, United Kingdom
*T* +44 20 3180 3530
graham.ewen at bluecrestcapital.com <mailto:graham.ewen at bluecrestcapital.com>
Description: Description: Description: Description: Description:
Description: Description: aaaBlueCrest Capital Management (UK) LLP Logo
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you
received this in error, please contact the sender and delete the
material from any computer.
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of any
financial instrument or as an official confirmation of any transaction.
Any market prices, data and other information are not warranted as to
completeness or accuracy and are subject to change without notice. Any
comments or statements made herein do not necessarily reflect those of
BlueCrest Capital Management (UK) LLP, its subsidiaries or affiliates.
BlueCrest Capital Management (UK) LLP is authorised and regulated by the
Financial Conduct Authority. BlueCrest Capital Management (UK) LLP is
registered in England and Wales with registered number OC349662.
Registered Office: 40 Grosvenor Place, London SW1X 7AW, United Kingdom.
Please see the important information at
www.bluecrestcapital.com/disclaimer.
Tel: +44 (0)20 3180 3000 Fax: +44 (0)20 3180 3001 www.bluecrestcapital.com
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
4 days later
Thanks for the reply Alexios. I apologise I can see quite clearly in the documentation now, in Table 1, that the Covariance minrisk problem is not compatible with the NLP solver, so it should have been obvious to me why the NLP constraints were ignored. I think the lack of convergence in the solnp formulation is potentially due to the initial weights being too far from the solution under the tight turnover constraint. I will take your advice and try to reformulate and solve as a QP problem. Thank you, Graham. -----Original Message----- From: alexios ghalanos [mailto:alexios at 4dscape.com] Sent: 10 April 2015 19:10 To: Graham Ewen; r-sig-finance at r-project.org Cc: alexios at 4dscape.com Subject: Re: [R-SIG-Finance] Portfolio Min Variance Optimisation with Turnover Constraints Hi Graham, The reason it ignores the turnover constraint is because it is an NLP constraint (scenario based), _not_ a QP constraint. From the documentation: "Provides a number of custom constraints and their jacobians for use with the NLP representation (both minimum risk and the fractional problem)." As to the lack of convergence of the solnp formulation you describe, I am guessing that it is because of the bounds placed on the ineqUB (0.2) for the turnover constraint and the presence of the absolute function which is not smooth. To solve this as a QP problem, the abs function would require that you represent it as a second order cone problem and solve it with an SOCP solver. Alternatively, if you can write out the gradients of your functions, you _may_ have better luck with the nloptr solver (see ineqjac.turnover.min for an example). Regards, Alexios
On 10/04/2015 19:54, Graham Ewen wrote:
Hi,
I am new to using R for optimisation and I am trying to set up a
simple portfolio minimum variance optimisation with turnover
constraints, but am having some difficulty setting up the problem
correctly. I would really appreciate any help. I am trying two
approaches one using the Rsolnp library and the other using the the
parma library, but am having trouble with both.
Using Rsolnp I am having trouble getting the optimisation to converge,
but this may be that the problem is poorly conditioned but please
advise if the formulation seems correct.
ineq.fun.turnover <- function (x, sigma, wInit)
{
return(sum(abs(x - wInit)))
}
obj.fun <- function(x, sigma, wInit)
{
return(as.numeric(x%*%sigma%*%x))
}
eq.fun <- function(x,sigma,wInit)
{
return(sum(x))
}
tst <- solnp(initWeights, fun=obj.fun, eqfun=eq.fun, eqB = 1.0,
ineqfun = ineq.fun.turnover,
ineqLB = 0.0, ineqUB = 0.2, LB =
rep(0,numberOfSecurities), UB = rep(0.1,numberOfSecurities),
sigma = covarMatx, wInit = initWeights)
Where initWeights is a vector of length numberOfSecurities, and the
covarMatx is a covariance Matrix (generated from a factor model) of
dimensions numberOfSecurities by numberOfSecurities.
Using parma, I cannot seem to get parmaspec to recognise the turnover
constraint inequality functions (using the custom ones in the
library), so I am guessing I am using incompatible parameters.... ?
servars = list()
uservars$turnover <- 0.2
uservars$wold <- initWeights
spec2 <- parmaspec(S = covarMatx, LB = lowerBounds, UB = upperBounds,
risk = "EV", riskType = "minrisk",
ineqfun = list(ineqfun.turnover.min), ineqgrad =
list(ineqjac.turnover.min), uservars = uservars)
It simply tries to solve the QP min risk problem ignoring the turnover
inequality.
Thank you,
Graham.
*Graham Ewen*
BlueCrest Capital Management (UK) LLP
40 Grosvenor Place, London, SW1X 7AW, United Kingdom
*T* +44 20 3180 3530
graham.ewen at bluecrestcapital.com
<mailto:graham.ewen at bluecrestcapital.com>
Description: Description: Description: Description: Description:
Description: Description: aaaBlueCrest Capital Management (UK) LLP
Logo
The information transmitted is intended only for the person or entity
to which it is addressed and may contain confidential and/or
privileged material. Any review, retransmission, dissemination or
other use of, or taking of any action in reliance upon, this
information by persons or entities other than the intended recipient
is prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of any
financial instrument or as an official confirmation of any transaction.
Any market prices, data and other information are not warranted as to
completeness or accuracy and are subject to change without notice. Any
comments or statements made herein do not necessarily reflect those of
BlueCrest Capital Management (UK) LLP, its subsidiaries or affiliates.
BlueCrest Capital Management (UK) LLP is authorised and regulated by
the Financial Conduct Authority. BlueCrest Capital Management (UK) LLP
is registered in England and Wales with registered number OC349662.
Registered Office: 40 Grosvenor Place, London SW1X 7AW, United Kingdom.
Please see the important information at
www.bluecrestcapital.com/disclaimer.
Tel: +44 (0)20 3180 3000 Fax: +44 (0)20 3180 3001
www.bluecrestcapital.com
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. Any market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of BlueCrest Capital Management (UK) LLP, its subsidiaries or affiliates. BlueCrest Capital Management (UK) LLP is authorised and regulated by the Financial Conduct Authority. BlueCrest Capital Management (UK) LLP is registered in England and Wales with registered number OC349662. Registered Office: 40 Grosvenor Place, London SW1X 7AW, United Kingdom. Please see the important information at www.bluecrestcapital.com/disclaimer. Tel: +44 (0)20 3180 3000 Fax: +44 (0)20 3180 3001 www.bluecrestcapital.com