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.

Thursday, April 27, 2017

Connecting security dongle through USB





If you have a legacy software purchased in good old days (may be DOS / Windows 3.X- 98) requiring a security token to be plugged in the parallel printer port (LPT) for execution, but your new PC does not have a parallel printer port and has a USB port, you still have a chance to have your legacy software running again.

First thing first, you have to get a "USB to printer port" cable. You can easily find it on Amazon or eBay. It costs below USD10.


Once you have it, put your security token in place, and insert it into the USB port.



The next thing, you need to add a "Virtual Printer" to your Windows. You do not need a physical printer, a nd You do not have to download any software to do that. Just follow these steps.









Now, you have a dummy printer, you are almost there. The next thing is to download DOSPrintUI. It is a freeware to forward command from the "Virtual Printer" to the USB. It is free, absolutely free.

http://andtechnologies.com/download/free20110630/DOSPrint.zip



Map  the "Virtual Printer" to a LPT port.


You are good to go!

Wednesday, February 22, 2017

Excel 2016 64 bits - Slow marco




I have been suffering from "upgrading" Excel 2013 bits to Excel 2016 64 bits. There are some excel marco becoming painfully slow, says 8 -10 times slower, in Excel 2016 64 bits, compare with Excel 32 bits.

Microsoft tells me Excel 64 bits is a lot better than Excel 32 bits, in term of file size limit, memory management.... blah..blah...blah... In fact,  I don't see any so called "improvement" for a product developed almost 30 years ago. People are asking for a productive tool to get their job done and go back home on time. You cannot expect every car owner knows how a car works and able to fix it.

After pulling my hair off for days, I find that there are things have to be disabled before running a sizable marco for the "best performance". The reasons behind is something actually does not matter to people life. *Though... can be easily found on Google, some of them are just ridiculous.

Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.PrintCommunication = False
Application.EnableAutoComplete = False
Application.EnableLivePreview = False
Application.Cursor = xlWait             'When the mouse cursor pointed on a cell, the excel slows down


I am now going back home.

Sunday, February 5, 2017

SNES9X - Synchronize save state between Android and PC



Snes9X is one of the best Android SNES emulators ever made. It is free, no ads, highly customisable. It helps bringing back tons of good memories. The auto save in Android version is just making the emulator even better than the original snes.

Snes9X
Android: https://play.google.com/store/apps/details?id=com.explusalpha.Snes9xPlus&hl=en 
Windows: http://www.snes9x.com/

I wanted to play SNES on my PC at home and on my Android on the go. SNES9x EX no doubt deserves a 5 stars, but so far it does not support cloud save.

It is non-sense to play Chrono Trigger with a 5.5 inch phone screen at home. So I decided to hands on a bit. It took me some time to Google to find the way out. The investment is well paid-off.

The thing is going to be a bit techie, so grab a coffee if necessary.

Finding save files

By default, the save file is located same as the ROM folder in Android; and save file is located in the "Saves" folder in the SNES folder in Windows.

Windows > Emulation > Settings


The Android save files ends with an extension .0A.frz ~ .0J.frz and the Windows save file ends with an extension .000 ~ .009

Converting save files

The Windows save file and the Android save file are actually the same. The only difference is their filename extension. They can be converted simply by changing the filename extension.

i.e.

Windows
Chrono Trigger.000

Android
Chrono Trigger.0A.frz


Copy all the save files from Android to Windows. Find the newest save files by comparing their timestamp. Change the extension from .000 to .0A.frz or vice versa

I created a VB script to get rid of this repetitive boring job.


Save file converter: https://github.com/DavidTsangHW/SNES9X-save-file-converter 

Cloud storage

It is not cool keep copying those save files between my PC and my phone. I wanted a more sophisticated way of doing this. I need a cloud storage. There are free cloud storage i.e. One Drive, Google Drive and Dropbox to choose from, but only the official Dropbox Android client allows exporting files to a custom location (SNES saves folder). Dropbox is the best pick for this.

Download: https://www.dropbox.com/

Setup Dropbox Windows Client

After installing Dropbox client on Windows, move the Save folder in the Dropbox folder. All new saves will be saved to Dropbox automatically as well.

Install DropSync Android Client

The official Dropbox Android client allows you to upload and download save files from the cloud storage. Yet, this can only be done, each time, manually.


To skip this painful and meaningless task, there is a better deal. Dropsync is  a Android Dropbox Client which  synchronizes files between you phone and the cloud storage periodically (say 5, 10, 30 minutes). The free version supports only one folder synchronization only, but it is sufficient to get the job done.

Choose the save folder for the periodic synchronization. DropSync will upload and download the latest game saves to the cloud storage.

Voila!

Tuesday, January 3, 2017

How to teach kids loving-kindness meditation

http://greatergood.berkeley.edu/raising_happiness/post/better_than_sex_and_appropriate_for_kids

Monday, August 15, 2016

Posting a Facebook post by using python

1. Download get-pip.py 2. python get-pip.py 3. python\scripts\pip install virtualenv 4. python\scripts\pip install facebook-sdk

Monday, June 20, 2016

Transparent background with GIMP

One of the simplest way to transfer a solid filled background into transparent background. First thing first, download GIMP.

This is the source file, and I want to turn the white background into transparent.


Quickly go to Colors > Color to Alpha


Here is where is the magic happens 


voilà !!




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...