this is my code. i dont want to print trade details, i only want ending capital at the…
- User
this is my code. i dont want to print trade details, i only want ending capital at the end of each day after all trades executed: import yfinance as yf import pandas as pd import pandas_ta as ta import datetime as dt
Define the initial capital
initial_capital = 1000
Define the strategy parameters
short_window = 10 long_window = 30
Download historical data for GBP/USD with a 5-minute interval
data = yf.download('GBPUSD=X', period='7d', interval='5m')
Calculate Exponential Moving Averages (EMAs)
data['Short_EMA'] = data['Close'].ewm(span=short_window, adjust=False).mean() data['Long_EMA'] = data['Close'].ewm(span=long_window, adjust=False).mean()
Calculate RSI
data['RSI'] = ta.rsi(data['Close'], window=14)
Calculate MACD
data['Short_MA'] = data['Close'].rolling(window=12, min_periods=1).mean() data['Long_MA'] = data['Close'].rolling(window=26, min_periods=1).mean() data['MACD'] = data['Short_MA'] - data['Long_MA'] data['Signal_Line'] = data['MACD'].rolling(window=9, min_periods=1).mean()
Generate signals
data['Signal'] = 0.0 conditions_long = (data['Short_EMA'] > data['Long_EMA']) &
(data['RSI'] > 30) &
(data['MACD'] > 0) &
(data['Signal_Line'] > 0) &
(data['Close'] > data['Short_EMA']) &
(data['Close'].shift(1) < data['Short_EMA'].shift(1))conditions_short = (data['Short_EMA'] < data['Long_EMA']) &
(data['RSI'] < 70) &
(data['MACD'] < 0) &
(data['Signal_Line'] < 0) &
(data['Close'] < data['Short_EMA']) &
(data['Close'].shift(1) > data['Short_EMA'].shift(1))data.loc[conditions_long, 'Signal'] = 1.0 # Long signal data.loc[conditions_short, 'Signal'] = -1.0 # Short signal
Initialize the variables for the backtest
position = 0 capital = initial_capital entry_price = 0.0 entry_time = None
Run the backtest
for index, row in data.iterrows(): # Check for long signals if row['Signal'] == 1.0 and position <= 0: position = 1 entry_price = row['Close'] entry_time = index print(f"Trade {index}: Going Long | Buying at {entry_price}")
code - Assistant
To modify the code so that it only prints the ending capital at the end of each day after all trades have been executed, you'll need to do the following:
- Remove or comment out all the statements that are related to the trading details.
- User
give me whole code please without placeholders
- Assistant