[R-SIG-Finance] Performance Analytics Calendar Returns

pie trader pietrader at gmail.com
Wed Sep 5 20:12:33 CEST 2012


Hi Nikos,
See if following helps...(note: you need to install chron package).

> df
                 Profit
2011-11-04  0.009513150
2011-12-23 -0.050548660
2012-01-27  0.031123389
2012-02-03  0.010962336
2012-03-16  0.000681096
2012-04-06  0.023744912
2012-04-13 -0.018906776
2012-05-11 -0.004662004
2012-08-17  0.020979889
2012-08-24  0.017647059
> dts = index(df)
> mdts = cut(dts, "months")
> mdts
 [1] 2011-11-01 2011-12-01 2012-01-01 2012-02-01 2012-03-01 2012-04-01
2012-04-01 2012-05-01 2012-08-01
[10] 2012-08-01
10 Levels: 2011-11-01 2011-12-01 2012-01-01 2012-02-01 2012-03-01
2012-04-01 2012-05-01 ... 2012-08-01
> mdts = as.Date(cut(dts, "months"))
> mdts
 [1] "2011-11-01" "2011-12-01" "2012-01-01" "2012-02-01" "2012-03-01"
"2012-04-01" "2012-04-01"
 [8] "2012-05-01" "2012-08-01" "2012-08-01"
> index(df) = mdts
> df
                 Profit
2011-11-01  0.009513150
2011-12-01 -0.050548660
2012-01-01  0.031123389
2012-02-01  0.010962336
2012-03-01  0.000681096
2012-04-01  0.023744912
2012-04-01 -0.018906776
2012-05-01 -0.004662004
2012-08-01  0.020979889
2012-08-01  0.017647059
> aggregate(df, by=index(df))

2011-11-01  0.009513150
2011-12-01 -0.050548660
2012-01-01  0.031123389
2012-02-01  0.010962336
2012-03-01  0.000681096
2012-04-01  0.004838136
2012-05-01 -0.004662004
2012-08-01  0.038626948

Regards
PieT

On Tue, Sep 4, 2012 at 10:21 PM, Nikos Rachmanis
<nikos.rachmanis at gmail.com> wrote:
> hi Krishna,
>
> thank you for the reply. i believe the solution you suggested would work
> well for a price based timeseries.
>
> However, I am trying to transform the daily returns of my P&L (which also
> include gaps) to monthly and unfortunately the to.monthly does not work
> very well.
>
> i am currently trying table.TrailingPeriods and rollapply.
>
> Any other ideas or functions?
>
> Thank
>
> On Tue, Sep 4, 2012 at 7:39 AM, Kris <kk2250 at optonline.net> wrote:
>
>>
>> >
>> > I am trying to use the table.CalendarReturns from the Performance
>> Analytics
>> > package with daily returns.
>> >
>>
>> Last I checked the help/usage file states that it expects monthly return
>> data. There are some zOo and xts functions that do this..
>>
>> ?to.monthly
>>
>> ?table.Annualizedreturns
>>
>> Cheers
>> Krishna
>>
>>
>> >
>> t(table.CalendarReturns(tradedata$daily.pnl.norm["1998/2012"],as.perc=TRUE,digits=4,geometric=TRUE))
>> >
>> > 1) is there anything wrong with my command? if not, is there any way to
>> > transform the daily results to monthly?
>> >
>> > 2) is there a function that would give me the same table for volatility
>> and
>> > sharpe?
>> >
>> > Thank you all in advance,
>> >
>> > Nikos
>> >
>> >    [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-SIG-Finance at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> > -- Subscriber-posting only. If you want to post, subscribe first.
>> > -- Also note that this is not the r-help list where general R questions
>> should go.
>>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list