Impact analysis - financial correlation matrices

조회 수: 1 (최근 30일)
Nadezhda Dimitrova
Nadezhda Dimitrova 2019년 2월 17일
댓글: Nadezhda Dimitrova 2019년 3월 8일
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
Nadezhda Dimitrova 2019년 3월 8일
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