예제 #1
0
        internal CurrencyRate GetCGSELevyCurrencyRate(Account account, Instrument instrument, CurrencyRate originCurrencyRate, ExecuteContext context)
        {
            if (this.CGSELevyCurrecyType == CGSELevyCurrecyType.UseInstrumentCurrencyType)
            {
                return(originCurrencyRate);
            }
            Guid sourceCurrencyId = account.CurrencyId;
            Guid targetCurrencyId = account.IsMultiCurrency ? instrument.CurrencyId : account.CurrencyId;

            return(!context.ShouldUseHistorySettings ? Setting.Default.GetCurrencyRate(sourceCurrencyId, targetCurrencyId)
                : Setting.Default.GetCurrencyRate(sourceCurrencyId, targetCurrencyId, context.TradeDay));
        }
예제 #2
0
        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));
            }
        }