code: def test_sma():
      indicator_name = "SMA"
      # Test Case 1: constant prices
      cols = get_cols_name(1)
      data_df = pd.DataFrame(index=dates, columns=cols, data=1)
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=-1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=1,
      )
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 2: Normal case with one single security
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 3: Normal case with multiple securities
      cols = get_cols_name(10)
      col_prices = np.array(range(1, 9))
      data_df = pd.DataFrame(
          index=dates,
          columns=cols,
          data=np.tile(col_prices, (len(cols), 1)).T,
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 4: Decreasing price with multiple securities
      cols = get_cols_name(10)
      col_prices = np.array(range(8, 0, -1))
      data_df = pd.DataFrame(
          index=dates,
          columns=cols,
          data=np.tile(col_prices, (len(cols), 1)).T,
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=-1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=data_df.shift().values,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
      expected_df.iloc[: tech_params.sma_period - 1] = np.nan
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 5: With SOME missing data
      cols = get_cols_name(1)
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      data_df.iloc[3] = np.nan
  
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=[np.nan, np.nan, 2, 2.67, 3.67, 4.67, 6, 7],
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      expected_signal_df.iloc[: tech_params.sma_period] = np.nan
  
      assert_frame_equal(df.apply(lambda x: round(x, 2)), expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 6: With not enough data
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=list(range(1, 9))
      )
      tech_params.sma_period = 20
  
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=np.nan,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=np.nan,
      )
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
file_path: finmarketpy/tests/test_techindicator.py
imports: import pytest
  import pandas
  import numpy
  from pandas.testing import assert_frame_equal
  from finmarketpy.economics.techindicator import TechParams, TechIndicator
label_desc: Use image node_id 2 for calling a global function with example usage: test_sma() without return types