| Home | Trees | Indices | Help |
|
|---|
|
|
1 from math import sqrt
2 from cvxopt.base import matrix
3 from cvxopt.blas import dot
4 from cvxopt.solvers import qp
5 ##import pylab
6
7 p = matrix([[2,0],
8 [0,8]],tc='d')
9 q = matrix([-8,-16],tc='d')
10 G = matrix([[1,1,1],
11 [1,0,-1],
12 ],tc='d')
13 h = matrix([5,3,2],tc='d')
14
15 ##print type(p)
16
17 res = qp(p,q,G,h)
18
19 ##options['show_progress'] = False
20 # Problem data.
21 ##n = 4
22 ##S = matrix([[ 4e-2, 6e-3, -4e-3, 0.0 ],
23 ## [ 6e-3, 1e-2, 0.0, 0.0 ],
24 ## [-4e-3, 0.0, 2.5e-3, 0.0 ],
25 ## [ 0.0, 0.0, 0.0, 0.0 ]])
26 ##pbar = matrix([.12, .10, .07, .03])
27 ##G = matrix(0.0, (n,n))
28 ##G[::n+1] = -1.0
29 ##h = matrix(0.0, (n,1))
30 ##A = matrix(1.0, (1,n))
31 ##b = matrix(1.0)
32 ##
33 ##print qp(S, -pbar, G, h, A, b)['y']
34
35 # Plot trade-off curve and optimal allocations.
36 ##pylab.figure(1, facecolor='w')
37 ##pylab.plot(risks, returns)
38 ##pylab.xlabel('standard deviation')
39 ##pylab.ylabel('expected return')
40 ##pylab.axis([0, 0.2, 0, 0.15])
41 ##pylab.title('Risk-return trade-off curve (fig 4.12)')
42 ##pylab.yticks([0.00, 0.05, 0.10, 0.15])
43 ##
44 ##pylab.figure(2, facecolor='w')
45 ##c1 = [ x[0] for x in portfolios ]
46 ##c2 = [ x[0] + x[1] for x in portfolios ]
47 ##c3 = [ x[0] + x[1] + x[2] for x in portfolios ]
48 ##c4 = [ x[0] + x[1] + x[2] + x[3] for x in portfolios ]
49 ##pylab.fill(risks + [.20], c1 + [0.0], '#F0F0F0')
50 ##pylab.fill(risks[-1::-1] + risks, c2[-1::-1] + c1, '#D0D0D0')
51 ##pylab.fill(risks[-1::-1] + risks, c3[-1::-1] + c2, '#F0F0F0')
52 ##pylab.fill(risks[-1::-1] + risks, c4[-1::-1] + c3, '#D0D0D0')
53 ##pylab.axis([0.0, 0.2, 0.0, 1.0])
54 ##pylab.xlabel('standard deviation')
55 ##pylab.ylabel('allocation')
56 ##pylab.text(.15,.5,'x1')
57 ##pylab.text(.10,.7,'x2')
58 ##pylab.text(.05,.7,'x3')
59 ##pylab.text(.01,.7,'x4')
60 ##pylab.title('Optimal allocations (fig 4.12)')
61 ##pylab.show()
62
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Wed Aug 19 16:50:05 2009 | http://epydoc.sourceforge.net |