value method

Implementation

@override
MatexProfitAndLossResult value() {
  if (result != null) {
    return result!;
  }

  if (isValid) {
    final dGrossBuyPrice = _computeGrossBuyPrice();
    final dEntryCosts = _computeEntryCosts(dGrossBuyPrice);
    final dGrossSellPrice = _computeGrossSellPrice();
    final dExitCosts = _computeExitCosts(dGrossSellPrice);
    final dNetBuyPrice = _computeNetGrossPrice(
      dGrossBuyPrice,
      dEntryCosts,
    );
    final dNetSellPrice = _computeNetSellPrice(
      dGrossSellPrice,
      dExitCosts,
    );
    final dGrossPnl = computeGrossProfitOrLoss(
      dGrossBuyPrice,
      dGrossSellPrice,
    );

    final dFixedCosts = state.fixedCosts != null
        ? MatexDecimal.fromDouble(state.fixedCosts!)
        : Decimal.zero;
    final dTotalCosts = dEntryCosts + dExitCosts + dFixedCosts;
    final dNetPnl = dGrossPnl - dTotalCosts;
    final dTaxAmount = computeTaxAmount(dNetPnl);
    final dNetPnlAfterTaxe = dNetPnl - dTaxAmount;
    final dROI = computeReturnOnInvestment(dNetBuyPrice, dNetPnlAfterTaxe);
    final dBreakEvenUnits = _computBreakEvenUnits(
      dFixedCosts,
      dGrossSellPrice,
      dGrossBuyPrice,
      dEntryCosts,
      dExitCosts,
    );

    return MatexProfitAndLossResult(
      totalCosts: dTotalCosts.toDouble(),
      entryCostsAmount: dEntryCosts.toDouble(),
      exitCostsAmount: dExitCosts.toDouble(),
      grossSellPrice: dGrossSellPrice.toDouble(),
      grossBuyPrice: dGrossBuyPrice.toDouble(),
      netSellPrice: dNetSellPrice.toDouble(),
      netBuyPrice: dNetBuyPrice.toDouble(),
      profitOrLoss: dNetPnlAfterTaxe.toDouble(),
      returnOnInvestement: dROI.toDouble(),
      taxAmount: dTaxAmount.toDouble(),
      breakEvenUnits: dBreakEvenUnits.toDouble(),
    );
  }

  return const MatexProfitAndLossResult();
}