code: def test_mtd_ytd(df):
      data = df["AAPL"]
  
      # Intramonth
      prices = data[
          pd.to_datetime("2004-12-10") : pd.to_datetime("2004-12-25")
      ]
      dp = prices.resample("D").last().dropna()
      mp = prices.resample("M").last().dropna()
      yp = prices.resample("A").last().dropna()
      mtd_actual = ffn.calc_mtd(dp, mp)
      ytd_actual = ffn.calc_ytd(dp, yp)
  
      aae(mtd_actual, -0.0175, 4)
      assert mtd_actual == ytd_actual
  
      # Year change - first month
      prices = data[
          pd.to_datetime("2004-12-10") : pd.to_datetime("2005-01-15")
      ]
      dp = prices.resample("D").last().dropna()
      mp = prices.resample("M").last().dropna()
      yp = prices.resample("A").last().dropna()
      mtd_actual = ffn.calc_mtd(dp, mp)
      ytd_actual = ffn.calc_ytd(dp, yp)
  
      aae(mtd_actual, 0.0901, 4)
      assert mtd_actual == ytd_actual
  
      # Year change - second month
      prices = data[
          pd.to_datetime("2004-12-10") : pd.to_datetime("2005-02-15")
      ]
      dp = prices.resample("D").last().dropna()
      mp = prices.resample("M").last().dropna()
      yp = prices.resample("A").last().dropna()
      mtd_actual = ffn.calc_mtd(dp, mp)
      ytd_actual = ffn.calc_ytd(dp, yp)
  
      aae(mtd_actual, 0.1497, 4)
      aae(ytd_actual, 0.3728, 4)
  
      # Single day
      prices = data[[pd.to_datetime("2004-12-10")]]
      dp = prices.resample("D").last().dropna()
      mp = prices.resample("M").last().dropna()
      yp = prices.resample("A").last().dropna()
      mtd_actual = ffn.calc_mtd(dp, mp)
      ytd_actual = ffn.calc_ytd(dp, yp)
  
      assert mtd_actual == ytd_actual == 0
  
imports: import ffn
  import pandas
  import numpy
  from pytest import fixture
  from numpy.testing import assert_almost_equal
label_desc: Use image node_id 3 for calling a global function with example usage: test_mtd_ytd(df) without return types