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
  import math
  import pandas
  import numpy
  from math import pow
  from scipy import stats, optimize
  from six import iteritems
  from sys import float_info
  from .utils import nanmean, nanstd, nanmin, up, down, roll, rolling_window
  from .periods import ANNUALIZATION_FACTORS, APPROX_BDAYS_PER_YEAR
  from .periods import DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY
label_desc: Use image node_id 29 for calling a global function with example usage: stability_of_timeseries(returns) and returns: unknown, np