Write Trade Journal using python with Binance Tarde History data

Introduce to write trade journal using Binance Trade History excel file.

  1. Write Trade Journal using pandas library
    I would like to introduce easy way to write trade journal using pandas library. Assume that you are capable of using python.
  2. Export trade history in Binance through the export button.
  3. Copy and paste the code below.
import pandas as pd

# Assuming 'Realized Profit' is a column in your DataFrame that contains the profit or loss from each trade

# Win column: count of trades where 'Realized Profit' > 0
df['Win'] = df['Realized Profit'].apply(lambda x: 1 if x > 0 else 0)

# Lose column: count of trades where 'Realized Profit' < 0
df['Lose'] = df['Realized Profit'].apply(lambda x: 1 if x < 0 else 0)

# Win ratio: ratio of winning trades to total trades
win_ratio = df['Win'].sum() / (df['Win'].sum() + df['Lose'].sum())

# Total Trade: total number of trades
total_trade = df.shape[0]

# Total Fee: assuming 'fee' is a column in your DataFrame that contains the fee from each trade
total_fee = df['Fee'].sum()

# Accumulate profit: cumulative sum of 'Realized Profit'
df['Accumulate profit'] = df['Realized Profit'].cumsum()

# Initial Budget: assuming 'initial_budget' is a column in your DataFrame
initial_budget = df['initial_budget']=150  # if the initial budget is the same for all trades

# Total profit: (Initial Budget + Accumulate profit) - Total fee - Initial budget
df['Total profit'] = (initial_budget + df['Accumulate profit']) - total_fee - initial_budget

# Adding a single row DataFrame to store the calculated values
summary_df = pd.DataFrame({
    'Win ratio': [win_ratio],
    'Total Trade': [total_trade],
    'Total Fee': [total_fee],
    'Initial Budget': [initial_budget],
    'Accumulate profit': [df['Accumulate profit'].iloc[-1]],  # The last value in the 'Accumulate profit' column
    'Total profit': [df['Total profit'].iloc[-1]]  # The last value in the 'Total profit' column
})

summary_df

답글 남기기