I am trying to work through code from a book on Quantitative trading I am reading. The problem is that the code from the book is old and in some cases out of date.
I tried to re-create the code in R2020b however my result is not right according to the expected out put
my result - 8.3184
the expected result - 0.7618
Edit - I now know that my error is with this line
Its suppose to match sort cls by the date column but instead it orders cls in ascending order. What is the way to create this association correctly?
Your help is must appreciated. (Spreadsheet attached)
Here is the OLD code from the book
clear;
[num, txt]=xlsread('IGE');
tday=txt(2:end, 1);
tday=datestr(datenum(tday, 'mm/dd/yyyy'), 'yyyymmdd');
tday=str2double(cellstr(tday));
cls=num(:, end);
[tday sortIndex]=sort(tday, 'ascend');
cls=cls(sortIndex);
dailyret=(cls(2:end)-cls(1:end-1))./cls(1:end-1);
excessRet=dailyret - 0.04/252;
sharpeRatio=sqrt(252)*mean(excessRet)/std(excessRet)
Here is my code.
T = readtable("IGEv3.xlsx");
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the
VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
tday=T{2:end, 1};
tday.Format = 'yyyy-MMM-dd';
cls=T(:, end);
[tday, sortIndex] = sort(tday, 'ascend');
cls = sortrows(cls, 1);
dailyret=(cls{2:end, :}-cls{1:end-1, :})./cls{1:end-1, :};
excessRet = dailyret - 0.04/252;
sharpeRatio = sqrt(252)*mean(excessRet)/std(excessRet)
sharpeRatio =
8.3184
0 Comments
Sign in to comment.