original_docstring: Generates trading signals for a given dataset.
docstring: Generates trading signals for a given dataset.
docstring_tokens: Generates trading signals for a given dataset .
code: def generate_signals(df):
      """Generates trading signals for a given dataset."""
      print("-----> Generating trading signals <-----")
      # Set window
      short_window = 10
  
      signals = df.copy()
      signals["signal"] = 0.0
  
      # Generate the short and long moving averages
      signals["sma10"] = signals["close"].rolling(window=10).mean()
      signals["sma20"] = signals["close"].rolling(window=20).mean()
  
      # Generate the trading signal 0 or 1,
      signals["signal"][short_window:] = np.where(
          signals["sma10"][short_window:] > signals["sma20"][short_window:], 1.0, 0.0
      )
  
      # Calculate the points in time at which a position should be taken, 1 or -1
      signals["entry/exit"] = signals["signal"].diff()
      print("-----> Trading signals generated  <-----")
  
      return signals
code_tokens: def generate_signals ( df ) : print ( "-----> Generating trading signals <-----" ) short_window = 10 signals = df . copy ( ) signals [ "signal" ] = 0.0 signals [ "sma10" ] = signals [ "close" ] . rolling ( window = 10 ) . mean ( ) signals [ "sma20" ] = signals [ "close" ] . rolling ( window = 20 ) . mean ( ) signals [ "signal" ] [ short_window : ] = np . where ( signals [ "sma10" ] [ short_window : ] > signals [ "sma20" ] [ short_window : ] , 1.0 , 0.0 ) signals [ "entry/exit" ] = signals [ "signal" ] . diff ( ) print ( "-----> Trading signals generated  <-----" ) return signals
short_docstring: Generates trading signals for a given dataset.
short_docstring_tokens: Generates trading signals for a given dataset .
comment: """Generates trading signals for a given dataset."""$SEP$# Set window$SEP$# Generate the short and long moving averages$SEP$# Generate the trading signal 0 or 1,$SEP$# Calculate the points in time at which a position should be taken, 1 or -1