# portfolio

Solve a Markowitz Portfolio problem with JuMP: \begin{alignat}{2} \min_{0 \leq x \leq 1} \quad & x^T \Sigma x \\ \text{subject to} \quad & \mu x \geq r_{min} \\ & \sum x = 1 \\ \end{alignat}



In [24]:

using JuMP, Mosek, DataFrames, PyPlot




In [25]:

data=data[2:end]




Out[25]:

stock1stock2stock310.425.877.5921.758.7916.1330.35.335.840.245.849.1451.659.0313.2560.03.883.2370.667.089.080.35.335.890.245.849.14100.285.516.96111.659.0313.25120.385.737.3513-1.243.916.7114-0.740.16-2.63151.413.2418.7816-0.745.4711.65174.213.915.9818-3.592.949.36191.789.8314.1120-0.852.276.8121-0.54-3.34-6.5622-2.882.4815.69230.544.358.43247.3910.984.51255.667.410.72261.482.996.75272.265.358.05283.5912.0315.61293.452.49-0.33301.87.6112.52&vellip&vellip&vellip&vellip




In [26]:

data = convert(Array{Float64}, data)
plot([i for i in 1:length(data[:,1])],data[:,1],color="r", label="asset1")
plot(data[:,2],color="b",label="asset2")
plot(data[:,3],color="g",label="asset3")
legend()




Out[26]:

PyObject <matplotlib.legend.Legend object at 0x14b524fd0>




In [40]:

n, μ, Σ = length(data[1,:]), vec(mean(data,1)), cov(data)
result=[]
figure(figsize=(4.0,3.0))
for r_min in 0.0:1.0:5.0
port = Model(solver=MosekSolver(LOG=0))
@variable(port, 0 ≤ x[1:n] ≤ 1)
@constraint(port, sum(x) == 1)
@constraint(port, dot(μ,x) ≥ r_min)
@objective(port, Min, x' * Σ * x)
solve(port)
plot([i for i in 1:n], getvalue(x), label=r_min)
end
legend()




Out[40]:

PyObject <matplotlib.legend.Legend object at 0x14d021fd0>




In [ ]: