code: def stability_of_timeseries(returns):
      """Determines R-squared of a linear fit to the cumulative
      log returns. Computes an ordinary least squares linear fit,
      and returns R-squared.
  
      Parameters
      ----------
      returns : pd.Series or np.ndarray
          Daily returns of the strategy, noncumulative.
          - See full explanation in :func:`~empyrical.stats.cum_returns`.
  
      Returns
      -------
      float
          R-squared.
  
      """
      if len(returns) < 2:
          return np.nan
  
      returns = np.asanyarray(returns)
      returns = returns[~np.isnan(returns)]
  
      cum_log_returns = np.log1p(returns).cumsum()
      rhat = stats.linregress(
          np.arange(len(cum_log_returns)), cum_log_returns
      )[2]
  
      return rhat**2
  
imports: from __future__ import division
  from functools import wraps
  import pandas
  import numpy
  from scipy import stats
  from six import iteritems
  from empyrical.utils import nanmean, nanstd, nanmin
label_desc: Use image node_id 24 for calling a global function with example usage: stability_of_timeseries(returns) and returns: unknown, np