Impact analysis - financial correlation matrices
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone,
I am quite new with Matlab so please bare with me. I am doind an impact analysis for financial correlation matrices and I cannot ger the code right. Could you please take a look and advise?
The basic idea is that the accuracy of the financial matrices will vary with the training period used in the estimation. Therefore, I will work with different lengts of the training period in order to minimise the error to the correlation matrix of the investment perios (test period). The data I am using is the S&P 500 stock prices. Here is the basic code:
>> P = COPY;
R = price2ret(P);
lengthInvestmentPeriod = 5*size(R,2);
InvestmentPeriodReturns = R(end - lengthInvestmentPeriod:end,:);
OracleInvestmentPeriodCorrelationMatrix = corr(InvestmentPeriodReturns);
TrainingPeriodReturns = R(1:end - lengthInvestmentPeriod - 1,:);
>> for i = size(TrainingPeriodReturns,2):size(TrainingPeriodReturns,1)
tempReturns = TrainingPeriodReturns(1:I,:); % I chose I=1.5 but I am not sure what the range can be
tempCorrelation(:,:,i) = corr(tempReturns);
end
>>
>> for i = 1:size(tempCorrelation,3)
Error(i) = sum(sum(abs(tempCorrelation(:,:,i)-OracleInvestmentPeriodCorrelationMatrix)));
end
>> plot(Error);
Undefined function or variable 'tempCorrelation'.
So in the end I get the above error message and I am not sure why the variable tempCorrelation is not identified.
Could you please advise?
Thank you in advance!
Nadya
4 Kommentare
David Goodmanson
am 2 Mär. 2019
Hi Nadezhda
randperm(n) supplies a random permutation of the integers 1:n. So, e.g.
a = randperm(100);
b = a(1:20);
gives 20 items randomly chosen from 100 items.
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!