You are on page 1of 4

Quantitative Finance Stack Exchange sign up log in

Questions Tags Users Badges Ask

4 Learn backtesting using MATLAB


quant-trading-strategies backtesting research matlab quantitative

What are some good ressources (books, articles, ...) to learn backtesting of investment strategies using
MATLAB ?

It can be strategies related to fixed-income, equities, derivatives, ... whatever. The process of backtesting is
more important than the actual strategy.
Thank you.

Maxime.

share improve this question

Maxime asked
209 ● 2 ● 8 Dec 30 '14 at 20:54

1 While I like where this question is going, I would suggest to make it a little more concrete. What parts of the backtesting
process would you like to learn? This can range anywhere from only estimating a normal return, where the portfolio
returns from your strategy are already given; to implementing a full portfolio formation rule algorithmically. – Constantin
Dec 30 '14 at 21:06

To be honest I don't know much about backtesting. I was told that I will have to backtest new strategies or improve
current one during my internship. So I would like to know a bit more about the subject before starting. What are the
different parts of it ? –  Maxime Dec 30 '14 at 21:31

How comfortable are you in Matlab? – Constantin Dec 30 '14 at 21:32

Just started matlab a few weeks ago. Already read some doc about it but mostly regarding the pricing of derivatives. –
  Maxime Dec 30 '14 at 21:41

add a comment

1 Answer order by votes

4
The general idea
For equity securities, a simple backtest will typically consist of two steps:

1. Computation of the portfolio return resulting from your portfolio formation rule (or trading
strategy)
2. Risk-adjustment of portfolio returns using an asset pricing model
Step 2 is simply a regression and computationally very simple in Matlab. What's trickier is the
implementation of step 1, which will require you to be very comfortable in Matlab, and there are
different ways to do this.
If you know how to do an OLS regression in Matlab, what you should focus on is all kinds of matrix
manipulations.

Implementation in Matlab
Portfolio formation and returns computation
To give you an example of how a primitive trading strategy could be implemented in Matlab, let's
assume monthly return data and a uniform holding period of one month on n assets over k periods,
where i ∈ {1, . . . , n}
and k ∈ {1, . . . ,. t}

Assuming no changes in the composition of your stock universe, your returns matrix X is of
dimensions k × n
.

x11 … x1i … x1n

⋮ ⋱ ⋮ ⋱ ⋮

X = xt1 … xti … xtn

⋮ ⋱ ⋮ ⋱ ⋮

xk1 … xki … xkn

pt+1,i
Where returns are computed as xit =
pti
.
− 1

Assuming that your selection criterion is some kind of stock characteristic which is available at
monthly frequency, you will also have a characteristics matrix C.
You then could write an algorithm which identifies those entries in C which fulfill your selection
criterion (e.g. exceed a certain threshold) and replace the corresponding entries (where i and t are
the same) of an indicator matrix I (which has been initialized as a zero matrix using the zeros
function) with ones.
You can then multiply the entries of I by those of the returns matrix X to obtain a matrix Rwhich
indicates the returns resulting from your holdings. You can then compute the mean of the non-zero
entries for each row of Rto obtain your vector of portfolio returns.

Risk-adjustment and identification of abnormal returns


In step 2 you compare this vector to the normal returns obtained from regression estimation of an
asset pricing model such as the Fama-French model. By subtracting the normal return vector from
your portfolio returns vector, you determine whether your trading strategy has resulted in a positive
abnormal return, which is what you're aiming for.

Recommendations
If you are new to Matlab, I personally suggest you familiarize yourself with it sufficiently to
implement this simplistic strategy before relaxing some of the simplifying assumptions (such as
uniform holding period and periodicity) and proceeding to more sophisticated implementations.
Again, what I would like to stress is that this requires you to be very comfortable with Matlab and
especially the different ways to manipulate matrices, which can take some time. If you are not
required to use Matlab for your internship and would like to get results fast, you could do step 1 in
Excel instead, which is tedious, but doesn't require the (worthwhile) initial investment you need to
make for Matlab.
To become familiar with Matlab, I am sure you have already discovered the extremely good
documentation that comes with it. That, to me, is the single most valuable resource and likely more
useful than any more finance-specific resources (with which I would wait until you are familiar with
Matlab itself). All that's required to determine the normal return is an OLS regression and a
rudimentary understanding of asset pricing models.

share improve this answer

Constantin answered
337 ● 1 ● 2 ● 14 Dec 30 '14 at 22:20

edited
Dec 31 '14 at 0:10

Your Answer

Body

Add picture

Log in

OR

Name

Email

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Post Your Answer


meta chat tour help blog privacy policy legal contact us full site

Download the Stack Exchange Android app


2019 Stack Exchange, Inc

You might also like