Convert monthly stock returns to quarterly returns using timetable - compound returns or interest rates
7 views (last 30 days)
Show older comments
Hello all,
I'm quite new to the usage of Matlab.
My problem is that I was given two datasets the one contains data quarterly while the other contains the data in a monthly interval.
The monthly data contains stock returns, so I have to calculate the quarterly data as a compounded return.
Since I haven't found a function to compound interest rates I have written one myself
function [b] =compound_returns(x)
a=1;
for j=1:length(x)
for i=1:length(x);
x_i=x(i)
a=(a*(1+x_i));
end
b=a-1;
end
The data was in two different excel files so I used the readtable feature to import the data
My code looks as follows:
oecd_cons = readtable('oecd_consumption_hd', 'ReadVariableNames', true, 'VariableNamingRule', 'preserve','Sheet','import');%Qaurterly data
date_oecd = datetime(table2array(oecd_cons(:,1)),'ConvertFrom','excel');
oecd_cons = oecd_cons(:,2:21);
oecd_cons = table2timetable(oecd_cons,'RowTimes',date_oecd);
oecd_cons =retime(oecd_cons, 'quarterly', @compound_returns); %I use this function only to match the dates for syncronisation
msci_usd = readtable ('msci_usd_hd', 'ReadVariableNames', true, 'VariableNamingRule', 'preserve','Sheet', 'import1'); % monthly data
date_msci = datetime(table2array(msci_usd(:,1)),'ConvertFrom','excel');
msci_usd = msci_usd(:,2:10);
msci_usd = table2timetable(msci_usd,'RowTimes',date_msci);
msci_usd =retime(msci_usd, 'quarterly', @compound_returns); %here is the line of code where my problem occurs
data = synchronize(oecd_cons, msci_usd);
The problem is now that the results of the compounded returns are too high, it seems to me that there is a calculation error somewhere in my compounding function.
I hope someone can help me with this problem or give me a simpler solution to my problem.
Best regards
Henrik
0 Comments
Answers (1)
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!