Skip to main content
edited title, retagged
Link
SRKX
  • 11.2k
  • 4
  • 42
  • 84

Market neutral (Beta) constraint How to build a market-neutral portfolio optimisation using CVXPY?

reformatting, rephrasing.
Source Link
SRKX
  • 11.2k
  • 4
  • 42
  • 84

Market neutral (Beta) constraint portfolio optimisation using CVXPY?

I am trying to implement a simple minminimum variance portfolio optimisation with a few simple constraints, long-only, sums to one. I also want to constraint on my betas to create a market neutral portfolio, i.e sum(betas) = 0.:

  • long-only portfolio
  • fully invested (sums to one)
  • market-neutrality, i.e sum(betas) = 0.

I am not very experienced with cvxpycvxpy but I quite like it and want to implement my stuff with it going forward. AsBelow is an example( from the cvxpy website), which uses

$$Min_x\;\; \frac{1}{2}x^T\Sigma x$$$$\min_x\;\; \frac{1}{2}x^T\Sigma x$$ Under the constraints $$x^T \mathbb{1}=1$$ $$\mu^Tx \geq \tau$$

I now want to add

$$B^Tx=0$$ The constraint $B^Tx=0$, which will ensure that the portfolios beta is zero.

Here is the example:

from cvxpy import *
import numpy as np

np.random.seed(1)
n = 10
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)

betas = [np.random.uniform(-1,1) for _ in range(10)]

w = Variable(n)

risk = quad_form(w, Sigma)
constraints = [sum_entries(w) == 1, w >= 0]
prob = Problem(Minimize(risk), constraints)
                          
for i in range(100):
    prob.solve()

print('Weights :', w.value)

How can I define the additional variable for beta and how do you alter your constraints list. 

From the manual I assume we need s.thsomething in the form a quad_form()quad_form(), but does this have to be defines similardefined similarly to the risk variable in the example or inside the constraints object, and? how do you link it to the betas data vector  ? 

I would have done s.thsomething like

sum(quad_form(w, betas)) == 0 

inside the constraints object which unfortunately doesn't work.

Market neutral (Beta) constraint portfolio optimisation using CVXPY

I am trying to implement a simple min variance portfolio optimisation with a few simple constraints, long-only, sums to one. I also want to constraint on my betas to create a market neutral portfolio, i.e sum(betas) = 0. I am not very experienced with cvxpy but I quite like it and want to implement my stuff with it going forward. As an example( from the cvxpy website), which uses

$$Min_x\;\; \frac{1}{2}x^T\Sigma x$$ Under the constraints $$x^T \mathbb{1}=1$$ $$\mu^Tx \geq \tau$$

I now want to add

$$B^Tx=0$$ The constraint $B^Tx=0$ will ensure that the portfolios beta is zero.

from cvxpy import *
import numpy as np

np.random.seed(1)
n = 10
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)

betas = [np.random.uniform(-1,1) for _ in range(10)]

w = Variable(n)

risk = quad_form(w, Sigma)
constraints = [sum_entries(w) == 1, w >= 0]
prob = Problem(Minimize(risk), constraints)
                          
for i in range(100):
    prob.solve()

print('Weights :', w.value)

How can I define the additional variable for beta and how do you alter your constraints list. From the manual I assume we need s.th in the form a quad_form(), but does this have to be defines similar to the risk variable in the example or inside the constraints object, and how do you link it to the betas data vector  ? I would have done s.th like

sum(quad_form(w, betas)) == 0 

inside the constraints object which unfortunately doesn't work.

Market neutral (Beta) constraint portfolio optimisation using CVXPY?

I am trying to implement a simple minimum variance portfolio optimisation with a few simple constraints:

  • long-only portfolio
  • fully invested (sums to one)
  • market-neutrality, i.e sum(betas) = 0.

I am not very experienced with cvxpy but I quite like it and want to implement my stuff with it going forward. Below is an example( from the cvxpy website), which uses

$$\min_x\;\; \frac{1}{2}x^T\Sigma x$$ Under the constraints $$x^T \mathbb{1}=1$$ $$\mu^Tx \geq \tau$$

I now want to add $B^Tx=0$, which will ensure that the portfolios beta is zero.

Here is the example:

from cvxpy import *
import numpy as np

np.random.seed(1)
n = 10
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)

betas = [np.random.uniform(-1,1) for _ in range(10)]

w = Variable(n)

risk = quad_form(w, Sigma)
constraints = [sum_entries(w) == 1, w >= 0]
prob = Problem(Minimize(risk), constraints)
                          
