Skip to content
Prev 15162 / 15274 Next

PerformanceAnalytics::table.CalendarReturns

On Thu, 05 Sep 2024, Brian G. Peterson via R-SIG-Finance writes:
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

  
    
Message-ID: <87cyli9nxn.fsf@enricoschumann.net>
In-Reply-To: <d48298811461a55d044809d7778734ee9eb9191a.camel@braverock.com> (Brian G. Peterson via's message of "Thu, 05 Sep 2024 07:44:52 -0500")