ENH: Add parameter agg= to lib.resample_apply()

This commit is contained in:
Kernc
2020-01-17 02:08:19 +01:00
parent 3da6d36927
commit efe516791a

View File

@@ -133,7 +133,9 @@ def quantile(series, quantile=None):
def resample_apply(rule: str,
func: Callable,
series,
*args, **kwargs):
*args,
agg='last',
**kwargs):
"""
Apply `func` (such as an indicator) to `series`, resampled to
a time frame specified by `rule`. When called from inside
@@ -155,6 +157,10 @@ def resample_apply(rule: str,
resampling limitations, this only works when input series
has a datetime index.
`agg` is the aggregation function to use on resampled groups of data.
Default value is `"last"`, which may be suitable for closing prices,
but you might prefer another (e.g. 'max' for peaks, or similar).
Finally, any `*args` and `**kwargs` that are not already eaten by
implicit `backtesting.backtesting.Strategy.I` call
are passed to `func`.
@@ -203,7 +209,7 @@ def resample_apply(rule: str,
'or a `Strategy.data.*` array'
series = series.to_series()
resampled = series.resample(rule, label='right').agg('last').dropna()
resampled = series.resample(rule, label='right').agg(agg).dropna()
resampled.name = _as_str(series) + '[' + rule + ']'
# Check first few stack frames if we are being called from