Skip to content

Commit

Permalink
Fixed calculation of profit when closing deals
Browse files Browse the repository at this point in the history
  • Loading branch information
simba77 committed Aug 22, 2024
1 parent a7ab652 commit f8ae511
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Services/Deals/DealService.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,16 @@ private function getDealSum(SecurityDTO $securityDTO, SellDealRequestDTO $dealRe
$result = bcmul($result, (string) $dealRequestDTO->quantity, 4);
return bcadd($result, bcmul($securityDTO->bondAccumulatedCoupon, (string) $dealRequestDTO->quantity, 4), 4);
} elseif ($securityDTO->securityType === SecurityTypeEnum::Future) {
$result = bcmul($securityDTO->lotSize, $dealRequestDTO->price, 4);
$result = bcmul($result, (string) $dealRequestDTO->quantity, 4);
return bcsub($result, bcmul(bcmul($deal->getBuyPrice(), $securityDTO->lotSize, 4), (string) $dealRequestDTO->quantity, 4));
if ($securityDTO->lotSize < $dealRequestDTO->price) {
$sellLotPrice = $dealRequestDTO->price;
$buyLotPrice = $deal->getBuyPrice();
} else {
$sellLotPrice = bcmul($securityDTO->lotSize, $dealRequestDTO->price, 4);
$buyLotPrice = bcmul($deal->getBuyPrice(), $securityDTO->lotSize, 4);
}
$sellFullPrice = bcmul($sellLotPrice, (string) $dealRequestDTO->quantity, 4);
$buyFullPrice = bcmul($buyLotPrice, (string) $dealRequestDTO->quantity, 4);
return bcsub($sellFullPrice, $buyFullPrice);
}
return '0';
}
Expand Down

0 comments on commit f8ae511

Please sign in to comment.