total PNL
This commit is contained in:
parent
fc2f834b32
commit
13c4f72b01
@ -365,7 +365,7 @@ def update_live_html(candles, trade_history, epoch):
|
|||||||
Generate an HTML page with a live chart.
|
Generate an HTML page with a live chart.
|
||||||
The chart displays price (line) and volume (bar chart on a secondary y-axis),
|
The chart displays price (line) and volume (bar chart on a secondary y-axis),
|
||||||
and includes buy/sell markers with dotted lines connecting entries and exits.
|
and includes buy/sell markers with dotted lines connecting entries and exits.
|
||||||
The page auto-refreshes every 10 seconds.
|
The page auto-refreshes every 1 second.
|
||||||
"""
|
"""
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import base64
|
import base64
|
||||||
@ -383,7 +383,7 @@ def update_live_html(candles, trade_history, epoch):
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="refresh" content="10">
|
<meta http-equiv="refresh" content="1">
|
||||||
<title>Live Trading Chart - Epoch {epoch}</title>
|
<title>Live Trading Chart - Epoch {epoch}</title>
|
||||||
<style>
|
<style>
|
||||||
body {{
|
body {{
|
||||||
@ -535,6 +535,7 @@ class BacktestEnvironment:
|
|||||||
# --- Enhanced Training Loop ---
|
# --- Enhanced Training Loop ---
|
||||||
def train_on_historical_data(env, model, device, args, start_epoch, optimizer, scheduler):
|
def train_on_historical_data(env, model, device, args, start_epoch, optimizer, scheduler):
|
||||||
lambda_trade = args.lambda_trade
|
lambda_trade = args.lambda_trade
|
||||||
|
total_pnl = 0.0
|
||||||
for epoch in range(start_epoch, args.epochs):
|
for epoch in range(start_epoch, args.epochs):
|
||||||
env.reset()
|
env.reset()
|
||||||
loss_accum = 0.0
|
loss_accum = 0.0
|
||||||
@ -563,10 +564,12 @@ def train_on_historical_data(env, model, device, args, start_epoch, optimizer, s
|
|||||||
loss_accum += loss.item()
|
loss_accum += loss.item()
|
||||||
scheduler.step()
|
scheduler.step()
|
||||||
epoch_loss = loss_accum / steps
|
epoch_loss = loss_accum / steps
|
||||||
print(f"Epoch {epoch+1} Loss: {epoch_loss:.4f}")
|
total_pnl += sum(trade["pnl"] for trade in env.trade_history)
|
||||||
|
print(f"Epoch {epoch+1} Loss: {epoch_loss:.4f} | Total PnL: {total_pnl:.2f}")
|
||||||
save_checkpoint(model, optimizer, epoch, loss_accum)
|
save_checkpoint(model, optimizer, epoch, loss_accum)
|
||||||
simulate_trades(model, env, device, args)
|
simulate_trades(model, env, device, args)
|
||||||
update_live_html(env.candle_window, env.trade_history, epoch+1)
|
update_live_html(env.candle_window, env.trade_history, epoch+1)
|
||||||
|
|
||||||
|
|
||||||
# --- Live Plotting (for Live Mode) ---
|
# --- Live Plotting (for Live Mode) ---
|
||||||
def live_preview_loop(candles, env):
|
def live_preview_loop(candles, env):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user