code: def test_set_riskfree_rate(df):
      r = df.to_returns()
  
      performanceStats = ffn.PerformanceStats(df["MSFT"])
      groupStats = ffn.GroupStats(df)
      daily_returns = (
          df["MSFT"].resample("D").last().dropna().pct_change()
      )
  
      aae(
          performanceStats.daily_sharpe,
          daily_returns.dropna().mean()
          / (daily_returns.dropna().std())
          * (np.sqrt(252)),
          3,
      )
  
      aae(
          performanceStats.daily_sharpe,
          groupStats["MSFT"].daily_sharpe,
          3,
      )
  
      monthly_returns = df["MSFT"].resample("M").last().pct_change()
      aae(
          performanceStats.monthly_sharpe,
          monthly_returns.dropna().mean()
          / (monthly_returns.dropna().std())
          * (np.sqrt(12)),
          3,
      )
      aae(
          performanceStats.monthly_sharpe,
          groupStats["MSFT"].monthly_sharpe,
          3,
      )
  
      yearly_returns = df["MSFT"].resample("A").last().pct_change()
      aae(
          performanceStats.yearly_sharpe,
          yearly_returns.dropna().mean()
          / (yearly_returns.dropna().std())
          * (np.sqrt(1)),
          3,
      )
      aae(
          performanceStats.yearly_sharpe,
          groupStats["MSFT"].yearly_sharpe,
          3,
      )
  
      performanceStats.set_riskfree_rate(0.02)
      groupStats.set_riskfree_rate(0.02)
  
      daily_returns = df["MSFT"].pct_change()
      aae(
          performanceStats.daily_sharpe,
          np.mean(daily_returns.dropna() - 0.02 / 252)
          / (daily_returns.dropna().std())
          * (np.sqrt(252)),
          3,
      )
      aae(
          performanceStats.daily_sharpe,
          groupStats["MSFT"].daily_sharpe,
          3,
      )
  
      monthly_returns = df["MSFT"].resample("M").last().pct_change()
      aae(
          performanceStats.monthly_sharpe,
          np.mean(monthly_returns.dropna() - 0.02 / 12)
          / (monthly_returns.dropna().std())
          * (np.sqrt(12)),
          3,
      )
      aae(
          performanceStats.monthly_sharpe,
          groupStats["MSFT"].monthly_sharpe,
          3,
      )
  
      yearly_returns = df["MSFT"].resample("A").last().pct_change()
      aae(
          performanceStats.yearly_sharpe,
          np.mean(yearly_returns.dropna() - 0.02 / 1)
          / (yearly_returns.dropna().std())
          * (np.sqrt(1)),
          3,
      )
      aae(
          performanceStats.yearly_sharpe,
          groupStats["MSFT"].yearly_sharpe,
          3,
      )
  
      rf = np.zeros(df.shape[0])
      # annual rf is 2%
      rf[1:] = 0.02 / 252
      rf[0] = 0.0
      # convert to price series
      rf = 100 * np.cumprod(
          1 + pd.Series(data=rf, index=df.index, name="rf")
      )
  
      performanceStats.set_riskfree_rate(rf)
      groupStats.set_riskfree_rate(rf)
  
      daily_returns = df["MSFT"].pct_change()
      rf_daily_returns = rf.pct_change()
      aae(
          performanceStats.daily_sharpe,
          np.mean(daily_returns - rf_daily_returns)
          / (daily_returns.dropna().std())
          * (np.sqrt(252)),
          3,
      )
      aae(
          performanceStats.daily_sharpe,
          groupStats["MSFT"].daily_sharpe,
          3,
      )
  
      monthly_returns = df["MSFT"].resample("M").last().pct_change()
      rf_monthly_returns = rf.resample("M").last().pct_change()
      aae(
          performanceStats.monthly_sharpe,
          np.mean(monthly_returns - rf_monthly_returns)
          / (monthly_returns.dropna().std())
          * (np.sqrt(12)),
          3,
      )
      aae(
          performanceStats.monthly_sharpe,
          groupStats["MSFT"].monthly_sharpe,
          3,
      )
  
      yearly_returns = df["MSFT"].resample("A").last().pct_change()
      rf_yearly_returns = rf.resample("A").last().pct_change()
      aae(
          performanceStats.yearly_sharpe,
          np.mean(yearly_returns - rf_yearly_returns)
          / (yearly_returns.dropna().std())
          * (np.sqrt(1)),
          3,
      )
      aae(
          performanceStats.yearly_sharpe,
          groupStats["MSFT"].yearly_sharpe,
          3,
      )
  
imports: import ffn
  import pandas
  import numpy
  from pytest import fixture
  from numpy.testing import assert_almost_equal
label_desc: Use image node_id 40 for calling a global function with example usage: test_set_riskfree_rate(df) without return types