On Thu, 05 Sep 2024, Brian G. Peterson via R-SIG-Finance writes:

> the 'returns' package has just turned them into whole numbers rather
> than decimals.  The numbers all agree.

Thank you, Brian.  Indeed, I do hope that the numbers
are the same ;-)

Amarjit, it's just that PMwR::returns _prints_ the
returns as percentages.  To give an example:

    library("quantmod")
    S <- getSymbols("SPY", src = "yahoo",
                    from = as.Date("2020-01-01"),
                    return.class = "zoo",
                    periodicity = "daily", 
                    auto.assign = FALSE)[, 6]
    
    library("PMwR")
    returns(S, period = "month")
    ##       Jan  Feb   Mar  Apr May  Jun Jul  Aug  Sep  Oct  Nov  Dec   YTD
    ## 2020 -1.0 -7.9 -12.5 12.7 4.8  1.8 5.9  7.0 -3.7 -2.5 10.9  3.7  17.2
    ## 2021 -1.0  2.8   4.5  5.3 0.7  2.2 2.4  3.0 -4.7  7.0 -0.8  4.6  28.7
    ## 2022 -5.3 -3.0   3.8 -8.8 0.2 -8.2 9.2 -4.1 -9.2  8.1  5.6 -5.8 -18.2
    ## 2023  6.3 -2.5   3.7  1.6 0.5  6.5 3.3 -1.6 -4.7 -2.2  9.1  4.6  26.2
    ## 2024  1.6  5.2   3.3 -4.0 5.1  3.5 1.2  2.3 -2.3                 16.6

To see the raw numbers, a convenient way is to use
'as.matrix', which drops the class and leaves a numeric
matrix (with options(digits = 3)):

    as.matrix(returns(S, period = "month"))
        ##         1       2       3       4       5       6
    ## 2020 -0.00967 -0.0792 -0.1249  0.1270 0.04765  0.0177
    ## 2021 -0.01019  0.0278  0.0454  0.0529 0.00657  0.0224
    ## 2022 -0.05274 -0.0295  0.0376 -0.0878 0.00226 -0.0825
    ## 2023  0.06289 -0.0251  0.0371  0.0160 0.00462  0.0648
    ## 2024  0.01593  0.0522  0.0327 -0.0403 0.05058  0.0353
    ##           7       8       9      10       11      12    YTD
    ## 2020 0.0589  0.0698 -0.0374 -0.0249  0.10878  0.0370  0.172
    ## 2021 0.0244  0.0298 -0.0466  0.0702 -0.00803  0.0462  0.287
    ## 2022 0.0921 -0.0408 -0.0924  0.0813  0.05559 -0.0576 -0.182
    ## 2023 0.0327 -0.0163 -0.0474 -0.0217  0.09134  0.0457  0.262
    ## 2024 0.0121  0.0234 -0.0226      NA       NA      NA  0.166



kind regards
    Enrico

>On Thu, 2024-09-05 at 12:35 +0100, Amarjit Chandhial via R-SIG-Finance
>wrote:
>> 
>>  
>> Thanks Enrico!
>>  
>> If try on SPY for the year 2023 
>>  
>>  > calendarReturnTable(spyRets, digits = 4, percent = FALSE)
>> Using 'Value' as value column. Use 'value.var' to override
>>      Jan     Feb     Mar     Apr     May     Jun     Jul     Aug    
>> Sep 
>> Oct     Nov     Dec  Annual
>>   0.0674 -0.0251  0.0371  0.0160  0.0046  0.0648  0.0327 -0.0163 -
>> 0.0474 
>> -0.0217  0.0913  0.0457  0.2671
>>       DD
>>   0.0997  
>>  > PMwR::returns(SPY, period = &quot;month&quot;)
>>       Jan  Feb Mar Apr May Jun Jul  Aug  Sep  Oct Nov Dec  YTD
>> 2023 6.7 -2.5 3.7 1.6 0.5 6.5 3.3 -1.6 -4.7 -2.2 9.1 4.6 26.7  > 
>> PerformanceAnalytics::table.AnnualizedReturns(spyRets, scale = 249, 
>> geometric = TRUE)
>>                            Adjusted
>> Annualized Return           0.2671
>> Annualized Std Dev          0.1301
>> Annualized Sharpe (Rf=0%)   2.0525
>>  > PerformanceAnalytics::maxDrawdown(spyRets)
>> [1] 0.09974311 
>>  
>>  
>> Amarjit
>>  
>>  
>>  
>> ------ Original Message ------
>> From: e...@enricoschumann.net
>> To: a.chandh...@btinternet.com Cc: r-sig-finance@r-project.org
>> Sent: Thursday, September 5th 2024, 10:10
>> Subject: Re: [R-SIG-Finance]
>> PerformanceAnalytics::table.CalendarReturns
>> On Wed, 04 Sep 2024, Amarjit Chandhial via R-SIG-Finance writes: >
>> Hi, > 
>>   > Are there any plans for > 
>> https://timelyportfolio.github.io/PerformanceAnalytics/reference/table.CalendarReturns.html
>>  
>> > function to handle daily returns aggregated to monthly and year? >
>> >   > 
>> It would be useful to have a table displaying Monthly Returns and
>> Total 
>> > Return (rows), by year's (columns), for daily returns. >   >
>> > Amarjit > 
>> If an alternative package be acceptable as well, then function
>> 'returns' 
>> in PMwR (which I maintain) might do what you want: returns(, period =
>> &quot;month&quot;) in which series is a zoo (or xts) series. It is 
>> described in the manual: 
>> https://enricoschumann.net/R/packages/PMwR/manual/PMwR.html#holding-period-returns
>>  
>> -- Enrico Schumann Lucerne, Switzerland https://enricoschumann.net
>> 
>>         [[alternative HTML version deleted]]


-- 
Enrico Schumann
Lucerne, Switzerland
https://enricoschumann.net

_______________________________________________
R-SIG-Finance@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.

Reply via email to