views:

909

answers:

9

Hi guys,

Can anyone direct me in the right direction?

Basically, I'm trying to analyze stock prices and see if I can spot any patterns. I'm using PHP and MySQL to do this. Where can I find sample algorithms like the ones used in MetaStock or thinkorswim? I know they are closed source, but are there any tutorials available for beginners?

Thank you,

P.S. I don't even know what to search for in google :(

+7  A: 

A basic, educational algorithm to start with is a dual-crossover moving average. Simply chart fast (say, 5-day) and slow (say, 10-day) moving averages of a stock's closing price, and you have a weak predictor of when to buy long (fast line goes above slow) and sell short (slow line goes above the fast). After getting this working, you could implement exponential smoothing (see previously linked wiki article).

That would be a decent start. Take a look at other technical analysis techniques, but do keep in mind that this is quite a perilous method of trading.

Update: As for actually implementing this? You're a PHP programmer, so here is a charting library for PHP. This is the one I used a few years ago for this very project, and it worked out swimmingly. Maybe someone else can recommend a better one. If you need a free source of data, take a look at Yahoo! Finance's historical data. They dispense CSV files containing daily opening prices, closing prices, trading volume, etc. of virtually every indexed corporation.

BipedalShark
Technical analysis is what you want. Also see http://www.riskglossary.com/ for help while trying to make sense of this.
fatcat1111
+1 for an actual answer.
hughdbrown
yeah, i know it is technical analysis that i want, but my question was how do i program those that patterns? of course I could make my own algorithm but since i don't have experience it would not be an efficient one.
Baha
+2  A: 

First you will need a solid math background : statistics in general, correlation analysis, linear algebra... If you really want to push it check out dimensional transposition. Then you will need solid basis in Data Mining. Associations can be useful if yo want to link strict numerical data with news headlines and other events.

One thing for sure you will most likely not find pre-digested algorithms out there that will make you rich...

I know someone who is trying just that... He is somewhat successful (meaning is is not loosing money and is making a bit) and making his own algorithms... I should mention he has a doctorate in Actuarial science.

Here are a few more links... hope they help out a bit

Best of luck to you

Newtopian
thank you, the best answer so far
Baha
A: 

Thank you guys so much. I know most of the stuff you all mentioned. I just didn't know how to translate my knowledge into a computer language. I think I'll look at data mining and try to find some programming examples. Thank you again.

Baha
+2  A: 

Check out algorithms at investopedia and FM Labs has formulas for a lot of technical analysis indicators.

hughdbrown
thank you, but i was more interested in how to program and find patterns, which is, I'm guessing, is more than just implementing technical indicator formulas
Baha
Okay, then here is an article I wrote that takes a technical analysis formula and works through producing code: http://www.iwebthereforeiam.com/iwebthereforeiam/2008/05/money-flow-index-and-other-tec.html
hughdbrown
thanks, hughbrown!
Baha
+1  A: 

May I suggest that you do a little reading with respect to the Kalman filter? Wikipedia is a pretty good place to start: http://en.wikipedia.org/wiki/Kalman%5Ffilter/

This should give you a little background on the problem of estimating and predicting the variables of some system (the stock market in this case).

But the stock market is not very well behaved so you may want to familiarize yourself with non linear extensions to the KF. Yes, the wikipedia entry has sections on the extended KF and the unscented KF, but here is an introduction that is just a little more in-depth: http://cslu.cse.ogi.edu/nsel/ukf/

I suppose if anyone had ever tried this before then it would have been all over the news and very well known. So you may very well be on to something.

leed25d
thank you, another good answer
Baha
+2  A: 

Here's a pattern for ya http://ddshankar.files.wordpress.com/2008/02/image001.jpg

Dude
haha, it reminds me of south park
Baha
beautiful :) (no, it doesn't need 15 chars)
ldigas
+2  A: 

I'd start with a good introduction to time series analysis and go from there. If you're interested in finding patterns then the interesting term is "1D-Pattern Matching". But for that you need nice features, so google for "Feature extraction in time series". Remember GiGo. So make sure you have error-free stock price data for a sufficiently long timeperiod before you start.

jilles de wit
thanks for a good answer
Baha
A: 

Use TradeStation

It is a platform that lets you write software to analyze historical stock data. You can even write programs that would trade the stock, and you can back test your program on historical data or run it real time through out the day.

Nick
thanks for the info
Baha
+1  A: 

Save yourself time and use programs like NinjaTrader and Wealth-Lab. Both of them are great technical analysis platforms and accept C# as a programming language for defining your trading rules. Every possible technical indicator you can imagine is already included and if you need something more advanced you can always write your own indicator. You would also need a lot of data in order for your analysis to be statistically significant. For US stocks and ETFs, visit www.Kibot.com. We have good experience using their data.

boe100