Log Returns of Stock Prices

59 views (last 30 days)
Gaurav Sharma on 26 Jan 2015
Answered: Roger Wohlwend on 26 Jan 2015
Hello,
I'm a total newbie and this is my first time using MATLAB, so please bear with me.
I have stock prices over a 20 year period with monthly frequency in Excel. I imported that in MATLAB.
After that, I've been trying to search through documentation/Google but I'm totally lost. I have a few questions (some of them may sound silly as the only statistical software I know is STATA):
1. Is there a need to specify that the imported data is a time series data?
If yes, this is what I found: ts = timeseries(data,'Name',name) where data is my column of prices, and name is the name I want to give to the Time Series. I presume I have to do this individually for the various stock prices I have?
2. I'm not sure if this is the proper command to generate log returns, but this is what I found: [RetSeries, RetIntervals] = tick2ret(TickSeries, TickTimes, Method)
where TickSeries is the name of time series column I created in Step 1, and TickTimes is specifying the first column with dates, and Method is Continous (Google search shows it calculates log returns).
When I try to run this command, I get "Undefined function or variable 'Continuous'."
I'm totally lost here. Thanks for anyone who takes the time to read this and reply. :)

Roger Wohlwend on 26 Jan 2015
You can keep things quite simple. Import your stock data, create two variables, one - let's call it D - that contains the dates, and one - let's call it Prices - that contains the stock prices. D is a column vector and X is a matrix. Then you can calculate the returns with the following command:
Returns = diff(log(X))
For a lot of applications that is enough. Sometimes, however, it is advisable to use a fints object. When working with financial data, use fints instead of timeseries. By the way in Matlab you cannot specify something as a time series. With the function timeseries you create an object timeseries