Sunday, May 7, 2017

Stock price predication using Weka




Background

As a seasonal stock trader, it has been a dream for me to have a stock info system suggesting order price.

Traditional technical indicators do help me a lot for giving buy / sell signal most of the time, but would big data with applying machine learning techniques help me to capture every trading opportunities? 

During the Easter holiday, I spent a few days for trying out using WEKA for stock price prediction.

Objective

To predicate day low and day high of the next trading day.


Choosing stock - 0002 CLP Power Hong Kong

Stock market: Hong Kong 
Stock code: 0002
Stock name: CLP Power Hong Kong Limited

The CLP Group (Chinese中電集團) and its holding companyCLP Holdings Ltd (SEHK0002) (Chinese中電控股有限公司), is a Hong Kong electric company that has businesses in a number of Asian markets and Australia. It is one of the two main electric power generation companies in Hong Kong.

There are couple of reasons to pick CLP Power 
  1. Sizable market cap
  2. Sizable trade volume per trading day
  3. Stable income
  4. Stable customer base (monopoly, the only electric power company in Kowloon and New Terror ties, covering over 85% of total Hong Kong population)
  5. Stable dividend scheme
  6. Stable government policy, less sensitive to political and financial issues
Feeding Weka- Preparing data files

I used Yahoo Finance as the data source for 
4/Jan/2000 - 4/May/2017 (4504 records), and later normalize the data and adding technical indicators. 

Be aware, Weka works with file in ARFF only. Read http://www.cs.waikato.ac.nz/ml/weka/arff.html for more.
WEKA comes with a ARFFViewer to read ARFF.




Data files:
Engine On

Open the "Explorer"

Press "Open File"
I pick 0002-COMPLETE.arff to predict change% of high on 5 May 2017.
In my dataset, each record comes with two expecting results. 

  1. The change percentage of lowest price; 
  2. The change percentage of the highest price. 

Either one has to be removed for processing. 

i.e. If you wanted to predict the change of the highest price, remove the change of lowest price.

Go to "Classify" and choose "AutoWEKAClassifier" as classifier
I gave 15 minutes to Weka to predict the change of highest price.
Results
I got the result after the coffee break. Weka found the best classifier.


And I scrolled down, there were the summary and the prediction result. The accuracy 
seemed to be very disappointing. But when I looked deeper into the results, it might not be that bad as it seems. 

Result files
  1. Low
  2. High
I decided to put the prediction results into a trading simulation to see how it looks. It is the end of part 1.

11 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. This comment has been removed by a blog administrator.

      Delete
  2. Great post David,
    did you get good results ?

    Thanks!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. can you share the logic to arrive at the technical indicators too please?

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete

Applying SMA10/20, SMA20/50 as trading signals

This is the comparison for results before and after applying SMA10/20 and SMA20/50 in the stock trader. Background Trading 3 stock ma...