Python stock market analysis tools?

Beliavsky beliavsky at aol.com
Mon Mar 5 08:55:28 EST 2007


On Mar 5, 12:41 am, "Raymond Hettinger" <pyt... at rcn.com> wrote:
> On Mar 4, 7:52 pm, "Mudcat" <mnati... at gmail.com> wrote:
>
> > I have done a bit of searching and can't seem to find a stock market
> > tool written in Python that is active. Anybody know of any? I'm trying
> > not to re-create the wheel here.
>
> What kind of tool do you want?  Getting quotes is the easy part:
>
> import urllib
> symbols = 'ibm jpm msft nok'.split()
> quotes = urllib.urlopen( 'http://finance.yahoo.com/d/quotes.csv?s='+
>          '+'.join(symbols) + '&f=l1&e=.csv').read().split()
> print dict(zip(symbols, quotes))
>
> The hard part is raising capital and deciding what to buy, sell, or
> hold.

Yes, and a discussion of investment approaches would be off-topic.
Unfortunately, newsgroups such as misc.invest.stocks are dominated by
spam -- the moderated newsgroup misc.invest.financial-plan is better.

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

http://groups.google.com/group/misc.invest.financial-plan/msg/3b9d13f3d399050c?dmode=source
Newsgroups: misc.invest.financial-plan
From: beliavsky at aol.com
Date: Mon, 26 Feb 2007 12:47:25 -0600
Local: Mon, Feb 26 2007 1:47 pm
Subject: Re: Portfolio Optimization Software?

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/src/contrib/Descriptions/backtest.html
"for exploring portfolio-based hypotheses about financial instruments
(stocks, bonds, swaps, options, et cetera)."




More information about the Python-list mailing list