for i in range(100):
    prob.solve()

print('Weights :', w.value)

How can I define the additional variable for beta and how do you alter your constraints list. 

From the manual I assume we need something in the form a quad_form(), but does this have to be defined similarly to the risk variable in the example or inside the constraints object? how do you link it to the betas data vector? 

I would have done something like

sum(quad_form(w, betas)) == 0 

inside the constraints object which unfortunately doesn't work.

added 24 characters in body
Source Link

I am trying to implement a simple min variance portfolio optimisation with a few simple constraints, long-only, sums to one. I also want to constraint on my betas to create a market neutral portfolio, i.e sum(betas) = 0. I am not very experienced with cvxpy but I quite like it and want to implement my stuff with it going forward. As an example( from the cvxpy website), which uses

$$Min_x\;\; \frac{1}{2}x^T\Sigma x$$ Under the constraints $$x^T \mathbb{1}=1$$ $$\mu^Tx \geq \tau$$

I now want to add

$$B^Tx=0$$ The constraint $B^Tx=0$ will ensure that the portfolios beta is zero.

from cvxpy import *
import numpy as np

np.random.seed(1)
n = 10
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)

betas = [random[np.random.uniform(-1,1) for _ in range(10)]

w = Variable(n)

risk = quad_form(w, Sigma)
constraints = [sum_entries(w) == 1, w >= 0]
prob = Problem(Minimize(risk), constraints)
                          
for i in range(100):
    prob.solve()

print('Weights :', w.value)

How can I define the additional variable for beta and how do you alter your constraints list. From the manual I assume we need s.th in the form a quad_form(), but does this have to be defines similar to the risk variable in the example or inside the constraints object, and how do you link it to the betas data vector ? I would have done s.th like

sum(quad_form(w, betas)) == 0 

inside the constraints object which unfortunately doesn't work.

I am trying to implement a simple min variance portfolio optimisation with a few simple constraints, long-only, sums to one. I also want to constraint on my betas to create a market neutral portfolio, i.e sum(betas) = 0. I am not very experienced with cvxpy but I quite like it and want to implement my stuff with it going forward. As an example( from the cvxpy website), which uses

$$Min_x\;\; \frac{1}{2}x^T\Sigma x$$ Under the constraints $$x^T \mathbb{1}=1$$ $$\mu^Tx \geq \tau$$

I now want to add

$$B^Tx=0$$ The constraint $B^Tx=0$ will ensure that the portfolios beta is zero.

from cvxpy import *

np.random.seed(1)
n = 10
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)

betas = [random.uniform(-1,1) for _ in range(10)]

w = Variable(n)

risk = quad_form(w, Sigma)
constraints = [sum_entries(w) == 1, w >= 0]
prob = Problem(Minimize(risk), constraints)
                          
for i in range(100):
    prob.solve()

print('Weights :', w.value)

How can I define the additional variable for beta and how do you alter your constraints list. From the manual I assume we need s.th in the form a quad_form(), but does this have to be defines similar to the risk variable in the example or inside the constraints object, and how do you link it to the betas data vector ? I would have done s.th like

sum(quad_form(w, betas)) == 0 

inside the constraints object which unfortunately doesn't work.

I am trying to implement a simple min variance portfolio optimisation with a few simple constraints, long-only, sums to one. I also want to constraint on my betas to create a market neutral portfolio, i.e sum(betas) = 0. I am not very experienced with cvxpy but I quite like it and want to implement my stuff with it going forward. As an example( from the cvxpy website), which uses

$$Min_x\;\; \frac{1}{2}x^T\Sigma x$$ Under the constraints $$x^T \mathbb{1}=1$$ $$\mu^Tx \geq \tau$$

I now want to add

$$B^Tx=0$$ The constraint $B^Tx=0$ will ensure that the portfolios beta is zero.

from cvxpy import *
import numpy as np

np.random.seed(1)
n = 10
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)

betas = [np.random.uniform(-1,1) for _ in range(10)]

w = Variable(n)

risk = quad_form(w, Sigma)
constraints = [sum_entries(w) == 1, w >= 0]
prob = Problem(Minimize(risk), constraints)
                          
for i in range(100):
    prob.solve()

print('Weights :', w.value)

How can I define the additional variable for beta and how do you alter your constraints list. From the manual I assume we need s.th in the form a quad_form(), but does this have to be defines similar to the risk variable in the example or inside the constraints object, and how do you link it to the betas data vector ? I would have done s.th like

sum(quad_form(w, betas)) == 0 

inside the constraints object which unfortunately doesn't work.

Source Link
Loading