fixes
This commit is contained in:
@@ -570,9 +570,12 @@ class BacktestResult:
|
||||
symbol_trades = [trade for trade in trades if trade["symbol"] == symbol]
|
||||
|
||||
# Calculate returns for all trade combinations
|
||||
for i in range(len(symbol_trades) - 1):
|
||||
trade1 = trades[i]
|
||||
trade2 = trades[i + 1]
|
||||
for idx in range(0, len(symbol_trades), 2):
|
||||
trade1 = trades[idx]
|
||||
trade2 = trades[idx + 1]
|
||||
|
||||
assert trade1["timestamp"] < trade2["timestamp"], f"Trade 1: {trade1['timestamp']} is not less than Trade 2: {trade2['timestamp']}"
|
||||
assert trade1["action"] == "OPEN" and trade2["action"] == "CLOSE", f"Trade 1: {trade1['action']} and Trade 2: {trade2['action']} are the same"
|
||||
|
||||
# Calculate return based on action combination
|
||||
trade_return = 0
|
||||
@@ -589,6 +592,8 @@ class BacktestResult:
|
||||
pair_trades.append(
|
||||
(
|
||||
symbol,
|
||||
trade1["timestamp"],
|
||||
trade2["timestamp"],
|
||||
trade1["side"],
|
||||
trade1["price"],
|
||||
trade2["side"],
|
||||
@@ -596,7 +601,7 @@ class BacktestResult:
|
||||
trade_return,
|
||||
trade1["scaled_disequilibrium"],
|
||||
trade2["scaled_disequilibrium"],
|
||||
i + 1, # Trade sequence number
|
||||
f"{idx + 1}", # Trade sequence number
|
||||
)
|
||||
)
|
||||
|
||||
@@ -607,6 +612,8 @@ class BacktestResult:
|
||||
print(f" {pair}:")
|
||||
for (
|
||||
symbol,
|
||||
trade1["timestamp"],
|
||||
trade2["timestamp"],
|
||||
trade1["side"],
|
||||
trade1["price"],
|
||||
trade2["side"],
|
||||
@@ -625,13 +632,14 @@ class BacktestResult:
|
||||
f" Close Dis-eq: {trade2["scaled_disequilibrium"]:.2f}"
|
||||
|
||||
print(
|
||||
f" {symbol} (Trade #{trade_num}):"
|
||||
f" {trade2['timestamp'].time()} {symbol} (Trade #{trade_num}):"
|
||||
f" {trade1["side"]} @ ${trade1["price"]:.2f},"
|
||||
f" {trade2["side"]} @ ${trade2["price"]:.2f},"
|
||||
f" Return: {trade_return:.2f}%{disequil_info}"
|
||||
)
|
||||
print(f" Pair Total Return: {pair_return:.2f}%")
|
||||
day_return += pair_return
|
||||
|
||||
|
||||
# Print day total return and add to global realized PnL
|
||||
if day_return != 0:
|
||||
|
||||
Reference in New Issue
Block a user