1

Sorry am new to Pandas. Can I check how do I use Pandas to get the annualized mean returns. (Note: NOT the Annualized returns) I will like to calculate for the entire dataframe

Mean of the returns: m = (1/M * Σ)

M is the number of number of observations (1 date = 1 observation), r is the daily returns

Annualized daily mean returns = (1+m)^365 -1

I've already calculated the daily returns by using .pctchange

This is the returns

So to give you guys an example, skipping the first column with NaN.

From the second column assuming i made an observation from the 26th to 30th , therefore the calculation is:

m = (1/3 * (0.007246+0.001199+0.006587))= 0.00501

Annualized daily mean returns = (1+0.00501)^365 -1

The formula is above

Sorry for my poor english.

Thanks :)

Jonathan
  • 424
  • 4
  • 14

1 Answers1

2

It can be useful to you. Assign datetime index, apply groupby function over year and calculate mean :-) Groupby index

Considered sample DataFrame

              TP    MENU    SLY     CZA
Time                
2016-01-31  1.01    -0.33   -0.60   0.0
2016-01-30  0.32    0.06    0.16    0.0
2017-01-29  -1.19   -0.10   0.34    0.0
2017-01-28  -0.31   0.62    -0.20   0.0
2017-01-27  0.39    0.03    -0.43   0.0
2017-01-26  1.21    -0.54   -0.21   0.0
2018-07-25  -0.39   0.67    -0.11   0.0
2018-07-24  -0.27   0.00    0.11    0.0

Code snippet

df.index = pd.to_datetime(df.index)
df.groupby([df.index.year]).mean()

Output Annualised mean

          TP     MENU    SLY    CZA
2016    0.665   -0.1350 -0.220  0.0
2017    0.025   0.0025  -0.125  0.0
2018    -0.330  0.3350  0.000   0.0
Naga kiran
  • 4,528
  • 1
  • 17
  • 31