[R-SIG-Finance] Difficulty getting desired returns with returns(fSeries) function

Jeff Ryan jeff.a.ryan at gmail.com
Fri Sep 5 16:31:51 CEST 2008


Try:

library(quantmod)

my.ts <- timeSeries(c(rep(NA,10),6500,8100,8010,7930),
as.Date('1970-01-01')+0:13)

Delt(my.ts)
           Delt.1.arithmetic
1970-01-01                NA
1970-01-02                NA
1970-01-03                NA
1970-01-04                NA
1970-01-05                NA
1970-01-06                NA
1970-01-07                NA
1970-01-08                NA
1970-01-09                NA
1970-01-10                NA
1970-01-11                NA
1970-01-12       0.246153846
1970-01-13      -0.011111111
1970-01-14      -0.009987516

What you are getting, as Adam points out, is log returns.

> Delt(my.ts, type='log')
            Delt.1.log
1970-01-01          NA
1970-01-02          NA
1970-01-03          NA
1970-01-04          NA
1970-01-05          NA
1970-01-06          NA
1970-01-07          NA
1970-01-08          NA
1970-01-09          NA
1970-01-10          NA
1970-01-11          NA
1970-01-12  0.22006188
1970-01-13 -0.01117330
1970-01-14 -0.01003773

The xts library also has a family of functions to calculate period
returns (and much more).

?periodReturn

HTH
Jeff
On Fri, Sep 5, 2008 at 3:14 AM, Weiyang Lim <Weiyang.Lim at henderson.com> wrote:
> Dear users,
>
> I tried to use the getReturns/returns function available with the fSeries package but it did not appear to give me the results generated by the same function in S-Plus finmetrics. I am not sure what is happening or what goes behind the calculations.
>
> I have the code
>
> my.ts <- timeSeries(data = DataSeries) which generates the time series
>
>                        37
> 1970-01-01        NA
> 1970-01-02        NA
> 1970-01-03        NA
> 1970-01-04        NA
> 1970-01-05        NA
> 1970-01-06        NA
> 1970-01-07        NA
> 1970-01-08        NA
> 1970-01-09        NA
> 1970-01-10        NA
> 1970-01-11        6500
> 1970-01-12        8100
> 1970-01-13        8010
> 1970-01-14        7930
> .                       .
> .                       .
> .                       .
> .                       .
> .                       .
>
> Then I used
>
> dummystock.rs <- getReturns(my.ts, type = "discrete", na.rm = F, trim = F, percentage = T) which generates the returns
>
>                        37
> 1970-01-01        NA
> 1970-01-02        NA
> 1970-01-03        NA
> 1970-01-04        NA
> 1970-01-05        NA
> 1970-01-06        NA
> 1970-01-07        NA
> 1970-01-08        NA
> 1970-01-09        NA
> 1970-01-10        NA
> 1970-01-11        NA
> 1970-01-12        22.0061885
> 1970-01-13        -1.1173301
> 1970-01-14        -1.0037725
> .                       .
> .                       .
> .                       .
> .                       .
>
> However, what I really want is 24.61, -1.111, and -0.99 respectively rather than the returns above. The calculation I wanted for returns was (8100-6500)/6500 * 100 (for the first return) = 24.61 rather than 22.0061885.
>
> I am using R version 2.7.0.
>
> I wonder if anyone can give me any kind advice as to how to achieve the returns I hope to have.
>
> Many thanks.
>
> Best Regards,
> Wy
>
>
>
>
>
> **********************************************************
>
> The information provided in this e-mail is confidential and is for the sole use of the recipient. It may not be disclosed, copied or distributed in any form without the express permission of Henderson Global Investors and to the extent that it is passed on, care must be taken to ensure that this is in a form which accurately reflects the information presented here.
>
> Whilst Henderson Global Investors believe that the information is correct at the date of this e-mail, no warranty or representation is given to this effect and no responsibility can be accepted by Henderson Global Investors to any end users for any action taken on the basis of this information.
>
> Henderson Global Investors is the name under which Henderson Global Investors Limited (registered no. 906355), Henderson Fund Management plc (registered no. 2607112), Henderson Investment Funds Limited (registered no. 2678531), Henderson Investment Management Limited (registered no. 1795354) Henderson Alternative Investment Advisor Limited (registered no. 962757) and Henderson Equity Partners Limited (registered no.2606646) (each incorporated and registered in England and Wales with registered office at 4 Broadgate, London EC2M 2DA and authorised and regulated by the Financial Services Authority) provide investment products and services.  Henderson Secretarial Services Limited (incorporated and registered in England and Wales, registered no. 1471624, registered office 4 Broadgate, London EC2M 2DA) is the name under which company secretarial services are provided. All these companies are wholly owned subsidiaries of Henderson Group plc (incorporated and registered in England !
>  and Wales, registered no. 2072534, registered office 4 Broadgate, London EC2M 2DA).
>
> We may record telephone calls or email for our mutual protection and to improve customer service.
>
> **********************************************************
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list