TL;DR - How do I add a target to CVXOPT instead of just minimizing the variable. Alternatively, how Do I add beta calculations to an algorithm like this instead of variance? Or is there another optimizer that would be better?
So I got the idea from Blue's Beta tool and something else I stumbled upon to meet my needs for an algorithm I want to attempt to use in the contest but can't because beta is too high.
My algo is a framework of separate algorithms that each return a portfolio weight (sub-portfolios), which are then combined and ordered with some fancy ordering logic into a total portfolio. So my intent is for for this code is to function in the following way:
- It calculates my total portfolio's beta
- It will take that number and reverse it, that will become the "target" beta of the CVXOPT
- The CVXOPT will look at the individual returns and betas of the ETF's I specify and optimize them to attempt to reach the target beta while not suffering too much losses.
- The CVXOPT will return the weights of it's sub-portfolio that will get added to the total portfolio. It has no clue what the total portfolio will be, it only makes decisions based on it the target it's given and the ETF's it's allowed to use.
So far by combining Blue's code and the markowitz optimization I think I have accomplished goals #1, #3, and #4 (code below) but I'm stuck on goal #2. I can't seem to figure out how to get CVXOPT to function in a way that I can specify a target beta. I'll be honest, I have no idea how the constraint matrices work but I'm assuming I need a new one. If this isn't the best optimizer to use then maybe someone here can show me how to use a different optimizer such as scipy.optimize() for a target beta instead of for minimum variance if that would be easier.