projecting values to future dates

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 Comments

change datenum( Dates ) to datenum( Dates, 'dd/mm/yy' ) to
thank you isakon. NOw it is fine. I would like to ask, though, if this approach
that is,
Prices2 = interp1(datenum(Dates), values, datenum(Datesend) , 'linear')
is the appropriate to answer question 1.
thanks
I read that you have 4-week averages and want monthly averages, Price2. How good an estimate Price2 is depends on the properties of the price signal, e.g. day to day variations, volumes, week-ends, ...
thank you for your answer. Do you have to propose any other approach so as to obtain montly averages from 4-week averages ? thanks again
I guess there are 4-week periods in the first place to have the same number of weekends in each period. Do you think weekends (/number of trading days) are important?
A monthly value can be calculated as an weighted average of two 4-week-values with the weight being the actual number of days (/trading days) of each period, which the fall in the month in question.
However, interp1 might be just fine. That depends on your requirements.
Thank you isakson.
could you possible provide some code? I am trying to find a solution but can't. Any help is greatly appreciated
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.
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

Sign in to comment.

Answers (0)

Categories

Tags

Asked:

on 25 Jun 2012

Community Treasure Hunt

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

Start Hunting!