Impact analysis - financial correlation matrices
Afficher commentaires plus anciens
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 commentaires
David Goodmanson
le 17 Fév 2019
Hi Nadya,
I'm guessing that
size(TrainingPeriodReturns,2) > size(TrainingPeriodReturns,1)
so the loop that defines tempCorrelation(:,:,i) never gets run at all. Just a guess.
The best thing you can do is get familar with the debug option which is a highly valuable tool.
Nadezhda Dimitrova
le 1 Mar 2019
David Goodmanson
le 2 Mar 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.
Nadezhda Dimitrova
le 8 Mar 2019
Réponses (0)
Catégories
En savoir plus sur Correlation and Convolution dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!