hedgequantx 2.4.35 → 2.4.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/pages/stats.js +18 -11
package/package.json
CHANGED
package/src/pages/stats.js
CHANGED
|
@@ -205,6 +205,7 @@ const showStats = async (service) => {
|
|
|
205
205
|
});
|
|
206
206
|
|
|
207
207
|
// Calculate stats from completed trades only
|
|
208
|
+
// Include fees in P&L calculations to match TopStep
|
|
208
209
|
if (completedTrades.length > 0) {
|
|
209
210
|
stats.totalTrades = completedTrades.length;
|
|
210
211
|
let consecutiveWins = 0, consecutiveLosses = 0;
|
|
@@ -217,7 +218,9 @@ const showStats = async (service) => {
|
|
|
217
218
|
});
|
|
218
219
|
|
|
219
220
|
for (const trade of sortedTrades) {
|
|
220
|
-
const
|
|
221
|
+
const grossPnl = trade.profitAndLoss || trade.pnl || 0;
|
|
222
|
+
const fees = Math.abs(trade.fees || trade.commission || 0);
|
|
223
|
+
const netPnl = grossPnl - fees; // Net P&L after fees (like TopStep)
|
|
221
224
|
const size = trade.size || trade.quantity || 1;
|
|
222
225
|
const exitSide = trade.side; // 0=BUY exit (was SHORT), 1=SELL exit (was LONG)
|
|
223
226
|
|
|
@@ -228,26 +231,26 @@ const showStats = async (service) => {
|
|
|
228
231
|
// Exit side 1 = SELL to close = was LONG
|
|
229
232
|
if (exitSide === 1) {
|
|
230
233
|
stats.longTrades++;
|
|
231
|
-
if (
|
|
234
|
+
if (netPnl > 0) stats.longWins++;
|
|
232
235
|
} else if (exitSide === 0) {
|
|
233
236
|
stats.shortTrades++;
|
|
234
|
-
if (
|
|
237
|
+
if (netPnl > 0) stats.shortWins++;
|
|
235
238
|
}
|
|
236
239
|
|
|
237
|
-
if (
|
|
240
|
+
if (netPnl > 0) {
|
|
238
241
|
stats.winningTrades++;
|
|
239
|
-
stats.totalWinAmount +=
|
|
242
|
+
stats.totalWinAmount += netPnl;
|
|
240
243
|
consecutiveWins++;
|
|
241
244
|
consecutiveLosses = 0;
|
|
242
245
|
if (consecutiveWins > stats.maxConsecutiveWins) stats.maxConsecutiveWins = consecutiveWins;
|
|
243
|
-
if (
|
|
244
|
-
} else if (
|
|
246
|
+
if (netPnl > stats.bestTrade) stats.bestTrade = netPnl;
|
|
247
|
+
} else if (netPnl < 0) {
|
|
245
248
|
stats.losingTrades++;
|
|
246
|
-
stats.totalLossAmount += Math.abs(
|
|
249
|
+
stats.totalLossAmount += Math.abs(netPnl);
|
|
247
250
|
consecutiveLosses++;
|
|
248
251
|
consecutiveWins = 0;
|
|
249
252
|
if (consecutiveLosses > stats.maxConsecutiveLosses) stats.maxConsecutiveLosses = consecutiveLosses;
|
|
250
|
-
if (
|
|
253
|
+
if (netPnl < stats.worstTrade) stats.worstTrade = netPnl;
|
|
251
254
|
}
|
|
252
255
|
}
|
|
253
256
|
}
|
|
@@ -271,8 +274,12 @@ const showStats = async (service) => {
|
|
|
271
274
|
const longWinRate = stats.longTrades > 0 ? ((stats.longWins / stats.longTrades) * 100).toFixed(1) : 'N/A';
|
|
272
275
|
const shortWinRate = stats.shortTrades > 0 ? ((stats.shortWins / stats.shortTrades) * 100).toFixed(1) : 'N/A';
|
|
273
276
|
|
|
274
|
-
// Quantitative metrics (calculated from completed trades only)
|
|
275
|
-
const tradePnLs = completedTrades.map(t =>
|
|
277
|
+
// Quantitative metrics (calculated from completed trades only, with fees)
|
|
278
|
+
const tradePnLs = completedTrades.map(t => {
|
|
279
|
+
const grossPnl = t.profitAndLoss || t.pnl || 0;
|
|
280
|
+
const fees = Math.abs(t.fees || t.commission || 0);
|
|
281
|
+
return grossPnl - fees; // Net P&L
|
|
282
|
+
});
|
|
276
283
|
const avgReturn = tradePnLs.length > 0 ? tradePnLs.reduce((a, b) => a + b, 0) / tradePnLs.length : 0;
|
|
277
284
|
|
|
278
285
|
// Standard deviation
|