• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Portfolio Optimization Model

Joined
4/18/12
Messages
67
Points
118
Hello,

Does anybody have a working portfolio optimization model in c++, Python, or excel that can take in returns as inputs? I have an excel model but it can only take in the returns of 5 assets. I am looking to run the model on data of around 10-12 assets. I would appreaciate it if someone was willing to share. Thanks!
 
I have one coded in VBA that takes any number of assets, but it pulls data from a specific database only. Are you getting your returns from an SQL database or something? If so, then a simple linear algebra package and python will do.
 
Sorry I should have been more specific. The excel model I have takes in returns of 5 assets. It outputs the optimal portfolio weights. I am looking for something similar, yet lets me input around 10-12 sets of returns. I just used yahoo/google to pull my data.
 
in order to get an optimal portfolio you need to have a function you are trying minimize or maximize, you need to specify what it is you are trying to optimize.

for ex), portfolio that minimizes AVaR given shorting is allowed or not allowed.
 
Dataminer is right, you need to specify what you are optimizing. You can maximize many things like variance, sharpe ratio, max drawdown, VaR, ect. But I am guessing you are new to this, and referring to the classic Markowitz mean-variance optimization. Either way, I don't see why you can't just modify your existing worksheet, unless you didn't write it yourself and don't know how it works. Is this the case?
 
It has been a while since i looked at the excel model. I had to make it for an investments class. I will post the details tomorrow so that you guys can get an accurate idea of the objective of the assignment. I think my problem would be creating the covariance matrix for all the assets.
 
Yeah, I don't know what the problem is unless you don't know what a covariance matrix is...Did you forget or something? And you really shouldn't be asking others to do your homework for you...
 
It has been a while since i looked at the excel model. I had to make it for an investments class. I will post the details tomorrow so that you guys can get an accurate idea of the objective of the assignment. I think my problem would be creating the covariance matrix for all the assets.
Is this a homework? You should post the full problem.
 
I wrote a quick-n-dirty paper on this many years ago. It's a very, very basic intro to QP that can be implemented in a spreadsheet. I usually assign this as a model review for my students. If you like, I could send some working examples.
 

Attachments

  • PORT3.doc
    265.5 KB · Views: 223
I wrote a quick-n-dirty paper on this many years ago. It's a very, very basic intro to QP that can be implemented in a spreadsheet. I usually assign this as a model review for my students. If you like, I could send some working examples.
Very useful Ken, Thank you.

Yeah, I don't know what the problem is unless you don't know what a covariance matrix is...Did you forget or something? And you really shouldn't be asking others to do your homework for you...
This was homework over a year ago. I know what a covariance matrix is, I am just being a little lazy not wanting to create a new one for a bundle of assets.

just write some vba code to compute cov mat on the fly...
I am going to try this, this way I can use this in the future. I haven't had adequate time to take a look into this problem as I am doing this on the side for a relative.

I will keep you update and post my model when finished.
 
Back
Top