resample_returns#

API documentation for tradeexecutor.visual.equity_curve.resample_returns Python function.

resample_returns(returns, freq)[source]#

Resample returns series to a longer time frame.

  • Transform daily returns series to monthly and so on

  • The returns of each period is the cumulative product of the sub-returns

  • Does this with a cumulative product transformation

Example:

We have returns:

2021-06-01 00:00:00    0.000000
2021-06-01 08:00:00    0.000000
2021-06-01 16:00:00    0.000000
2021-06-02 00:00:00    0.000000
2021-06-02 08:00:00    0.000000
                         ...
2024-03-08 08:00:00   -0.002334
2024-03-08 16:00:00   -0.012170
2024-03-09 00:00:00   -0.003148
2024-03-09 08:00:00    0.010400
2024-03-09 16:00:00   -0.000277

Make it quarterly:

# Transform daily returns to monthly for easier comparison
freq = QuarterBegin()
resampled_returns = resample_returns(returns, freq)

Now it is:

2021-06-01    0.483777
2021-09-01    0.287191
2021-12-01    0.265714
2022-03-01   -0.035728
2022-06-01    0.194215
2022-09-01    0.059003
2022-12-01    0.062195
2023-03-01   -0.091300
Parameters:
Returns:

Returns series where the returns are binned by a new timeframe.

Return type:

Series