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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/pages/stats.js +18 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedgequantx",
3
- "version": "2.4.35",
3
+ "version": "2.4.36",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -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 pnl = trade.profitAndLoss || trade.pnl || 0;
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 (pnl > 0) stats.longWins++;
234
+ if (netPnl > 0) stats.longWins++;
232
235
  } else if (exitSide === 0) {
233
236
  stats.shortTrades++;
234
- if (pnl > 0) stats.shortWins++;
237
+ if (netPnl > 0) stats.shortWins++;
235
238
  }
236
239
 
237
- if (pnl > 0) {
240
+ if (netPnl > 0) {
238
241
  stats.winningTrades++;
239
- stats.totalWinAmount += pnl;
242
+ stats.totalWinAmount += netPnl;
240
243
  consecutiveWins++;
241
244
  consecutiveLosses = 0;
242
245
  if (consecutiveWins > stats.maxConsecutiveWins) stats.maxConsecutiveWins = consecutiveWins;
243
- if (pnl > stats.bestTrade) stats.bestTrade = pnl;
244
- } else if (pnl < 0) {
246
+ if (netPnl > stats.bestTrade) stats.bestTrade = netPnl;
247
+ } else if (netPnl < 0) {
245
248
  stats.losingTrades++;
246
- stats.totalLossAmount += Math.abs(pnl);
249
+ stats.totalLossAmount += Math.abs(netPnl);
247
250
  consecutiveLosses++;
248
251
  consecutiveWins = 0;
249
252
  if (consecutiveLosses > stats.maxConsecutiveLosses) stats.maxConsecutiveLosses = consecutiveLosses;
250
- if (pnl < stats.worstTrade) stats.worstTrade = pnl;
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 => t.profitAndLoss || t.pnl || 0);
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