Feasible set

571 days ago by rafalzajac74@gmail.com

mu_1=0.1 mu_2=0.15 sigma_1=0.2 sigma_2=0.3 @interact def feasible_set(rho=(8,(-10..10))): rho = rho/10 mu(w)=w*mu_1+(1-w)*mu_2 sigma(w)=abs(w^2*sigma_1^2+(1-w)^2*sigma_2^2+2*w*(1-w)*rho*sigma_1*sigma_2)^0.5 show(parametric_plot( (sigma(w), mu(w)), (w, -1, 2),detect_poles=true )+point([(sigma_1,mu_1),(sigma_2,mu_2)])) 
       

Click to the left again to hide and once more to show the dynamic interactive window

m = matrix([[2,3],[4,5]]) w = var('w') #w=5 wv=matrix([[w,1-w]]) mu1=matrix([[0.1],[0.15]]) mu(w) = wv*mu1 plot(mu(w),w) 
       
Traceback (click to the left of this block for traceback)
...
TypeError: mutable matrices are unhashable
Traceback (most recent call last):    mu(w) = wv*mu1
  File "", line 1, in <module>
    
  File "/tmp/tmp3WftUW/___code___.py", line 10, in <module>
    exec compile(u'plot(mu(w),w)
  File "", line 1, in <module>
    
  File "/home/sage/sage_install/sage-4.3.5/local/lib/python2.6/site-packages/sage/plot/misc.py", line 283, in wrapper
    return func(*args, **kwds)
  File "/home/sage/sage_install/sage-4.3.5/local/lib/python2.6/site-packages/sage/plot/misc.py", line 138, in wrapper
    return func(*args, **options)
  File "/home/sage/sage_install/sage-4.3.5/local/lib/python2.6/site-packages/sage/plot/plot.py", line 2488, in plot
    G = funcs.plot(*args, **original_opts)
  File "expression.pyx", line 7134, in sage.symbolic.expression.Expression.plot (sage/symbolic/expression.cpp:28395)
  File "expression.pyx", line 7168, in sage.symbolic.expression.Expression._plot_fast_callable (sage/symbolic/expression.cpp:28678)
  File "fast_callable.pyx", line 451, in sage.ext.fast_callable.fast_callable (sage/ext/fast_callable.c:3612)
  File "fast_callable.pyx", line 1725, in sage.ext.fast_callable.generate_code (sage/ext/fast_callable.c:8226)
  File "fast_callable.pyx", line 1854, in sage.ext.fast_callable.InstructionStream.load_const (sage/ext/fast_callable.c:9184)
  File "fast_callable.pyx", line 1930, in sage.ext.fast_callable.InstructionStream.instr (sage/ext/fast_callable.c:9529)
  File "matrix_generic_dense.pyx", line 166, in sage.matrix.matrix_generic_dense.Matrix_generic_dense.__hash__ (sage/matrix/matrix_generic_dense.c:2798)
  File "matrix_dense.pyx", line 70, in sage.matrix.matrix_dense.Matrix_dense._hash (sage/matrix/matrix_dense.c:2001)
TypeError: mutable matrices are unhashable
mu = matrix([0.1,0.15]) sigma = matrix([0.2,0.3]) rho = matrix([[1,0.08],[0.08,1]]) html("<b>Input data:</b>") html('$\mu = '+latex(mu.n(5))+'$') html('$\sigma = '+latex(sigma.n(5))+' $') html('$\\rho = '+latex(rho.n(6))+' $') html('</br>') html("<b>Covariance matrix:</b>") cov = sigma.transpose()*sigma for i in range(0,len(sigma.columns())): for j in range(0,len(sigma.columns())): cov[i,j] = cov[i,j]*rho[i,j] html('$C = '+latex(cov.n(6))+' $') icov = cov.inverse(); html('$C^{-1} = '+latex(icov.n())+' $') html('</br>') html("<b>Matrix M:</b>") html('$M=\\left[\\begin{array}'+ '\\mu^{T}C^{-1}\mu & {1}^{T}C^{-1}\\mu\\\\'+ '\\mu^{T}C^{-1}{1} & {1}^{T}C^{-1}{1}\\end{array}\\right]$') one = matrix([[1,1]]) show(one) #M = matrix([[mu.tanspose()*icov*mu,],[]]) 
       
Input data:
\mu = \left(\begin{array}{rr} 0.10 & 0.15 \end{array}\right)
\sigma = \left(\begin{array}{rr} 0.20 & 0.30 \end{array}\right) 
\rho = \left(\begin{array}{rr} 1.0 & 0.080 \\ 0.080 & 1.0 \end{array}\right) 

Covariance matrix: C = \left(\begin{array}{rr} 0.040 & 0.0048 \\ 0.0048 & 0.090 \end{array}\right) C^{-1} = \left(\begin{array}{rr} 25.1610305958132 & -1.34192163177670 \\ -1.34192163177670 & 11.1826802648059 \end{array}\right)
Matrix M: M=\left[\begin{array}\mu^{T}C^{-1}\mu & {1}^{T}C^{-1}\mu\\\mu^{T}C^{-1}{1} & {1}^{T}C^{-1}{1}\end{array}\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr} 1 & 1 \end{array}\right)
Input data:
\mu = \left(\begin{array}{rr} 0.10 & 0.15 \end{array}\right)
\sigma = \left(\begin{array}{rr} 0.20 & 0.30 \end{array}\right) 
\rho = \left(\begin{array}{rr} 1.0 & 0.080 \\ 0.080 & 1.0 \end{array}\right) 

Covariance matrix: C = \left(\begin{array}{rr} 0.040 & 0.0048 \\ 0.0048 & 0.090 \end{array}\right) C^{-1} = \left(\begin{array}{rr} 25.1610305958132 & -1.34192163177670 \\ -1.34192163177670 & 11.1826802648059 \end{array}\right)
Matrix M: M=\left[\begin{array}\mu^{T}C^{-1}\mu & {1}^{T}C^{-1}\mu\\\mu^{T}C^{-1}{1} & {1}^{T}C^{-1}{1}\end{array}\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr} 1 & 1 \end{array}\right)