Sunday, January 24, 2016

Stock screening

Hello, welcome back to my blog about automated trading. Last week I have written article about historical quotes. This week I will write about the stock screening.

Example of the screener is on my trading cloud project page. For the source code example, please download repository and update to branch 3-stock-screener, changeset 8401ea797edc.

Background

I don't want go into theory of what stocks to choose and why. There are already plenty of other articles about that. I am going to the point when you actually know the criteria and you just want to find stocks which matches them. There are about 8000 publicly traded companies just in the US market. One way how to find them and filter them is to use screner. For example there is one offered by finviz. Simply put your filter and get what you want. My system fully automates this. It parses the result returned by finviz and allows it for the further processing. Columns included in the result are Ticker, Company, Sector and Industry. Very simple and copmletely free.

There is one note to be aware. As system merges data from multiple sources, they doesn't necessary have same data (e.g. some company appears only in one of them). Just need to live with that fact, nothing is perfect. Now let's proceed to the concrete code.

Coding

Code start with Instrument class. This is anything which can be traded. In this case this mean stock. There is little bit of mapping, but it is 1-1 (e.g. Ticker in finviz means Symbol in system). Then there is interface FinvizConnector. This has method downloadInstruments which accepts link to the finviz which has encoded filter (simply put filter on screener page and copy paste the link). Finally there is an implementation called DefaultFinvizConnector which does the job. All this is accompanyed with unit test DefaultFinvizConnectorTest and little application to play - DefaultFinvizConnectorTestInternetApp. Have fun!!!

That's it for today. Next time I will write about interface for receiving real time quotes duing trading session. Thank you for reading!

No comments:

Post a Comment