I have data of stock daily returns but I just use data of 21 days before the last trading day of a month. I already have a logical matrix of whether a date is a last trading date of a month but I dont know how to create a matrix of returns of only 21 days before it. Please help me.

 採用された回答

Image Analyst
Image Analyst 2015 年 4 月 5 日

0 投票

Let's say you have a logical vector, logicalLastDaysVector, of when a day is the last day of the month. Then just extract going back to 1 more than the last day of the prior month:
lastDayIndexes = find(logicalLastDaysVector);
for k = 2 : length(lastDayIndexes)
% Get the index of the first day of the month.
firstDay = lastDayIndexes(k-1) + 1;
% Get the index of the last day of the month
lastDay = lastDayIndexes(k);
% Extract all the days from first to last, inclusive.
thisMonth = stockReturns(firstDay:lastDay);
% Now do something with this data.....
end

1 件のコメント

Ha Hoang
Ha Hoang 2015 年 4 月 6 日
thank you so much for your comment.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFinancial Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by