4

I'm looking for a finance library in python which offers a method similar to the MATLAB's portalloc . It is used to optimize a portfolio.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Alexandre Deschamps
  • 1,178
  • 2
  • 14
  • 21

5 Answers5

3

If you know linear algebra, there is a simple function for solving the optimization problem which any library should support. Unfortunately, it's been so long since I researched it I can't tell you the formula nor a library that supports it, but a little research should reveal it. The main point is that any linear algebra library should do.

Update:

Here's a quote from a post I found.

Some research says that "mean variance portfolio optimization" can give good results. I discussed this in a message

To implement this approach, a needed input is the covariance matrix of returns, which requires historical stock prices, which one can obtain using "Python quote grabber" http://www.openvest.org/Databases/ovpyq .

For expected returns -- hmmm. One of the papers I cited found that assuming equal expected returns of all stocks can give reasonable results.

Then one needs a "quadratic programming" solver, which appears to be handled by the CVXOPT Python package.

If someone implements the approach in Python, I'd be happy to hear about it.

There is a "backtest" package in R (open source stats package callable from Python) http://cran.r-project.org/web/packages/backtest/index.html "for exploring portfolio-based hypotheses about financial instruments (stocks, bonds, swaps, options, et cetera)."

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
Binary Phile
  • 2,538
  • 16
  • 16
0

If you know how to define your objective function. You can use Numpy to solve almost any portfolio optimization problem.

pyCthon
  • 11,746
  • 20
  • 73
  • 135
0

Python implementations of some typical portfolio optimizations can be found at https://github.com/czielinski/portfolioopt. The corresponding quadratic programs are being solved using the CVXOPT library. (Disclaimer: this is my own GitHub repository.)

0

Maybe you could use this library (statlib) or this one (Mystic) to help you.

esylvestre
  • 1,850
  • 4
  • 21
  • 30
0

I am new but I believe gradient descent is what you are looking for. Michael Chu, who is author of optopsy 2.0 python library (https://github.com/michaelchu/optopsy), has great insights into implementation. Works great with v3.7.

Shmn
  • 681
  • 1
  • 4
  • 22
Cloihdna
  • 11
  • 2
  • The method involves lagrange multipliers for portfolio optimization but it escapes me the name of it. – Cloihdna Oct 25 '20 at 01:11