code: import numpy as np
  import pandas as pd
  
  
  def AAFT(df, random=np.random.uniform, random_state=None):
      """Amplitude Adjusted Fourier Transform Baseline Generator."""
      # set random seed
      np.random.seed(random_state)
      # Operate on numpy.ndarray
      ts = df.values
      # 2d time-series format
      _ts = ts.reshape(len(ts), -1)
      # Odd number of samples
      if len(_ts) % 2 != 0:
          _ts = _ts[1:, :]
      # Generated time-series
      ts_gen = np.empty_like(_ts)
      for i, tsi in enumerate(_ts.T):
          # Fourier Transaformation (real-valued signal)
          F_tsi = np.fft.rfft(tsi)
          # Randomization of Phase
          rv_phase = np.exp(random(0, np.pi, len(F_tsi)) * 1.0j)
          # Generation of new time-series
          F_tsi_new = F_tsi * rv_phase
          # Inverse Fourier Transformation
          ts_gen[:, i] = np.fft.irfft(F_tsi_new)
      # Create pandas DataFrame
      df_gen = pd.DataFrame(ts_gen, columns=df.columns,
                            index=df.index[-len(ts_gen):])
      return df_gen
   import numpy as np
  
  from qtrader.utils.numpy import eps
  
  
  def _mu_p(w: np.ndarray, r: np.ndarray) -> float:
      """Portfolio Returns."""
      return np.dot(w.T, r)
  
  
  def _sigma_p(w: np.ndarray, Sigma: np.ndarray) -> float:
      """Portoflio Variance"""
      return np.dot(np.dot(w.T, Sigma), w)
  
  
  def _trans_costs(w: np.ndarray, w0: np.ndarray, coef: float) -> float:
      """Transaction Costs."""
      return np.sum(np.abs(w0 - w)) * coef
  
  
  def risk_aversion(w: np.ndarray, mu: np.ndarray,
                    Sigma: np.ndarray, w0: np.ndarray,
                    alpha: float, beta: float) -> float:
      """Risk Aversion with Transaction Costs."""
      assert Sigma.shape[0] == Sigma.shape[1]
      assert mu.shape[0] == Sigma.shape[0]
      assert w.shape == w0.shape
      # mean - alpha * variance - transaction_costs
      return - (_mu_p(w, mu) - alpha * _sigma_p(w, Sigma) - _trans_costs(w, w0, beta))
  
  
  def sharpe_ratio(w: np.ndarray, mu: np.ndarray,
                   Sigma: np.ndarray, w0: np.ndarray,
                   beta: float) -> float:
      """Sharpe Ratio with Transaction Costs."""
      assert Sigma.shape[0] == Sigma.shape[1]
      assert mu.shape[0] == Sigma.shape[0]
      assert w.shape == w0.shape
      # mean - alpha * variance - transaction_costs
      return - ((_mu_p(w, mu) - _trans_costs(w, w0, beta)) / (_sigma_p(w, Sigma) + eps))
  
apis: numpy.empty_like numpy.fft.rfft numpy.random.seed numpy.fft.irfft
apis: numpy.dot numpy.abs