logo资料库

matlba cvar.docx

第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
资料共3页,全文预览结束
1. %-------------PORTFOLIO OPTIMIZATION FUNCTION UNDER CVAR MINIMIZATION---- 2. % 3. function [fval,w]=CVaROptimization(ScenRets, R0, VaR0, beta, UB, LB) 4. % 5. % 6. % The function estimates the optimal portfolio weights that minimize CVaR 7. % under a given target return R0 8. % 9. %INPUTS: ScenRets: Portfolio returns matrix R0: The target return beta:The confidence level between 0.9 and 0.999 LB, UB the upper and lower bound for the optimal weights. For example 10. % 11. % 12. % If 13. % you imput UB=.25 none of the stocks can consist more than the 25% of the 14. % 15. % 16. % portfolio. VaR0= the initial guess for the portfolio VaR 17. %OUTPUTS: fval = CVaR of the optimal portfolio 18. % 19. % 20. % w= the weights of the optimal portfolio, The last element in w equals the VaR of the optimal portfolio 21. %---------------- INPUT ARGUMENTS-------------------------------------- 22. % The function accepts 6 imputs however only the two first are required 23. % If you dont supply the 6 argument then LB=0 (no short positions) 24. % If you dont supply the 5 argument then UB=1 25. % If you dont supply the 4 argument then beta=0.95 26. % If you dont supply the 3 argument VaR0 equals the HS VaR of the equally weighted 27. % portfolio 28.
29. % Author: Manthos Vogiatzoglou, Un of Macedonia, 20/08/2008 30. % contact: vogia@yahoo.com 31. [J, nAssets]=size(ScenRets); 32. w0=[(1/nAssets)*ones(1,nAssets)]; 33. if isempty(LB) 34. LB=0; 35. end 36. if isempty(UB) 37. UB=1; 38. end 39. if isempty(beta) 40. beta=.95; 41. end 42. if isempty(VaR0) 43. VaR0=quantile(ScenRets*w0',.95); 44. end 45. if beta>1|beta<0.9 46. error('The confidence level beta = 1 - alpha, should be in (0.9 0.99)') 47. end 48. if LB>=UB 49. error('The LB has to be smaller than UB') 50. end 51. if UB>1 52. error('The upper bound should be less than 1') 53. end 54. if LB<-1 55. error('The lower bound should be greater than -1') 56. end 57. i=1:nAssets; 58. % the objective function
59. Riskfun=@(w) w(nAssets+1)+(1/J)*(1/(1-beta))*sum(max(-w(i)*ScenRets(:,i)'-w(nAssets+ 1),0)); 60. w0=[w0 VaR0]; 61. % the (linear) equalities and unequalities matrixes 62. A=[-mean(ScenRets) 0]; 63. A=[A; -eye(nAssets) zeros(nAssets,1)]; 64. A=[A; eye(nAssets) zeros(nAssets,1)]; 65. b=[-R0 -LB*ones(1,nAssets) UB*ones(1,nAssets)]; 66. b=b'; 67. Aeq=[ ones(1,nAssets) 0]; 68. beq=[1]; 69. options=optimset('LargeScale','off'); 70. options=optimset(options,'MaxFunEvals',5000); 71. % The VaR of the optimal portfolio equals w(nassets+1) 72. [w,fval,exitflag,output]=fmincon(Riskfun,w0,A,b,Aeq,beq,LB,UB,[],option s)
分享到:
收藏