Impact analysis - financial correlation matrices

2 次查看(过去 30 天)
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 个评论
David Goodmanson
David Goodmanson 2019-3-2
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
Hi David,
Perfect, thank you very much! It is a great idea and Ive used it in my algorithm :)
I have another problem with the code now but will post another question.
Many thanks again!
Nadya

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by