private void CalculatePhysicalPaymentDiscount(AllowedPaymentForm form, CurrencyRate currencyRate, ExecuteContext context) { var tradePolicyDetail = this.Owner.TradePolicyDetail(context.TradeDay); var physicalPaymentDiscountPolicy = tradePolicyDetail.PhysicalPaymentDiscountPolicy(context.TradeDay); if (physicalPaymentDiscountPolicy != null) { var physicalPaymentDiscount = physicalPaymentDiscountPolicy.CalculateDiscount(this.Lot, this.PhysicalOriginValue, form, currencyRate); this.AddBill(new Bill(this.AccountId, this.CurrencyId, physicalPaymentDiscount, BillType.PhysicalPaymentDiscount, BillOwnerType.Order, context.ExecuteTime ?? DateTime.Now)); } }
private Tuple <decimal, decimal> CalculatePaidPledgeForBuyTradeSide(CurrencyRate currencyRate, ExecuteContext context) { decimal paidPledge = 0m, paidPledgeBalance = 0m; AllowedPaymentForm form = AllowedPaymentForm.Fullpayment; if (this.IsInstalment) { decimal paidAmount = this.CalculatePaidAmountForPledge(); form = this.Instalment.Frequence == InstalmentFrequence.TillPayoff ? AllowedPaymentForm.AdvancePayment : AllowedPaymentForm.Instalment; this.CalculatePhysicalPaymentDiscount(form, currencyRate, context); paidPledge = paidPledgeBalance = -(Math.Round(paidAmount, currencyRate.TargetCurrency.Decimals, MidpointRounding.AwayFromZero) + this.PhysicalPaymentDiscount); } else { this.CalculatePhysicalPaymentDiscount(form, currencyRate, context); if (this.IsOpen) { paidPledge = paidPledgeBalance = -this.PhysicalOriginValue; } } return(Tuple.Create(paidPledge, paidPledgeBalance)); }
internal decimal CalculateDiscount(decimal lot, decimal marketValue, AllowedPaymentForm paymentForm, CurrencyRate currencyRate) { if ((paymentForm & this.AllowedPaymentForms) != paymentForm || this.Details.Count == 0) { return(0); } if (this.Option == DiscountOption.Flat) { PhysicalPaymentDiscountPolicyDetail detail = this.Details.FindLast(delegate(PhysicalPaymentDiscountPolicyDetail item) { return(lot > item.From); }); decimal discount = 0; if (detail != null) { if (this.DiscountBasis == DiscountBasis.UnitAmount) { discount = currencyRate.Exchange(lot * detail.DiscountValue); } else { discount = Math.Round(marketValue * detail.DiscountValue, currencyRate.TargetCurrency.Decimals, MidpointRounding.AwayFromZero); } } return(discount); } else if (this.Option == DiscountOption.Progressive) { decimal discount = 0; int index = 0; while (index < this.Details.Count && lot > this.Details[index].From) { PhysicalPaymentDiscountPolicyDetail detail = this.Details[index]; decimal calculateLot = lot - detail.From; if (index < this.Details.Count - 1) { decimal range = (this.Details[index + 1].From - detail.From); calculateLot = Math.Min(calculateLot, range); } decimal calculateValue = (marketValue * calculateLot) / lot; discount += this.DiscountBasis == DiscountBasis.UnitAmount ? calculateLot * detail.DiscountValue : calculateValue * detail.DiscountValue; index++; } if (this.DiscountBasis == DiscountBasis.UnitAmount) { discount = currencyRate.Exchange(discount); } else { discount = Math.Round(discount, currencyRate.TargetCurrency.Decimals, MidpointRounding.AwayFromZero); } return(discount); } else { throw new NotSupportedException(string.Format("Option = {0} is not supported", this.Option)); } }