code: def compute_stats(
      *,
      stats: pd.Series,
      data: pd.DataFrame,
      trades: pd.DataFrame = None,
      risk_free_rate: float = 0.0,
  ) -> pd.Series:
      """
      (Re-)compute strategy performance metrics.
  
      `stats` is the statistics series as returned by `backtesting.backtesting.Backtest.run()`.
      `data` is OHLC data as passed to the `backtesting.backtesting.Backtest`
      the `stats` were obtained in.
      `trades` can be a dataframe subset of `stats._trades` (e.g. only long trades).
      You can also tune `risk_free_rate`, used in calculation of Sharpe and Sortino ratios.
  
          >>> stats = Backtest(GOOG, MyStrategy).run()
          >>> only_long_trades = stats._trades[stats._trades.Size > 0]
          >>> long_stats = compute_stats(stats=stats, trades=only_long_trades,
          ...                            data=GOOG, risk_free_rate=.02)
      """
      equity = stats._equity_curve.Equity
      if trades is None:
          trades = stats._trades
      else:
          # XXX: Is this buggy?
          equity = equity.copy()
          equity[:] = stats._equity_curve.Equity.iloc[0]
          for t in trades.itertuples(index=False):
              equity.iloc[t.EntryBar :] += t.PnL
      return _compute_stats(
          trades=trades,
          equity=equity,
          ohlc_data=data,
          risk_free_rate=risk_free_rate,
          strategy_instance=stats._strategy,
      )
  
imports: from collections import OrderedDict
  from inspect import currentframe
  from itertools import compress
  from numbers import Number
  from typing import Callable, Optional, Sequence, Union
  import numpy
  import pandas
  from ._plotting import plot_heatmaps
  from ._stats import compute_stats
  from ._util import _Array, _as_str
  from .backtesting import Strategy
label_desc: Use image node_id 6 for calling a global function with example usage: compute_stats() and returns: _compute_stats