<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif"}
a:link, span.MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:#954F72;
        text-decoration:underline}
span.EmailStyle17
        {font-family:"Calibri","sans-serif";
        color:windowtext}
.MsoChpDefault
        {font-family:"Calibri","sans-serif"}
@page WordSection1
        {margin:72.0pt 72.0pt 72.0pt 72.0pt}
div.WordSection1
        {}
-->
</style>
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-family:"Courier New"">ineq.fun.turnover <- function (x, sigma, wInit)
</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">{</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">  return(sum(abs(x - wInit)))
</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">obj.fun <- function(x, sigma, wInit)</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">{</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">  return(as.numeric(x%*%sigma%*%x))</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">eq.fun <- function(x,sigma,wInit)</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">{</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">  return(sum(x))</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">  </span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">tst <- solnp(initWeights, fun=obj.fun, eqfun=eq.fun, eqB = 1.0, ineqfun = ineq.fun.turnover,</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">             ineqLB = 0.0, ineqUB = 0.2, LB = rep(0,numberOfSecurities), UB = rep(0.1,numberOfSecurities),</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">             sigma = covarMatx, wInit = initWeights)</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Where <span style="font-family:"Courier New"">initWeights </span>
is a vector of length <span style="font-family:"Courier New"">numberOfSecurities</span>, and the
<span style="font-family:"Courier New"">covarMatx</span> is a covariance Matrix (generated from a factor model) of dimensions
<span style="font-family:"Courier New"">numberOfSecurities</span> by <span style="font-family:"Courier New"">
numberOfSecurities</span>.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Using <span style="font-family:"Courier New"">parma</span>, I cannot seem to get
<span style="font-family:"Courier New"">parmaspec</span> to recognise the turnover constraint inequality functions (using the custom ones in the library), so I am guessing I am using incompatible parameters…. ?</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-family:"Courier New"">servars = list()</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">uservars$turnover <- 0.2</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">uservars$wold <- initWeights</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-family:"Courier New"">spec2 <- parmaspec(S = covarMatx,  LB = lowerBounds, UB = upperBounds,</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">                  risk = "EV", riskType = "minrisk",
</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">                  ineqfun = list(ineqfun.turnover.min), ineqgrad = list(ineqjac.turnover.min), uservars = uservars)</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">It simply tries to solve the QP min risk problem ignoring the turnover inequality.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thank you,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Graham.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:#00457C">Graham Ewen</span></b><span style="font-size:10.0pt; color:gray"><br>
BlueCrest Capital Management (UK) LLP<br>
40 Grosvenor Place, London, SW1X 7AW, United Kingdom<br>
<b>T</b>  +44 20 3180 3530<br>
</span><span style="font-size:10.0pt"><a href="mailto:graham.ewen@bluecrestcapital.com"><span style="color:blue">graham.ewen@bluecrestcapital.com</span></a><span style="color:gray"> </span></span><span style="color:gray">
</span><span style="font-size:10.0pt; color:gray"></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><img border="0" width="134" height="40" id="Picture_x0020_1" src="cid:image001.png@01D073B6.0BDD29B0" alt="Description: Description: Description: Description: Description: Description: Description: aaaBlueCrest Capital Management (UK) LLP Logo"></span><span style="font-size:9.0pt; color:#1F497D"> </span></p>
<p class="MsoNormal"> </p>
</div>
<br>
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.
<br>
<br>
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.
<br>
<br>
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. <br>
<br>
Please see the important information at www.bluecrestcapital.com/disclaimer. <br>
<br>
Tel: +44 (0)20 3180 3000 Fax: +44 (0)20 3180 3001 www.bluecrestcapital.com
</body>
</html>