Code covered by the BSD License  

Highlights from
Trading strategy back tester

5.0
5.0 | 3 ratings Rate this file 60 Downloads (last 30 days) File Size: 5.5 MB File ID: #30693
image thumbnail

Trading strategy back tester

by

Donny Lee (view profile)

 

09 Mar 2011 (Updated )

This program shows the profit and lost of using different trading strategies on Singapore stocks.

| Watch this File

File Information
Description

Directions to run the file.

1. Unzip the file "TradingStrat.zip" so that you'll get the folder "TradingStrat".
2. Set your working directory as "TradingStrat > CSV" (The CSV folder holds the comma separated values data which is required to use the back tester)
3. Run the file 'runCSV.mat' by typing runCSV at the Matlab prompt.
4. A new window will open. In the 'Input:' window, select the stock you want to backtest.
5. Click on 'Execute'. At the main Matlab prompt, you should see a percentage progress from 0% to 100%.
6. Once done, another window will open for you to select the time frame of data to back test. Click on 'Execute' again.
7. A main window opens showcasing the candlestick data of the stock and various indicators with buy and sell signals as according to the strategy implemented. Look at the Readme file for a description of the strategies used.
8. You are free to change the parameters of each individual strategy. The profit and loss will be changed accordingly.

Strategies used:
1. Simple and Exponential Moving Average Crossover.
2. Stochastic Oscillator.
3. Bollinger Band.
4. MACD Divergence.
5. RSI Strategy.

Stocks in the backtester:
DBS Bank (DBS), Genting (GENS), Kim Eng (KEH), Kep Corp (KEP), Osim (OSIM), Raffles Education Group (RLS), Singapore Airlines (SIA), Singapore Press Holdings (SPH), Singapore Technologies Engineering (STE), Starhub (STH), United Overseas Bank (UOB), UOL Group (UOL), Wilmar (WIL).

MATLAB release MATLAB 7.9 (R2009b)
Other requirements Made with computer screen at resolution 1440 x 900.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
05 Feb 2015 Satyajit Harjan

Good guidance

10 Dec 2013 QiFan Wu  
09 Jun 2012 hussen

hussen (view profile)

Hi,

I am applying filter and moving average trading rules using matlab to some stock prices. I could not get results from them and every time it shows that there sre some mistakes. I trying to deretmine buying and selling single but no results. can i find these rules already programmed some where.

Thanks

Comment only
17 Mar 2012 Justinas Barauskas

what do i need to change in the convert function so that the data imports correctly?

i have EURUSD data which has time in the separate column and different data separations...

2007.03.30 17:04 1.3376 1.3377 1.3375 1.3376 57
2007.03.30 17:05 1.33755 1.3376 1.3374 1.3375 65

where as dbs data looks like this:
02/11/2010 09:00 14.22 14.22 14.2 14.2 4000 56860

Comment only
17 Mar 2012 Justinas Barauskas

DBS data is something like this:

02/11/2010 09:00 14.22 14.22 14.2 14.2 4000 56860

Comment only
13 Jan 2012 Vova

Vova (view profile)

11

Comment only
16 Mar 2011 Philip

Philip (view profile)

Hello Donny,
I found your program and tested it out.

Initially I had a problem with readdata when I clicked on execute after selecting an input CSV file on the first screen. Matlab returned the following error:

??? Undefined function or method 'readdata' for input arguments of type
'char'.

Error in ==> CSVconvert>execute at 126
[TheData TheName] = readdata(tempname);

??? Error while evaluating uicontrol Callback

As a work around, I copied the contents of TradingStrat into the CSV folder. This seemed to work.

Then, while using your STE.csv file:

I found that if I removed all data after 6/11/10 15:32, The data range is incorrectly displayed as 2/11/10 to 6/10/10.
If I add anymore data points from 6/11/10 after 15:32, the range is fine.
I found that if I removed all data after 6/10/10 15:36, The data range is incorrectly displayed as 2/11/10 to 0/69/10
(which I assume is a formatting error combined with the incorrect date). If I add anymore data points from 6/10/10 after 15:36, the range is fine.
I found that if I removed all data after 6/09/10 15:35, The data range is incorrectly displayed as 2/11/10 to 0/68/10.
If I add anymore data points from 6/09/10 after 15:35, the range is fine (although there is still the formatting error of 0/69/10).

In conclusion, it seems as though the correct day is not registered until some time after 15:30pm. Any ideas?

I have been using matlab for one day so unfortunately I do not have the knowledge to fix these errors! Any input you could provide would be greatly appreciated.
Thanks again for posting this program.

Comment only
16 Mar 2011 Robbie Castelijn

I am getting errors trying to Input a .csv file after executing runCSV at the prompt.

Error in ==> CSVconvert>execute at 124
tempname = thelist(value,:);

Comment only
11 Mar 2011 Donny Lee

Donny Lee (view profile)

Hello Michael,

Thanks for your interest in my Matlab program.

PnL is based on buying one stock at its closing price when there is a buy signal and selling it at its closing price when there is a sell signal ONLY FOR EACH buy-sell pair. For the cases when there is a buy signal but no sell signal after, no stock is bought. It is in dollars and cents of one stock, not one lot.

Commission, MAR, etc. is not taken into consideration.

Regarding your comment on Matlab users, to my knowledge, I believe Matlab has more popularity compared to the other math based programs due to its simplicity. If Matlab users are rare, then I would only assume Java and C++ users that create such algorithmic backtesters are even more rare.

Comment only
10 Mar 2011 Michael Teo

Hi, its seem that you are from Singapore, btw its difficult to find matlab-ers over here.

I'm doing similar stuff as what yr application does, back-testing and walk-forward optimization trading strategies using matlab.

May i ask what is the PnL based on, dollar & cents? Do you take into consideration of commission, MAR (min acceptable rate of return), etc. to compute the performance of a strategy?

Updates
30 Mar 2011

Change title from "Algorithmic Trading strategy back tester" to "Trading strategy back tester"

Contact us