[R-SIG-Finance] Portfolio Optimisation as a function of targeted Risk rather than return.
Pierre Org
pierre at lequeux.org
Fri Jan 23 16:21:39 CET 2015
Hi Alexios
Many thanks for the below this is really useful to me (and hopefully others). Yes I understood since my previous post that the risk was expressed as variance rather than standard deviation. In respect of upper bound, I assume that you mean that the portfolio risk is constrained to a maximum of 7% rather than exactly 7% during the optimisation (i.e the risk will end up being close to 7% rather than exactly equal)? Is there a way of having a strict equality by forcing the lower bound as well ?
I am really thankful for the time you spend on this.
Kind regards
Pierre
-----Original Message-----
From: alexios [mailto:alexios at 4dscape.com]
Sent: 23 January 2015 14:48
To: Pierre Org; 'Ilya Kipnis'
Cc: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] Portfolio Optimisation as a function of targeted Risk rather than return.
1. The risk is variance, NOT standard deviation.
2. From the manual:
"riskB: For the case that riskType is “maxreward”, then riskB is the
upper bound for the risk constraint."
_Note_ the "upper bound".
3. Because of the quality of the SOCP solver currently used, you should probably scale your data by 100.
Therefore:
m = m*100
riskB = (7^2)/12
spec <- parmaspec(S = as.matrix(cov(m)),
riskB=riskB,risk="EV",riskType="maxreward", LB = rep(0,3), UB = rep(1,3), budget=1, forecast=as.numeric(colMeans(m))) port <- parmasolve(spec, solver="SOCP")
+---------------------------------+
| PARMA Portfolio |
+---------------------------------+
No.Assets : 3
Problem : SOCP
Risk Measure : EV
Objective : maxreward
Risk : 3.3703562
Reward : 1.634234
Optimal_Weights
World.Ex.UK.Stocks 1
> sqrt(parmarisk(port))*sqrt(12)/100
[1] 0.06359581
> parmareward(port)/100
[1] 0.01634234
But note:
>port at solution$status
"Error (0)"
i.e. "probably" unreliable solution. A new SOCP solver will be available sometime this year (courtesy of Bernhard Pfaff)...until then, use with caution.
Regards,
Alexios
On 23/01/2015 13:59, Pierre Org wrote:
> Hi Ilya
>
>
>
> Many thanks for pointing me toward the PARMA package. I have tried to use it but I seem to fail, I am not sure I am doing things right. When I optimise for a given level of risk (7% annualised) and then check what the portfolio volatility with the in-sample weights the level risk does not seem to equate to the intended target risk.
>
>
>
> Gilts World Ex UK Stocks UK Stocks
>
> 2014-02-28 1.548142e-03 0.0279529433 4.838851e-02
>
> 2014-03-31 7.806639e-05 0.0105305699 -2.702980e-02
>
> 2014-04-30 7.377730e-03 -0.0052597245 3.158530e-02
>
> 2014-05-31 9.628424e-03 0.0282594842 1.481751e-02
>
> 2014-06-30 -5.580206e-03 0.0001037494 -1.283548e-02
>
> 2014-07-31 1.057991e-02 -0.0034606566 -3.263463e-05
>
> 2014-08-31 3.487462e-02 0.0404001701 2.027569e-02
>
> 2014-09-30 -6.982201e-03 -0.0005089251 -2.937074e-02
>
> 2014-10-31 1.384694e-02 0.0226491298 -1.050032e-02
>
> 2014-11-30 3.209176e-02 0.0427556870 2.914371e-02
>
>
>
> I use the above data as an input (m) to the optimiser then force my
> monthly standard deviation to 0.07/sqrt(12)
>
>
>
> spec <- parmaspec(S = cov(m) ,riskB= 0.07/sqrt(12) ,risk="EV",riskType="maxreward", LB = rep(0,3), UB = rep(1,3), budget=1, forecast=colMeans(m))
>
> parmasolve(spec, solver="SOCP")}
>
>
>
> The annualised standard deviation of my series are :
>
>
>
>> apply(m,2,sd)*sqrt(12)
>
>
>
> Gilts World Ex UK Stocks UK Stocks
>
> 0.04938711 0.06359545 0.09144821
>
>
>
> so a 7% target risk portfolio that maximise return should exist as a solution. Anyhow the resulting weights from the above dataseries are calculated as:
>
>
>
>> spec <- parmaspec(S = cov(m) ,riskB= 0.07/sqrt(12) ,risk="EV",riskType="maxreward", LB = rep(0,3), UB = rep(1,3), budget=1, forecast=colMeans(m))
>
>> parmasolve(spec, solver="SOCP")}
>
>
>
>
>
> +---------------------------------+
>
> | PARMA Portfolio |
>
> +---------------------------------+
>
> No.Assets : 3
>
> Problem : SOCP
>
> Risk Measure : EV
>
> Objective : maxreward
>
> Risk : 0.0005859
>
> Reward : 0.0110454
>
>
>
> Optimal_Weights
>
> World Ex UK Stocks 0.9581
>
> Gilts 0.0419
>
>
>
>
>
>
>
> Now when I use the solution weights I do not get the same monthly
> targeted risk. I realise that the risk
>
>
>
>
>
>> w <- parmasolve(spec, solver="SOCP")@solution$weights
>
>> sd(rowSums(t(apply(m,1,function(x) x*t(w)))))*sqrt(12)
>
> [1] 0.0624795
>
>>
>
>
>
>
>
> My portfolio do not have a standard deviation of 0.7 as I was
> expecting……
>
>
>
>
>
> It is probably obvious to many of the PARMA users…but I can t understand where I get it wrong as the portfolio is obviously feasible. What I want is the portfolio that maximise return amongst all the possible portfolios with a 7% annualised vol.
>
> Any idea ?
>
>
>
>
>
> From: Ilya Kipnis [mailto:ilya.kipnis at gmail.com]
> Sent: 21 January 2015 15:50
> To: Pierre Org
> Cc: r-sig-finance at r-project.org
> Subject: Re: [R-SIG-Finance] Portfolio Optimisation as a function of targeted Risk rather than return.
>
>
>
> Check out the PortfolioAnalytics package.
>
>
>
> On Wed, Jan 21, 2015 at 6:13 AM, Pierre Org <pierre at lequeux.org> wrote:
>
> I am currently working on a portfolio optimisation strategy that would
> involves optimising a portfolio so that it maximises the returns for a user
> defined level of risk. E.g. keeping the volatility of the portfolio at 10%
> annualised whilst maximising the return for this level. For that
> purpose I was hoping to use the function maxreturnPortfolio in
> fPortfolio that should return the portfolio with the maximal return for a fixed target risk.
> Clearly though showing in this great package the function has been/is
> in development by the authors of the package and currently does not
> work as intended. This is confirmed by various posts and answer to those by the
> authors. I wonder if anyone knows of another more up to date package or
> way of doing this in R ?
>
>
>
> Any help would be really appreciated.
>
>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> 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.
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> 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.
>
More information about the R-SIG-Finance
mailing list