[R-SIG-Finance] Simple and fast date format conversion

Brian G. Peterson brian at braverock.com
Mon Aug 10 20:18:06 CEST 2009


Zanella Marco wrote:
> Gentleman,
> I have to convert a date to this format: nov 2009
>
> A) I've loaded a daily dataset of returns like this:
>   
>> ret[1,]
>>     
>         Date Ret
> 1 20090729  3.08
>
> B) Naturally, I've transformed Date with as.Date() and now I have:
>   
>> ret[1,]
>>     
>         Date Ret
> 1 2009-07-29 3.08
>
> Ok, now I want to analyse data also accorpated for months, and weeks, not only daily.
> I think the ways to do this can be various:
> 1) In A), where Date is simply a number, truncate the last two digits of Date (es. 200907). Then I can subset data for month thanks to new Date's format.
> 2) In B), after Date conversion to date format, proceed with a new format conversion (es. lug 2009)
>
> But, how I can do this with R? I tried with truncate() and strptime() but failed.
>   
You're working with returns, so you need to aggregate your returns.  You 
can't treat them like prices and simply grab the last price in your 
observation period.

Do you have a price (value) series available?  If not, convert it to a 
wealth index first.

With either price data or a wealth index, you can use to.period in xts 
to convert.  If you need returns for your analysis, the wealth index is 
fungible back to returns.

Further clarification would benefit from a sample data series.

Regards,

    - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list