accessors module¶
Custom pandas accessors for returns data.
Methods can be accessed as follows:
- ReturnsSRAccessor ->
pd.Series.vbt.returns.*
- ReturnsDFAccessor ->
pd.DataFrame.vbt.returns.*
Note
The underlying Series/DataFrame must already be a return series. To convert price to returns, use ReturnsAccessor.from_value().
Grouping is only supported by the methods that accept the group_by
argument.
Accessors do not utilize caching.
There are three options to compute returns and get the accessor:
>>> import numpy as np
>>> import pandas as pd
>>> import vectorbt as vbt
>>> price = pd.Series([1.1, 1.2, 1.3, 1.2, 1.1])
>>> # 1. pd.Series.pct_change
>>> rets = price.pct_change()
>>> ret_acc = rets.vbt.returns(freq='d')
>>> # 2. vectorbt.generic.accessors.GenericAccessor.to_returns
>>> rets = price.vbt.to_returns()
>>> ret_acc = rets.vbt.returns(freq='d')
>>> # 3. vectorbt.returns.accessors.ReturnsAccessor.from_value
>>> ret_acc = pd.Series.vbt.returns.from_value(price, freq='d')
>>> # vectorbt.returns.accessors.ReturnsAccessor.total
>>> ret_acc.total()
0.0
The accessors extend vectorbt.generic.accessors.
>>> # inherited from GenericAccessor
>>> ret_acc.max()
0.09090909090909083
Defaults¶
ReturnsAccessor accepts defaults
dictionary where you can pass defaults for arguments used throughout the accessor, such as
start_value
: The starting value.window
: Window length.minp
: Minimum number of observations in a window required to have a value.ddof
: Delta Degrees of Freedom.risk_free
: Constant risk-free return throughout the period.levy_alpha
: Scaling relation (Levy stability exponent).required_return
: Minimum acceptance return of the investor.cutoff
: Decimal representing the percentage cutoff for the bottom percentile of returns.
Stats¶
Hint
>>> ret_acc.stats()
UserWarning: Metric 'benchmark_return' requires benchmark_rets to be set
UserWarning: Metric 'alpha' requires benchmark_rets to be set
UserWarning: Metric 'beta' requires benchmark_rets to be set
Start 0
End 4
Duration 5 days 00:00:00
Total Return [%] 0
Annualized Return [%] 0
Annualized Volatility [%] 184.643
Sharpe Ratio 0.691185
Calmar Ratio 0
Max Drawdown [%] 15.3846
Omega Ratio 1.08727
Sortino Ratio 1.17805
Skew 0.00151002
Kurtosis -5.94737
Tail Ratio 1.08985
Common Sense Ratio 1.08985
Value at Risk -0.0823718
dtype: object
The missing benchmark_rets
can be either passed to the contrustor of the accessor or as a setting to StatsBuilderMixin.stats():
>>> benchmark = pd.Series([1.05, 1.1, 1.15, 1.1, 1.05])
>>> benchmark_rets = benchmark.vbt.to_returns()
>>> ret_acc.stats(settings=dict(benchmark_rets=benchmark_rets))
Start 0
End 4
Duration 5 days 00:00:00
Total Return [%] 0
Benchmark Return [%] 0
Annualized Return [%] 0
Annualized Volatility [%] 184.643
Sharpe Ratio 0.691185
Calmar Ratio 0
Max Drawdown [%] 15.3846
Omega Ratio 1.08727
Sortino Ratio 1.17805
Skew 0.00151002
Kurtosis -5.94737
Tail Ratio 1.08985
Common Sense Ratio 1.08985
Value at Risk -0.0823718
Alpha 0.78789
Beta 1.83864
dtype: object
Note
StatsBuilderMixin.stats() does not support grouping.
Plots¶
Hint
This class inherits subplots from GenericAccessor.
ReturnsAccessor class¶
ReturnsAccessor(
obj,
benchmark_rets=None,
year_freq=None,
defaults=None,
**kwargs
)
Accessor on top of return series. For both, Series and DataFrames.
Accessible through pd.Series.vbt.returns
and pd.DataFrame.vbt.returns
.
Args
obj
:pd.Series
orpd.DataFrame
- Pandas object representing returns.
benchmark_rets
:array_like
- Pandas object representing benchmark returns.
year_freq
:any
- Year frequency for annualization purposes.
defaults
:dict
- Defaults that override
returns.defaults
in settings. **kwargs
- Keyword arguments that are passed down to GenericAccessor.
Superclasses
- AttrResolver
- BaseAccessor
- Configured
- Documented
- GenericAccessor
- IndexingBase
- PandasIndexer
- Pickleable
- PlotsBuilderMixin
- StatsBuilderMixin
- Wrapping
Inherited members
- AttrResolver.deep_getattr()
- AttrResolver.post_resolve_attr()
- AttrResolver.pre_resolve_attr()
- AttrResolver.resolve_attr()
- BaseAccessor.align_to()
- BaseAccessor.apply()
- BaseAccessor.apply_and_concat()
- BaseAccessor.apply_on_index()
- BaseAccessor.broadcast()
- BaseAccessor.broadcast_to()
- BaseAccessor.combine()
- BaseAccessor.concat()
- BaseAccessor.drop_duplicate_levels()
- BaseAccessor.drop_levels()
- BaseAccessor.drop_redundant_levels()
- BaseAccessor.empty()
- BaseAccessor.empty_like()
- BaseAccessor.make_symmetric()
- BaseAccessor.rename_levels()
- BaseAccessor.repeat()
- BaseAccessor.select_levels()
- BaseAccessor.stack_index()
- BaseAccessor.tile()
- BaseAccessor.to_1d_array()
- BaseAccessor.to_2d_array()
- BaseAccessor.to_dict()
- BaseAccessor.unstack_to_array()
- BaseAccessor.unstack_to_df()
- Configured.copy()
- Configured.dumps()
- Configured.loads()
- Configured.replace()
- Configured.to_doc()
- Configured.update_config()
- GenericAccessor.apply_along_axis()
- GenericAccessor.apply_and_reduce()
- GenericAccessor.apply_mapping()
- GenericAccessor.applymap()
- GenericAccessor.barplot()
- GenericAccessor.bfill()
- GenericAccessor.binarize()
- GenericAccessor.boxplot()
- GenericAccessor.bshift()
- GenericAccessor.config
- GenericAccessor.count()
- GenericAccessor.crossed_above()
- GenericAccessor.crossed_below()
- GenericAccessor.cumprod()
- GenericAccessor.cumsum()
- GenericAccessor.describe()
- GenericAccessor.df_accessor_cls
- GenericAccessor.diff()
- GenericAccessor.ewm_mean()
- GenericAccessor.ewm_std()
- GenericAccessor.expanding_apply()
- GenericAccessor.expanding_max()
- GenericAccessor.expanding_mean()
- GenericAccessor.expanding_min()
- GenericAccessor.expanding_split()
- GenericAccessor.expanding_std()
- GenericAccessor.ffill()
- GenericAccessor.fillna()
- GenericAccessor.filter()
- GenericAccessor.fshift()
- GenericAccessor.get_ranges()
- GenericAccessor.groupby_apply()
- GenericAccessor.histplot()
- GenericAccessor.idxmax()
- GenericAccessor.idxmin()
- GenericAccessor.iloc
- GenericAccessor.indexing_kwargs
- GenericAccessor.lineplot()
- GenericAccessor.loc
- GenericAccessor.mapping
- GenericAccessor.max()
- GenericAccessor.maxabs_scale()
- GenericAccessor.mean()
- GenericAccessor.median()
- GenericAccessor.min()
- GenericAccessor.minmax_scale()
- GenericAccessor.normalize()
- GenericAccessor.obj
- GenericAccessor.pct_change()
- GenericAccessor.plot()
- GenericAccessor.power_transform()
- GenericAccessor.product()
- GenericAccessor.quantile_transform()
- GenericAccessor.range_split()
- GenericAccessor.ranges
- GenericAccessor.rebase()
- GenericAccessor.reduce()
- GenericAccessor.resample_apply()
- GenericAccessor.robust_scale()
- GenericAccessor.rolling_apply()
- GenericAccessor.rolling_max()
- GenericAccessor.rolling_mean()
- GenericAccessor.rolling_min()
- GenericAccessor.rolling_split()
- GenericAccessor.rolling_std()
- GenericAccessor.scale()
- GenericAccessor.scatterplot()
- GenericAccessor.self_aliases
- GenericAccessor.shuffle()
- GenericAccessor.split()
- GenericAccessor.sr_accessor_cls
- GenericAccessor.std()
- GenericAccessor.sum()
- GenericAccessor.to_mapped()
- GenericAccessor.to_returns()
- GenericAccessor.transform()
- GenericAccessor.value_counts()
- GenericAccessor.wrapper
- GenericAccessor.writeable_attrs
- GenericAccessor.zscore()
- PandasIndexer.xs()
- Pickleable.load()
- Pickleable.save()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.regroup()
- Wrapping.select_one()
- Wrapping.select_one_from_obj()
Subclasses
alpha method¶
ReturnsAccessor.alpha(
benchmark_rets=None,
risk_free=None,
wrap_kwargs=None
)
See alpha_nb().
ann_factor property¶
Get annualization factor.
annual method¶
ReturnsAccessor.annual(
**kwargs
)
Annual returns.
annualized method¶
ReturnsAccessor.annualized(
wrap_kwargs=None
)
annualized_volatility method¶
ReturnsAccessor.annualized_volatility(
levy_alpha=None,
ddof=None,
wrap_kwargs=None
)
See annualized_volatility_nb().
benchmark_rets property¶
Benchmark returns.
beta method¶
ReturnsAccessor.beta(
benchmark_rets=None,
wrap_kwargs=None
)
See beta_nb().
calmar_ratio method¶
ReturnsAccessor.calmar_ratio(
wrap_kwargs=None
)
See calmar_ratio_nb().
capture method¶
ReturnsAccessor.capture(
benchmark_rets=None,
wrap_kwargs=None
)
See capture_nb().
common_sense_ratio method¶
ReturnsAccessor.common_sense_ratio(
wrap_kwargs=None
)
Common Sense Ratio.
cond_value_at_risk method¶
ReturnsAccessor.cond_value_at_risk(
cutoff=None,
wrap_kwargs=None
)
cumulative method¶
ReturnsAccessor.cumulative(
start_value=None,
wrap_kwargs=None
)
See cum_returns_nb().
daily method¶
ReturnsAccessor.daily(
**kwargs
)
Daily returns.
defaults property¶
Defaults for ReturnsAccessor.
Merges returns.defaults
from settings with defaults
from ReturnsAccessor.
deflated_sharpe_ratio method¶
ReturnsAccessor.deflated_sharpe_ratio(
risk_free=None,
ddof=None,
var_sharpe=None,
nb_trials=None,
bias=True,
wrap_kwargs=None
)
Deflated Sharpe Ratio (DSR).
Expresses the chance that the advertised strategy has a positive Sharpe ratio.
If var_sharpe
is None, is calculated based on all columns. If nb_trials
is None, is set to the number of columns.
down_capture method¶
ReturnsAccessor.down_capture(
benchmark_rets=None,
wrap_kwargs=None
)
See down_capture_nb().
downside_risk method¶
ReturnsAccessor.downside_risk(
required_return=None,
wrap_kwargs=None
)
See downside_risk_nb().
drawdown method¶
ReturnsAccessor.drawdown(
wrap_kwargs=None
)
Relative decline from a peak.
drawdowns property¶
ReturnsAccessor.get_drawdowns() with default arguments.
from_value class method¶
ReturnsAccessor.from_value(
value,
init_value=nan,
broadcast_kwargs=None,
wrap_kwargs=None,
**kwargs
)
Returns a new ReturnsAccessor instance with returns calculated from value
.
get_drawdowns method¶
ReturnsAccessor.get_drawdowns(
wrapper_kwargs=None,
**kwargs
)
Generate drawdown records of cumulative returns.
See Drawdowns.
indexing_func method¶
ReturnsAccessor.indexing_func(
pd_indexing_func,
**kwargs
)
Perform indexing on ReturnsAccessor.
information_ratio method¶
ReturnsAccessor.information_ratio(
benchmark_rets=None,
ddof=None,
wrap_kwargs=None
)
max_drawdown method¶
ReturnsAccessor.max_drawdown(
wrap_kwargs=None
)
See max_drawdown_nb().
Yields the same result as max_drawdown
of ReturnsAccessor.drawdowns.
metrics class variable¶
Metrics supported by ReturnsAccessor.
Config({
"start": {
"title": "Start",
"calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dc9a0>",
"agg_func": null,
"check_is_not_grouped": false,
"tags": "wrapper"
},
"end": {
"title": "End",
"calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dca40>",
"agg_func": null,
"check_is_not_grouped": false,
"tags": "wrapper"
},
"period": {
"title": "Period",
"calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dcae0>",
"apply_to_timedelta": true,
"agg_func": null,
"check_is_not_grouped": false,
"tags": "wrapper"
},
"total_return": {
"title": "Total Return [%]",
"calc_func": "total",
"post_calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dcb80>",
"tags": "returns"
},
"benchmark_return": {
"title": "Benchmark Return [%]",
"calc_func": "benchmark_rets.vbt.returns.total",
"post_calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dcc20>",
"check_has_benchmark_rets": true,
"tags": "returns"
},
"ann_return": {
"title": "Annualized Return [%]",
"calc_func": "annualized",
"post_calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dccc0>",
"check_has_freq": true,
"check_has_year_freq": true,
"tags": "returns"
},
"ann_volatility": {
"title": "Annualized Volatility [%]",
"calc_func": "annualized_volatility",
"post_calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dcd60>",
"check_has_freq": true,
"check_has_year_freq": true,
"tags": "returns"
},
"max_dd": {
"title": "Max Drawdown [%]",
"calc_func": "drawdowns.max_drawdown",
"post_calc_func": "<function ReturnsAccessor.<lambda> at 0x1750dce00>",
"tags": [
"returns",
"drawdowns"
]
},
"max_dd_duration": {
"title": "Max Drawdown Duration",
"calc_func": "drawdowns.max_duration",
"fill_wrap_kwargs": true,
"tags": [
"returns",
"drawdowns",
"duration"
]
},
"sharpe_ratio": {
"title": "Sharpe Ratio",
"calc_func": "sharpe_ratio",
"check_has_freq": true,
"check_has_year_freq": true,
"tags": "returns"
},
"calmar_ratio": {
"title": "Calmar Ratio",
"calc_func": "calmar_ratio",
"check_has_freq": true,
"check_has_year_freq": true,
"tags": "returns"
},
"omega_ratio": {
"title": "Omega Ratio",
"calc_func": "omega_ratio",
"check_has_freq": true,
"check_has_year_freq": true,
"tags": "returns"
},
"sortino_ratio": {
"title": "Sortino Ratio",
"calc_func": "sortino_ratio",
"check_has_freq": true,
"check_has_year_freq": true,
"tags": "returns"
},
"skew": {
"title": "Skew",
"calc_func": "obj.skew",
"tags": "returns"
},
"kurtosis": {
"title": "Kurtosis",
"calc_func": "obj.kurtosis",
"tags": "returns"
},
"tail_ratio": {
"title": "Tail Ratio",
"calc_func": "tail_ratio",
"tags": "returns"
},
"common_sense_ratio": {
"title": "Common Sense Ratio",
"calc_func": "common_sense_ratio",
"check_has_freq": true,
"check_has_year_freq": true,
"tags": "returns"
},
"value_at_risk": {
"title": "Value at Risk",
"calc_func": "value_at_risk",
"tags": "returns"
},
"alpha": {
"title": "Alpha",
"calc_func": "alpha",
"check_has_freq": true,
"check_has_year_freq": true,
"check_has_benchmark_rets": true,
"tags": "returns"
},
"beta": {
"title": "Beta",
"calc_func": "beta",
"check_has_benchmark_rets": true,
"tags": "returns"
}
})
Returns ReturnsAccessor._metrics
, which gets (deep) copied upon creation of each instance. Thus, changing this config won't affect the class.
To change metrics, you can either change the config in-place, override this property, or overwrite the instance variable ReturnsAccessor._metrics
.
omega_ratio method¶
ReturnsAccessor.omega_ratio(
risk_free=None,
required_return=None,
wrap_kwargs=None
)
See omega_ratio_nb().
plots_defaults property¶
Defaults for PlotsBuilderMixin.plots().
Merges GenericAccessor.plots_defaults, defaults from ReturnsAccessor.defaults (acting as settings
), and returns.plots
from settings
qs property¶
Quantstats adapter.
resolve_self method¶
ReturnsAccessor.resolve_self(
cond_kwargs=None,
custom_arg_names=None,
impacts_caching=True,
silence_warnings=False
)
Resolve self.
Creates a copy of this instance year_freq
is different in cond_kwargs
.
rolling_alpha method¶
ReturnsAccessor.rolling_alpha(
benchmark_rets=None,
window=None,
minp=None,
risk_free=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.alpha().
rolling_annualized method¶
ReturnsAccessor.rolling_annualized(
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.annualized().
rolling_annualized_volatility method¶
ReturnsAccessor.rolling_annualized_volatility(
window=None,
minp=None,
levy_alpha=None,
ddof=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.annualized_volatility().
rolling_beta method¶
ReturnsAccessor.rolling_beta(
benchmark_rets=None,
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.beta().
rolling_calmar_ratio method¶
ReturnsAccessor.rolling_calmar_ratio(
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.calmar_ratio().
rolling_capture method¶
ReturnsAccessor.rolling_capture(
benchmark_rets=None,
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.capture().
rolling_common_sense_ratio method¶
ReturnsAccessor.rolling_common_sense_ratio(
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.common_sense_ratio().
rolling_cond_value_at_risk method¶
ReturnsAccessor.rolling_cond_value_at_risk(
window=None,
minp=None,
cutoff=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.cond_value_at_risk().
rolling_down_capture method¶
ReturnsAccessor.rolling_down_capture(
benchmark_rets=None,
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.down_capture().
rolling_downside_risk method¶
ReturnsAccessor.rolling_downside_risk(
window=None,
minp=None,
required_return=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.downside_risk().
rolling_information_ratio method¶
ReturnsAccessor.rolling_information_ratio(
benchmark_rets=None,
window=None,
minp=None,
ddof=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.information_ratio().
rolling_max_drawdown method¶
ReturnsAccessor.rolling_max_drawdown(
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.max_drawdown().
rolling_omega_ratio method¶
ReturnsAccessor.rolling_omega_ratio(
window=None,
minp=None,
risk_free=None,
required_return=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.omega_ratio().
rolling_sharpe_ratio method¶
ReturnsAccessor.rolling_sharpe_ratio(
window=None,
minp=None,
risk_free=None,
ddof=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.sharpe_ratio().
rolling_sortino_ratio method¶
ReturnsAccessor.rolling_sortino_ratio(
window=None,
minp=None,
required_return=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.sortino_ratio().
rolling_tail_ratio method¶
ReturnsAccessor.rolling_tail_ratio(
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.tail_ratio().
rolling_total method¶
ReturnsAccessor.rolling_total(
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.total().
rolling_up_capture method¶
ReturnsAccessor.rolling_up_capture(
benchmark_rets=None,
window=None,
minp=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.up_capture().
rolling_value_at_risk method¶
ReturnsAccessor.rolling_value_at_risk(
window=None,
minp=None,
cutoff=None,
wrap_kwargs=None
)
Rolling version of ReturnsAccessor.value_at_risk().
sharpe_ratio method¶
ReturnsAccessor.sharpe_ratio(
risk_free=None,
ddof=None,
wrap_kwargs=None
)
See sharpe_ratio_nb().
sortino_ratio method¶
ReturnsAccessor.sortino_ratio(
required_return=None,
wrap_kwargs=None
)
See sortino_ratio_nb().
stats_defaults property¶
Defaults for StatsBuilderMixin.stats().
Merges GenericAccessor.stats_defaults, defaults from ReturnsAccessor.defaults (acting as settings
), and returns.stats
from settings
subplots class variable¶
Subplots supported by ReturnsAccessor.
Config({
"plot": {
"check_is_not_grouped": true,
"plot_func": "plot",
"pass_trace_names": false,
"tags": "generic"
}
})
Returns ReturnsAccessor._subplots
, which gets (deep) copied upon creation of each instance. Thus, changing this config won't affect the class.
To change subplots, you can either change the config in-place, override this property, or overwrite the instance variable ReturnsAccessor._subplots
.
tail_ratio method¶
ReturnsAccessor.tail_ratio(
wrap_kwargs=None
)
See tail_ratio_nb().
total method¶
ReturnsAccessor.total(
wrap_kwargs=None
)
up_capture method¶
ReturnsAccessor.up_capture(
benchmark_rets=None,
wrap_kwargs=None
)
See up_capture_nb().
value_at_risk method¶
ReturnsAccessor.value_at_risk(
cutoff=None,
wrap_kwargs=None
)
See value_at_risk_nb().
year_freq property¶
Year frequency for annualization purposes.
ReturnsDFAccessor class¶
ReturnsDFAccessor(
obj,
benchmark_rets=None,
year_freq=None,
defaults=None,
**kwargs
)
Accessor on top of return series. For DataFrames only.
Accessible through pd.DataFrame.vbt.returns
.
Superclasses
- AttrResolver
- BaseAccessor
- BaseDFAccessor
- Configured
- Documented
- GenericAccessor
- GenericDFAccessor
- IndexingBase
- PandasIndexer
- Pickleable
- PlotsBuilderMixin
- ReturnsAccessor
- StatsBuilderMixin
- Wrapping
Inherited members
- AttrResolver.deep_getattr()
- AttrResolver.post_resolve_attr()
- AttrResolver.pre_resolve_attr()
- AttrResolver.resolve_attr()
- BaseAccessor.align_to()
- BaseAccessor.apply()
- BaseAccessor.apply_and_concat()
- BaseAccessor.apply_on_index()
- BaseAccessor.broadcast()
- BaseAccessor.broadcast_to()
- BaseAccessor.combine()
- BaseAccessor.concat()
- BaseAccessor.drop_duplicate_levels()
- BaseAccessor.drop_levels()
- BaseAccessor.drop_redundant_levels()
- BaseAccessor.empty()
- BaseAccessor.empty_like()
- BaseAccessor.make_symmetric()
- BaseAccessor.rename_levels()
- BaseAccessor.repeat()
- BaseAccessor.select_levels()
- BaseAccessor.stack_index()
- BaseAccessor.tile()
- BaseAccessor.to_1d_array()
- BaseAccessor.to_2d_array()
- BaseAccessor.to_dict()
- BaseAccessor.unstack_to_array()
- BaseAccessor.unstack_to_df()
- Configured.copy()
- Configured.dumps()
- Configured.loads()
- Configured.replace()
- Configured.to_doc()
- Configured.update_config()
- GenericAccessor.apply_along_axis()
- GenericAccessor.apply_and_reduce()
- GenericAccessor.apply_mapping()
- GenericAccessor.applymap()
- GenericAccessor.barplot()
- GenericAccessor.bfill()
- GenericAccessor.binarize()
- GenericAccessor.boxplot()
- GenericAccessor.bshift()
- GenericAccessor.count()
- GenericAccessor.crossed_above()
- GenericAccessor.crossed_below()
- GenericAccessor.cumprod()
- GenericAccessor.cumsum()
- GenericAccessor.describe()
- GenericAccessor.diff()
- GenericAccessor.ewm_mean()
- GenericAccessor.ewm_std()
- GenericAccessor.expanding_apply()
- GenericAccessor.expanding_max()
- GenericAccessor.expanding_mean()
- GenericAccessor.expanding_min()
- GenericAccessor.expanding_split()
- GenericAccessor.expanding_std()
- GenericAccessor.ffill()
- GenericAccessor.fillna()
- GenericAccessor.filter()
- GenericAccessor.fshift()
- GenericAccessor.get_ranges()
- GenericAccessor.groupby_apply()
- GenericAccessor.histplot()
- GenericAccessor.idxmax()
- GenericAccessor.idxmin()
- GenericAccessor.lineplot()
- GenericAccessor.max()
- GenericAccessor.maxabs_scale()
- GenericAccessor.mean()
- GenericAccessor.median()
- GenericAccessor.min()
- GenericAccessor.minmax_scale()
- GenericAccessor.normalize()
- GenericAccessor.pct_change()
- GenericAccessor.plot()
- GenericAccessor.power_transform()
- GenericAccessor.product()
- GenericAccessor.quantile_transform()
- GenericAccessor.range_split()
- GenericAccessor.rebase()
- GenericAccessor.reduce()
- GenericAccessor.resample_apply()
- GenericAccessor.robust_scale()
- GenericAccessor.rolling_apply()
- GenericAccessor.rolling_max()
- GenericAccessor.rolling_mean()
- GenericAccessor.rolling_min()
- GenericAccessor.rolling_split()
- GenericAccessor.rolling_std()
- GenericAccessor.scale()
- GenericAccessor.scatterplot()
- GenericAccessor.shuffle()
- GenericAccessor.split()
- GenericAccessor.std()
- GenericAccessor.sum()
- GenericAccessor.to_mapped()
- GenericAccessor.to_returns()
- GenericAccessor.transform()
- GenericAccessor.value_counts()
- GenericAccessor.zscore()
- GenericDFAccessor.flatten_grouped()
- GenericDFAccessor.heatmap()
- GenericDFAccessor.squeeze_grouped()
- GenericDFAccessor.ts_heatmap()
- PandasIndexer.xs()
- Pickleable.load()
- Pickleable.save()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- ReturnsAccessor.alpha()
- ReturnsAccessor.ann_factor
- ReturnsAccessor.annual()
- ReturnsAccessor.annualized()
- ReturnsAccessor.annualized_volatility()
- ReturnsAccessor.benchmark_rets
- ReturnsAccessor.beta()
- ReturnsAccessor.calmar_ratio()
- ReturnsAccessor.capture()
- ReturnsAccessor.common_sense_ratio()
- ReturnsAccessor.cond_value_at_risk()
- ReturnsAccessor.config
- ReturnsAccessor.cumulative()
- ReturnsAccessor.daily()
- ReturnsAccessor.defaults
- ReturnsAccessor.deflated_sharpe_ratio()
- ReturnsAccessor.df_accessor_cls
- ReturnsAccessor.down_capture()
- ReturnsAccessor.downside_risk()
- ReturnsAccessor.drawdown()
- ReturnsAccessor.drawdowns
- ReturnsAccessor.from_value()
- ReturnsAccessor.get_drawdowns()
- ReturnsAccessor.iloc
- ReturnsAccessor.indexing_func()
- ReturnsAccessor.indexing_kwargs
- ReturnsAccessor.information_ratio()
- ReturnsAccessor.loc
- ReturnsAccessor.mapping
- ReturnsAccessor.max_drawdown()
- ReturnsAccessor.obj
- ReturnsAccessor.omega_ratio()
- ReturnsAccessor.plots_defaults
- ReturnsAccessor.qs
- ReturnsAccessor.ranges
- ReturnsAccessor.resolve_self()
- ReturnsAccessor.rolling_alpha()
- ReturnsAccessor.rolling_annualized()
- ReturnsAccessor.rolling_annualized_volatility()
- ReturnsAccessor.rolling_beta()
- ReturnsAccessor.rolling_calmar_ratio()
- ReturnsAccessor.rolling_capture()
- ReturnsAccessor.rolling_common_sense_ratio()
- ReturnsAccessor.rolling_cond_value_at_risk()
- ReturnsAccessor.rolling_down_capture()
- ReturnsAccessor.rolling_downside_risk()
- ReturnsAccessor.rolling_information_ratio()
- ReturnsAccessor.rolling_max_drawdown()
- ReturnsAccessor.rolling_omega_ratio()
- ReturnsAccessor.rolling_sharpe_ratio()
- ReturnsAccessor.rolling_sortino_ratio()
- ReturnsAccessor.rolling_tail_ratio()
- ReturnsAccessor.rolling_total()
- ReturnsAccessor.rolling_up_capture()
- ReturnsAccessor.rolling_value_at_risk()
- ReturnsAccessor.self_aliases
- ReturnsAccessor.sharpe_ratio()
- ReturnsAccessor.sortino_ratio()
- ReturnsAccessor.sr_accessor_cls
- ReturnsAccessor.stats_defaults
- ReturnsAccessor.tail_ratio()
- ReturnsAccessor.total()
- ReturnsAccessor.up_capture()
- ReturnsAccessor.value_at_risk()
- ReturnsAccessor.wrapper
- ReturnsAccessor.writeable_attrs
- ReturnsAccessor.year_freq
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.regroup()
- Wrapping.select_one()
- Wrapping.select_one_from_obj()
ReturnsSRAccessor class¶
ReturnsSRAccessor(
obj,
benchmark_rets=None,
year_freq=None,
defaults=None,
**kwargs
)
Accessor on top of return series. For Series only.
Accessible through pd.Series.vbt.returns
.
Superclasses
- AttrResolver
- BaseAccessor
- BaseSRAccessor
- Configured
- Documented
- GenericAccessor
- GenericSRAccessor
- IndexingBase
- PandasIndexer
- Pickleable
- PlotsBuilderMixin
- ReturnsAccessor
- StatsBuilderMixin
- Wrapping
Inherited members
- AttrResolver.deep_getattr()
- AttrResolver.post_resolve_attr()
- AttrResolver.pre_resolve_attr()
- AttrResolver.resolve_attr()
- BaseAccessor.align_to()
- BaseAccessor.apply()
- BaseAccessor.apply_and_concat()
- BaseAccessor.apply_on_index()
- BaseAccessor.broadcast()
- BaseAccessor.broadcast_to()
- BaseAccessor.combine()
- BaseAccessor.concat()
- BaseAccessor.drop_duplicate_levels()
- BaseAccessor.drop_levels()
- BaseAccessor.drop_redundant_levels()
- BaseAccessor.empty()
- BaseAccessor.empty_like()
- BaseAccessor.make_symmetric()
- BaseAccessor.rename_levels()
- BaseAccessor.repeat()
- BaseAccessor.select_levels()
- BaseAccessor.stack_index()
- BaseAccessor.tile()
- BaseAccessor.to_1d_array()
- BaseAccessor.to_2d_array()
- BaseAccessor.to_dict()
- BaseAccessor.unstack_to_array()
- BaseAccessor.unstack_to_df()
- Configured.copy()
- Configured.dumps()
- Configured.loads()
- Configured.replace()
- Configured.to_doc()
- Configured.update_config()
- GenericAccessor.apply_along_axis()
- GenericAccessor.apply_and_reduce()
- GenericAccessor.apply_mapping()
- GenericAccessor.applymap()
- GenericAccessor.barplot()
- GenericAccessor.bfill()
- GenericAccessor.binarize()
- GenericAccessor.boxplot()
- GenericAccessor.bshift()
- GenericAccessor.count()
- GenericAccessor.crossed_above()
- GenericAccessor.crossed_below()
- GenericAccessor.cumprod()
- GenericAccessor.cumsum()
- GenericAccessor.describe()
- GenericAccessor.diff()
- GenericAccessor.ewm_mean()
- GenericAccessor.ewm_std()
- GenericAccessor.expanding_apply()
- GenericAccessor.expanding_max()
- GenericAccessor.expanding_mean()
- GenericAccessor.expanding_min()
- GenericAccessor.expanding_split()
- GenericAccessor.expanding_std()
- GenericAccessor.ffill()
- GenericAccessor.fillna()
- GenericAccessor.filter()
- GenericAccessor.fshift()
- GenericAccessor.get_ranges()
- GenericAccessor.groupby_apply()
- GenericAccessor.histplot()
- GenericAccessor.idxmax()
- GenericAccessor.idxmin()
- GenericAccessor.lineplot()
- GenericAccessor.max()
- GenericAccessor.maxabs_scale()
- GenericAccessor.mean()
- GenericAccessor.median()
- GenericAccessor.min()
- GenericAccessor.minmax_scale()
- GenericAccessor.normalize()
- GenericAccessor.pct_change()
- GenericAccessor.plot()
- GenericAccessor.power_transform()
- GenericAccessor.product()
- GenericAccessor.quantile_transform()
- GenericAccessor.range_split()
- GenericAccessor.rebase()
- GenericAccessor.reduce()
- GenericAccessor.resample_apply()
- GenericAccessor.robust_scale()
- GenericAccessor.rolling_apply()
- GenericAccessor.rolling_max()
- GenericAccessor.rolling_mean()
- GenericAccessor.rolling_min()
- GenericAccessor.rolling_split()
- GenericAccessor.rolling_std()
- GenericAccessor.scale()
- GenericAccessor.scatterplot()
- GenericAccessor.shuffle()
- GenericAccessor.split()
- GenericAccessor.std()
- GenericAccessor.sum()
- GenericAccessor.to_mapped()
- GenericAccessor.to_returns()
- GenericAccessor.transform()
- GenericAccessor.value_counts()
- GenericAccessor.zscore()
- GenericSRAccessor.flatten_grouped()
- GenericSRAccessor.heatmap()
- GenericSRAccessor.overlay_with_heatmap()
- GenericSRAccessor.plot_against()
- GenericSRAccessor.qqplot()
- GenericSRAccessor.squeeze_grouped()
- GenericSRAccessor.ts_heatmap()
- GenericSRAccessor.volume()
- PandasIndexer.xs()
- Pickleable.load()
- Pickleable.save()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- ReturnsAccessor.alpha()
- ReturnsAccessor.ann_factor
- ReturnsAccessor.annual()
- ReturnsAccessor.annualized()
- ReturnsAccessor.annualized_volatility()
- ReturnsAccessor.benchmark_rets
- ReturnsAccessor.beta()
- ReturnsAccessor.calmar_ratio()
- ReturnsAccessor.capture()
- ReturnsAccessor.common_sense_ratio()
- ReturnsAccessor.cond_value_at_risk()
- ReturnsAccessor.config
- ReturnsAccessor.cumulative()
- ReturnsAccessor.daily()
- ReturnsAccessor.defaults
- ReturnsAccessor.deflated_sharpe_ratio()
- ReturnsAccessor.df_accessor_cls
- ReturnsAccessor.down_capture()
- ReturnsAccessor.downside_risk()
- ReturnsAccessor.drawdown()
- ReturnsAccessor.drawdowns
- ReturnsAccessor.from_value()
- ReturnsAccessor.get_drawdowns()
- ReturnsAccessor.iloc
- ReturnsAccessor.indexing_func()
- ReturnsAccessor.indexing_kwargs
- ReturnsAccessor.information_ratio()
- ReturnsAccessor.loc
- ReturnsAccessor.mapping
- ReturnsAccessor.max_drawdown()
- ReturnsAccessor.obj
- ReturnsAccessor.omega_ratio()
- ReturnsAccessor.plots_defaults
- ReturnsAccessor.qs
- ReturnsAccessor.ranges
- ReturnsAccessor.resolve_self()
- ReturnsAccessor.rolling_alpha()
- ReturnsAccessor.rolling_annualized()
- ReturnsAccessor.rolling_annualized_volatility()
- ReturnsAccessor.rolling_beta()
- ReturnsAccessor.rolling_calmar_ratio()
- ReturnsAccessor.rolling_capture()
- ReturnsAccessor.rolling_common_sense_ratio()
- ReturnsAccessor.rolling_cond_value_at_risk()
- ReturnsAccessor.rolling_down_capture()
- ReturnsAccessor.rolling_downside_risk()
- ReturnsAccessor.rolling_information_ratio()
- ReturnsAccessor.rolling_max_drawdown()
- ReturnsAccessor.rolling_omega_ratio()
- ReturnsAccessor.rolling_sharpe_ratio()
- ReturnsAccessor.rolling_sortino_ratio()
- ReturnsAccessor.rolling_tail_ratio()
- ReturnsAccessor.rolling_total()
- ReturnsAccessor.rolling_up_capture()
- ReturnsAccessor.rolling_value_at_risk()
- ReturnsAccessor.self_aliases
- ReturnsAccessor.sharpe_ratio()
- ReturnsAccessor.sortino_ratio()
- ReturnsAccessor.sr_accessor_cls
- ReturnsAccessor.stats_defaults
- ReturnsAccessor.tail_ratio()
- ReturnsAccessor.total()
- ReturnsAccessor.up_capture()
- ReturnsAccessor.value_at_risk()
- ReturnsAccessor.wrapper
- ReturnsAccessor.writeable_attrs
- ReturnsAccessor.year_freq
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.regroup()
- Wrapping.select_one()
- Wrapping.select_one_from_obj()
plot_cumulative method¶
ReturnsSRAccessor.plot_cumulative(
benchmark_rets=None,
start_value=1,
fill_to_benchmark=False,
main_kwargs=None,
benchmark_kwargs=None,
hline_shape_kwargs=None,
add_trace_kwargs=None,
xref='x',
yref='y',
fig=None,
**layout_kwargs
)
Plot cumulative returns.
Args
benchmark_rets
:array_like
- Benchmark return to compare returns against. Will broadcast per element.
start_value
:float
- The starting returns.
fill_to_benchmark
:bool
- Whether to fill between main and benchmark, or between main and
start_value
. main_kwargs
:dict
- Keyword arguments passed to GenericAccessor.plot() for main.
benchmark_kwargs
:dict
- Keyword arguments passed to GenericAccessor.plot() for benchmark.
hline_shape_kwargs
:dict
- Keyword arguments passed to
plotly.graph_objects.Figure.add_shape
forstart_value
line. add_trace_kwargs
:dict
- Keyword arguments passed to
add_trace
. xref
:str
- X coordinate axis.
yref
:str
- Y coordinate axis.
fig
:Figure
orFigureWidget
- Figure to add traces to.
**layout_kwargs
- Keyword arguments for layout.
Usage
>>> import pandas as pd
>>> import numpy as np
>>> np.random.seed(0)
>>> rets = pd.Series(np.random.uniform(-0.05, 0.05, size=100))
>>> benchmark_rets = pd.Series(np.random.uniform(-0.05, 0.05, size=100))
>>> rets.vbt.returns.plot_cumulative(benchmark_rets=benchmark_rets)