projecting values to future dates

1 visualizzazione (ultimi 30 giorni)
antonet
antonet il 25 Giu 2012
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 Commenti
per isakson
per isakson il 25 Giu 2012
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.
antonet
antonet il 25 Giu 2012
thanks. I will follow your guidelines and get back to you for advice, albeit I am trying 3 weeks with no success.
Thank you again

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Time Series Objects in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by