code: def stats_to_algo_folder(
      stats, algo_namespace, folder_name, recorded_cols=None
  ):
      """
      Saves the performance stats to the algo local folder.
  
      Parameters
      ----------
      stats: list[Object]
      algo_namespace: str
      folder_name: str
      recorded_cols: list[str]
  
      Returns
      -------
      str
  
      """
      bytes_to_write = get_csv_stats(stats, recorded_cols=recorded_cols)
  
      timestr = time.strftime("%Y%m%d")
      folder = get_algo_folder(algo_namespace)
  
      stats_folder = os.path.join(folder, folder_name)
      ensure_directory(stats_folder)
  
      filename = os.path.join(stats_folder, "{}.csv".format(timestr))
  
      with open(filename, "wb") as handle:
          handle.write(bytes_to_write)
  
      return bytes_to_write
  
imports: import copy
  import csv
  import json
  import numbers
  import os
  import time
  import numpy
  import pandas
  from catalyst.assets._assets import TradingPair
  from catalyst.exchange.utils.exchange_utils import get_algo_folder
  from catalyst.utils.paths import data_root, ensure_directory
  from operator import itemgetter
label_desc: Use image node_id 12 for calling a global function with example usage: stats_to_algo_folder(stats, algo_namespace, folder_name, recorded_cols) and returns: bytes_to_write