Newbie question, what is scipy and how is it used to optimize algorithms?
Newbie question, what is scipy and how is it used to optimize algorithms?
Hello Calvin,
There is Python scipy, which includes optimization routines (see http://docs.scipy.org/doc/scipy/reference/optimize.html). For a simple example that you can clone, see https://www.quantopian.com/posts/long-only-minimum-variance-portfolio-using-scipy-dot-optimize-dot-minimize.
Grant
Thanks Grant,
So sorry, but I got a bit lost in the technicals of the documentation. How does it optimize when the function is completely dependent on the incoming data? How does it work and how can it be applied? What is the big picture of how it functions and its results? Thanks a bunch,
Calvin
Hello Calvin,
One application in the context of trading is to manually define a portfolio of stocks and solve the allocation problem. For simplicity, say it's a portfolio with only 3 stocks in it. The portfolio is defined by the percentage of capital allocated to each stock. Mathematically, a vector x = [x0, x1, x2] is handy, with 'xn' as the fraction in each stock. So now the question is what values should be used for x0, x1, & x2 at any given time? The trick is to define an objective function that, when minimized (at least approximately), will yield the desired portfolio vector, x. The function would incorporate information about the 3 stocks, so trailing price and volume data could be used (and now that fundamental data are available, those could be incorporated, as well).
A complication is that the optimizer has to be able to handle the function, not getting stuck searching for a minimum and not landing on a "local minimum" in the parameter space (in our case, the allowed values of x0, x1, & x2).
Gotta run. Hope this helps. Give it a shot, and try to write a simple algo and post it here!
Grant