projecting values to future dates
1 回表示 (過去 30 日間)
古いコメントを表示
Dear all,
I have the following sequence of dates
Dates=['02/11/08'
'30/11/08'
'28/12/08'
'25/01/09'
'22/02/09'
'22/03/09'];
The prices corresponding to these dates are given by the following cell vector
values =[
[8.0486]
[8.4678]
[8.1981]
[8.1123]
[7.9911]
[8.1159]]
Each price represents a 4-week average. For instance, the first price is 8.0486. This price is not the price recorded at the date '02/11/08' but the average of the prices in the previous 4 weeks before the '02/11/08' date.
I want to interpolate each of these prices to all the dates that are included in the time interval that starts from the date immediately following the reported dates in the “dates” vector up to the end date of the corresponding month.
To be more precise, the end dates corresponding to the “dates “ vector are given by
Datesend=['30/11/08'
'30/11/08'
'31/12/08'
'31/01/09'
'28/02/09'
'31/03/09'];
So, I want to interpolate the first value 8.0486 to the dates that are included in the time-interval [‘3/11/08' - '30/11/08']
For the second value, 8.4678, no interpolation is needed as the reported date coincides with the end date of that month.
For the third value, 8.1981, I want to interpolate it to the dates that are included in the time-interval ['29/12/08'-'31/12/08'] and so forth.
My question is whether I could use the interp1() function as follows
Prices2 = interp1(datenum(Dates), values, datenum(Datesend) , 'linear')
The problem is by applying this function I obtain
NaN
NaN
NaN
NaN
NaN
NaN
So, my questions are
1) Could I use the interp1() when I use this frequency of data (4-week average prices)? Clearly the dates at which I want to interpolate the value 7.9911 are included in the interval ['23/02/09'- '28/02/09'] . But the prices recorded on the dates of this interval were also used for calculating the next value 8.1159. So there is this overlapping
2) Is there any other approach that you be used so as to notify Matlab that my sequence of dates has these peculiarities?
Thanks a lot
8 件のコメント
per isakson
2012 年 6 月 25 日
Proposal:
1. Write a simple requirement specification. Do some exercises with paper and pencil to decide which factors you need to account for. Maybe you will find that interp1 is good enough.
2. Make the simplest code that solves the problem. I guess it is appropriate to loop over all days in the target month and accumulate data conditioned by weekday, etc. A loop is easy to grasp.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Financial Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!