08-06-2018 11:49 PM
Hi All,
I am having difficulty with a portfolio optimization problem. I can achieve what I want with amazing ease using MS Excel's solver add-in but I need to perform the same calculations within a LabVIEW app.
In the MS Excel solver you can find the portfolio with the lowest standard deviation by running the solver, selecting "min" and pointing it to the standard deviation cell and ask it to vary the portfolio stock weightings with a couple of constraints (they must add up to 100% and must be positive). This is simple and after MUCH reading I finally was able to achieve the same result in LabVIEW using the quadratic programming vi.
The problem I have is that I now want to calculate the optimal risky portfolio. In Excel this is easy as you run the solver, select "max" and point to the cell where you calculate the Sharpe ratio. I cannot find a way to get the quadratic programming vi to calculate a MAXIMUM of anything. I have looked through several other vi's in the optimization palette but a) I cannot see how to calculate a maximum and b) I cannot work out how to supply the correct objective function.
Given the sheer volume of material out there on portfolio optimization I am embarrassed I cannot solve this in LabVIEW. I am hoping there are a few of you out there that have looked at this and can point me in the right direction. Below is a link to the excel way of solving this.
I can provide my VI (after some massaging) if you want, but I suspect this is a case of "Hey, you should just use <solution.vi> and feed it <required inputs> in this format".
Thanks in advance.
08-07-2018 01:00 AM
08-07-2018 09:02 AM
The formulas are all over the internet in various forms. It's far simpler for me to grab an image of the maths than try and type it out as you will see from the image below.
As I mentioned previously, this is a maximisation problem, not minimisation. So I am struggling to work out how to use the quadratic programming VI.
08-07-2018 10:32 AM - edited 08-07-2018 10:33 AM
@phil_prismtc wrote:
Hi All,
I am having difficulty with a portfolio optimization problem. I can achieve what I want with amazing ease using MS Excel's solver add-in but I need to perform the same calculations within a LabVIEW app.
The EXCEL solver is a handy tool to solve a linear equation system, this is very likely to be doable in LabView
[...]
This is simple and after MUCH reading I finally was able to achieve the same result in LabVIEW using the quadratic programming vi.Well done.
Ok, so the app you want to write in LabView has to accept an input portfolio - and after some processing, it outputs an optimized portfolio based on the input portfolio
[...]
In the MS Excel solver you can find the portfolio with the lowest standard deviation by running the solver, selecting "min" and pointing it to the standard deviation cell and ask it to vary the portfolio stock weightings with a couple of constraints (they must add up to 100% and must be positive).
[...]
So, you achieved to calculate the portfolio with the lowest standard deviation with "quadratic programming.vi" ? Can you provide an successful example of an input and output dataset using the LabView "quadratic programming.vi"?
The problem I have is that I now want to calculate the optimal risky portfolio. In Excel this is easy as you run the solver, select "max" and point to the cell where you calculate the Sharpe ratio. I cannot find a way to get the quadratic programming vi to calculate a MAXIMUM of anything.
Is the optimal risky portfolio defined as the portfolio with the highest standard deviation ?
08-07-2018 07:10 PM - edited 08-07-2018 07:18 PM
Here is the VI (LV2016) that calculates the portfolio with the minimum standard deviation. This is (relatively) easy as the QP vi is designed to find a minimum.
The optimization process takes the input portfolio described in terms of the co-variance matrix and expected returns for each constituent stock.
The Minimum Variance Portfolio (MVP) is the one where the weightings of each stock are tuned to produce the lowest portfolio standard deviation. This is what the attached VI does and has been verified by the Excel solver.
The optimal risky portfolio is the one that has the highest Sharpe Ratio as described above.
08-07-2018 08:56 PM
I like math, but Economics is just mysterious to me. I did see stuff on the Web for Tangency Portfolios, which I gather is what you want to compute, but I don't understand what they are talking about ...
Bob Schor
08-07-2018 09:04 PM
I completely understand Bob. This IS a math problem, but phrased in economics terms which makes it all that much harder to discern exactly which way to approach the problem. Selecting the correct mathematical approach (solver) to use is half my problem. Being able to understand how LabVIEW implements the correct approach is the second challenge I have.
08-07-2018 09:18 PM
Here's a really crazy idea -- you have some function/measure you are attempting to maximize. Is it something that you know (because, for example, it is a square) can never go to zero? If that is the case, could you run a minimization problem in 1/Function? The values that minimize the reciprocal should (logically) maximize the function itself ... But that's just too weird to be correct.
Bob Schor
08-07-2018 10:57 PM
I have thought about this. Unfortunately, the Sharpe ratio (Sr) can go negative which is definitely sub-optimal. I have thought about minimizing 100-Sr but I have not gone through the heartache of trying to massage those constraints into the QP vi. There is a nice reduction of the problem described above into what I think is a set of linear equations:
08-08-2018 05:51 AM - edited 08-08-2018 05:53 AM
wrote:
The problem I have is that I now want to calculate the optimal risky portfolio. In Excel this is easy as you run the solver, select "max" and point to the cell where you calculate the Sharpe ratio.
So, we assume there exists a valid solution which can be calculated via EXCEL solver, which is described in the youtube video.
Does this "EXCEL solver" algorithm also work for the data in Portfolio Optimization example.vi 23 KB ?
@phil_prismtc wrote:I cannot find a way to get the quadratic programming vi to calculate a MAXIMUM of anything.
We know, "Quadratic Programming VI" is not designed to do your task.
We don't know if we can tweak it to do your task,
but we assume this is possible
At least we know that we need additional data,
e.g. the Sharpe ratio
maybe something else?
@phil_prismtc wrote:
There is a nice reduction of the problem described above into what I think is a set of linear equations:
Is there a geometrical representation of your problem?
https://www.quora.com/What-is-the-tangency-portfolio-and-how-do-I-derive-it
http://www.ece.northwestern.edu/local-apps/matlabhelp/toolbox/optim/tutor15b.html