mirror of
https://github.com/kernc/backtesting.py.git
synced 2024-01-28 15:29:30 +03:00
ENH: Add parameter agg= to lib.resample_apply()
This commit is contained in:
@@ -133,7 +133,9 @@ def quantile(series, quantile=None):
|
|||||||
def resample_apply(rule: str,
|
def resample_apply(rule: str,
|
||||||
func: Callable,
|
func: Callable,
|
||||||
series,
|
series,
|
||||||
*args, **kwargs):
|
*args,
|
||||||
|
agg='last',
|
||||||
|
**kwargs):
|
||||||
"""
|
"""
|
||||||
Apply `func` (such as an indicator) to `series`, resampled to
|
Apply `func` (such as an indicator) to `series`, resampled to
|
||||||
a time frame specified by `rule`. When called from inside
|
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
|
resampling limitations, this only works when input series
|
||||||
has a datetime index.
|
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
|
Finally, any `*args` and `**kwargs` that are not already eaten by
|
||||||
implicit `backtesting.backtesting.Strategy.I` call
|
implicit `backtesting.backtesting.Strategy.I` call
|
||||||
are passed to `func`.
|
are passed to `func`.
|
||||||
@@ -203,7 +209,7 @@ def resample_apply(rule: str,
|
|||||||
'or a `Strategy.data.*` array'
|
'or a `Strategy.data.*` array'
|
||||||
series = series.to_series()
|
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 + ']'
|
resampled.name = _as_str(series) + '[' + rule + ']'
|
||||||
|
|
||||||
# Check first few stack frames if we are being called from
|
# Check first few stack frames if we are being called from
|
||||||
|
|||||||
Reference in New Issue
Block a user