Skip to content

Commit 973e583

Browse files
committed
Fix profit loss calculation
1 parent b1b5127 commit 973e583

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/app/autopilot/autopilot.component.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,26 @@ export class AutopilotComponent implements OnInit, OnDestroy {
295295
for (const recordKey in lastProfitLoss.profitRecord) {
296296
if (lastProfitLoss.profitRecord[recordKey]) {
297297
if (tempProfitRecord[recordKey]) {
298-
tempProfitRecord[recordKey] += round(lastProfitLoss.profitRecord[recordKey], 2);
298+
tempProfitRecord[recordKey] += Number(lastProfitLoss.profitRecord[recordKey].toFixed(2));
299299
}
300300
} else {
301301
if (tempProfitRecord[recordKey]) {
302-
tempProfitRecord[recordKey] = round(Number(lastProfitLoss.profitRecord[recordKey]), 2);
302+
tempProfitRecord[recordKey] = Number(lastProfitLoss.profitRecord[recordKey].toFixed(2));
303303
}
304304
}
305305
}
306306
}
307+
308+
let profit = 0;
309+
for (let key in tempProfitRecord) {
310+
if (tempProfitRecord[key]) {
311+
profit += Number(tempProfitRecord[key].toFixed(2));
312+
}
313+
}
314+
307315
const profitObj: ProfitLossRecord = {
308316
'date': moment().format(),
309-
profit: this.scoreKeeperService.total,
317+
profit: profit,
310318
lastStrategy: this.strategyList[this.strategyCounter],
311319
lastRiskTolerance: this.riskCounter,
312320
profitRecord: tempProfitRecord

0 commit comments

Comments
 (0)