当前位置: 首页>>代码示例>>C#>>正文


C# Money.Abs方法代码示例

本文整理汇总了C#中Money.Abs方法的典型用法代码示例。如果您正苦于以下问题:C# Money.Abs方法的具体用法?C# Money.Abs怎么用?C# Money.Abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Money的用法示例。


在下文中一共展示了Money.Abs方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckMaximalRoundOffError

        public static void CheckMaximalRoundOffError(bool isSizeBased, InstrumentSize size, Money amount, Price price, Money accruedInterest, Side side)
        {
            if (!isSizeBased)
            {
                InstrumentSize calcAmt = size.CalculateAmount(price) * (decimal)side * -1M;
                //if (accruedInterest != null && accruedInterest.IsNotZero)
                //{
                //    accruedInterest = accruedInterest.Abs() * (decimal)side * -1M;
                //    calcAmt += accruedInterest;
                //}

                InstrumentSize diff = (calcAmt.Abs() - amount.Abs());
                if (diff.IsNotZero && !diff.IsWithinTolerance(0.02m))
                {
                    decimal percLeft = diff.Abs().Quantity / amount.Abs().Quantity;
                    if (percLeft >= 0.05m)
                        throw new ApplicationException(string.Format(
                            "Price times Size ({0}) differs by {1}% from the provided Amount ({2}). Order cannot be filled.",
                            calcAmt.DisplayString, Math.Round(percLeft * 100m, 1), amount.DisplayString));
                }
            }
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:22,代码来源:OrderP4.cs

示例2: MoneyTransferOrder

        public MoneyTransferOrder(IEffectenGiro stichtingDetails,
                            Money amount,
                            ICustomerAccount transfereeAccount,
                            ICounterAccount transfereeCounterAccount,
                            string transferDescription1,
                            string transferDescription2,
                            string transferDescription3,
                            string transferDescription4,
                            DateTime processDate,
                            string narBenef1,
                            string narBenef2,
                            string narBenef3,
                            string narBenef4,
                            IndicationOfCosts costIndication)
        {
            this.CreatedBy = B4F.TotalGiro.Security.SecurityManager.CurrentUser;
            this.TransferorJournal = stichtingDetails.DefaultWithdrawJournal;
            this.NarDebet1 = stichtingDetails.StichtingName;
            this.NarDebet2 = stichtingDetails.ResidentialAddress.AddressLine1;
            this.NarDebet3 = stichtingDetails.ResidentialAddress.AddressLine2;
            this.NarDebet4 = stichtingDetails.ResidentialAddress.Country.CountryName;

            this.ProcessDate = processDate;
            if (amount != null)
                this.Amount = amount.Abs();
            this.TransfereeAccount = transfereeAccount;
            this.TransfereeCounterAccount = transfereeCounterAccount;

            this.NarBenef1 = narBenef1;
            this.NarBenef2 = narBenef2;
            this.NarBenef3 = narBenef3;
            this.NarBenef4 = narBenef4;

            this.TransferDescription1 = transferDescription1;
            this.TransferDescription2 = transferDescription2;
            this.TransferDescription3 = transferDescription3;
            this.TransferDescription4 = transferDescription4;

            this.CostIndication = costIndication;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:40,代码来源:MoneyTransferOrder.cs

示例3: addFixMinMax

        private Money addFixMinMax(Money fee)
        {
            // Add Fixed setup
            if (FixedSetup != null && FixedSetup.IsNotZero)
            {
                fee += FixedSetupMonthly;
            }

            // Check Minimum Value
            if (MinValue != null && MinValue.IsNotZero && fee.Abs() < MinValueMonthly.Abs())
                fee = MinValueMonthly;

            // Check Maximum Value
            if (MaxValue != null && MaxValue.IsNotZero && fee.Abs() > MaxValueMonthly.Abs())
                fee = MaxValueMonthly;
            return fee;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:17,代码来源:FeeCalcVersionFlat.cs

示例4: InsertEndTermValue

        private static void InsertEndTermValue(IDalSession session, IPortfolioHistorical portfolio, IList<IJournalEntryLine> dividends, IPeriodicReporting reportingPeriod)
        {
            IAccountTypeInternal account = portfolio.ParentAccount;
            IEndTermValue etv = new EndTermValue(account, reportingPeriod);

            Money InternalDividend = new Money(0m, account.BaseCurrency);
            Money InternalDividendTax = new Money(0m, account.BaseCurrency);
            Money ExternalDividend = new Money(0m, account.BaseCurrency);
            Money ExternalDividendTax = new Money(0m, account.BaseCurrency);

            if (dividends != null)
            {
                List<IJournalEntryLine> divs = dividends.ToList();
                if (divs.Exists(d => d.GiroAccount.Key == account.Key))
                {
                    if (divs.Exists(d => d.GLAccount.IsGrossDividendInternal))
                        InternalDividend = divs.Where(d => (d.GLAccount.IsGrossDividendInternal && (d.GiroAccount.Key == account.Key))).Select(m => m.Balance.BaseAmount).Sum();
                    if (divs.Exists(d => d.GLAccount.IsDividendTaxInternal))
                        InternalDividendTax = divs.Where(d => (d.GLAccount.IsDividendTaxInternal && (d.GiroAccount.Key == account.Key))).Select(m => m.Balance.BaseAmount).Sum();
                    if (divs.Exists(d => d.GLAccount.IsGrossDividendExternal))
                        ExternalDividend = divs.Where(d => (d.GLAccount.IsGrossDividendExternal && (d.GiroAccount.Key == account.Key))).Select(m => m.Balance.BaseAmount).Sum();
                    if (divs.Exists(d => d.GLAccount.IsDividendTaxExternal))
                        ExternalDividendTax = divs.Where(d => (d.GLAccount.IsDividendTaxExternal && (d.GiroAccount.Key == account.Key))).Select(m => m.Balance.BaseAmount).Sum();
                }
            }

            etv.CashValue = portfolio.CashPortfolio.TotalPortfolioValue;
            etv.FundValue = portfolio.FundPortfolio.TotalPortfolioValue;
            etv.ClosingValue = etv.FundValue + etv.CashValue;
            etv.CultureFundValue = portfolio.FundPortfolio.CultureFundValue.Abs();
            etv.GreenFundValue = portfolio.FundPortfolio.GreenFundValue.Abs();
            etv.InternalDividend = InternalDividend.Abs();
            etv.InternalDividendTax = InternalDividendTax.Abs();
            etv.ExternalDividend = ExternalDividend.Abs();
            etv.ExternalDividendTax = ExternalDividendTax.Abs();
            session.InsertOrUpdate(etv);
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:37,代码来源:EndYearManagementAdapter.cs

示例5: setSignServiceCharge

 private void setSignServiceCharge(ref Money serviceCharge, ref decimal serviceChargePercentage)
 {
     // Set the sign of the ServiceCharge
     if (serviceCharge != null && serviceCharge.IsNotZero)
         serviceCharge = serviceCharge.Abs() * -1;
     serviceChargePercentage = Math.Abs(serviceChargePercentage);
 }
开发者ID:kiquenet,项目名称:B4F,代码行数:7,代码来源:OrderP4.cs

示例6: getTradeDifferenceOpenValue

 private InstrumentSize getTradeDifferenceOpenValue(InstrumentSize size, Money amount, Money serviceCharge, Money accruedInterest)
 {
     InstrumentSize diff;
     if (IsSizeBased)
         diff = (this.OpenValue.Abs() - size.Abs());
     else
         diff = (this.OpenValue.Abs() - amount.Abs() + serviceCharge + accruedInterest);
     return diff;
 }
开发者ID:kiquenet,项目名称:B4F,代码行数:9,代码来源:OrderP4.cs

示例7: Fill

        public IOrderExecution Fill(InstrumentSize size, Price price, Money amount, decimal exRate,
            IAccount counterParty, DateTime transactionDate, DateTime transactionDateTime, IExchange exchange,
            bool isCompleteFill, Money serviceCharge, decimal serviceChargePercentage, Money accruedInterest,
            ITradingJournalEntry tradingJournalEntry, IGLLookupRecords lookups)
        {
            IOrderExecution returnValue = null;

            if (size == null || price == null || amount == null)
                throw new Exception("Size, Price and Amount are mandatory when filling the order.");

            if (IsFillable != OrderFillability.True)
                throw new ApplicationException("This Order is not fillable.");

            setSignServiceCharge(ref serviceCharge, ref serviceChargePercentage);
            if (accruedInterest != null && accruedInterest.IsNotZero)
                accruedInterest = accruedInterest.Abs() * (decimal)this.Side * -1M;
            CheckMaximalRoundOffError(IsSizeBased, size, amount, price, accruedInterest, this.Side);

            if (isCompleteFill)
            {
                // Check whether the order has not been filled before
                if (Transactions.Count > 0)
                    throw new ApplicationException("The order has already been filled and so it can not be a complete fill.");

                if (this.OpenValue.IsZero)
                    throw new ApplicationException("The open value of this order is zero.");

                InstrumentSize diff = getTradeDifferenceOpenValue(size, amount, serviceCharge, accruedInterest);
                if (diff.IsNotZero)
                {
                    const decimal maxAllowed = 0.05m;
                    // TickSize && NominalValue
                    decimal tickSize = 0M;
                    if (this.OrderType == OrderTypes.SizeBased)
                    {
                        IInstrumentExchange ie = getInstrumentExchange(exchange);
                        if (ie != null)
                            tickSize = ie.TickSize;
                    }
                    if (this.RequestedInstrument.SecCategory.Key == SecCategories.Bond)
                        tickSize = ((IBond)this.RequestedInstrument).NominalValue.Quantity;

                    if (!(tickSize > 0M && Math.Abs(diff.Quantity / tickSize) < 1M))
                    {
                        decimal fillRatio = diff.Abs().Quantity / this.OpenValue.Abs().Quantity;
                        if (fillRatio > maxAllowed)
                            throw new ApplicationException(
                                string.Format("The size of this transaction is different from the order size by more than {0:0.##}%.", maxAllowed * 100));
                    }
                }
                amount.XRate = exRate;
            }
            else
            {
                orderInitialCheck(ref amount, size, exRate, serviceCharge, accruedInterest);
            }

            this.IsCompleteFilled = isCompleteFill;
            orderCheckSide(this.Side, ref amount, ref size);
            checkServiceChargePercentage(serviceCharge, serviceChargePercentage, amount);

            ListOfTransactionComponents[] components = packageComponents(amount, serviceCharge, accruedInterest);

            returnValue = new OrderExecution(this, counterParty, size, price, exRate, transactionDate, transactionDateTime, serviceChargePercentage, tradingJournalEntry, lookups, components);
            fillOrder(returnValue, size, price, amount, serviceCharge, accruedInterest);
            return returnValue;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:67,代码来源:OrderP4.cs

示例8: orderCheckSide

 protected bool orderCheckSide(Side side, ref Money amount, ref InstrumentSize size)
 {
     if (side == Side.Buy)
     {
         size = size.Abs();
         amount = amount.Abs() * -1;
     }
     else
     {
         size = size.Abs() * -1;
         amount = amount.Abs();
     }
     return true;
 }
开发者ID:kiquenet,项目名称:B4F,代码行数:14,代码来源:OrderP4.cs

示例9: calculateServiceChargeForAmountBasedOrder

        /// <summary>
        /// We need to calculate the serviceCharge for Netting.
        /// On the netted order, take the nett amount (minus service charge) and then add the service charge
        /// </summary>
        protected bool calculateServiceChargeForAmountBasedOrder(
            IExchange exchange, ref Money tradeAmount, 
            out Money serviceCharge, out decimal serviceChargePercentageforOrder)
        {
            bool retVal = false;
            serviceCharge = null;
            serviceChargePercentageforOrder = 0m;

            serviceChargePercentageforOrder = getServiceChargePercentageforOrder(exchange);

            // deduct ServiceCharge
            if (serviceChargePercentageforOrder > 0)
            {
                Money newAmount = tradeAmount * (decimal)(1M / (1M + serviceChargePercentageforOrder));
                serviceCharge = (tradeAmount.Abs() - newAmount.Abs()) * -1M;
                tradeAmount = newAmount;
                retVal = true;
            }
            return retVal;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:24,代码来源:OrderP4.cs

示例10: getCommAmount

 protected Money getCommAmount(Money amount)
 {
     Money result = new Money(0m, CommCurrency);
     Money comAmount = amount.Abs();
     if (!comAmount.Underlying.Equals(this.CommCurrency))
         comAmount = comAmount.Convert(this.CommCurrency);
     return comAmount;
 }
开发者ID:kiquenet,项目名称:B4F,代码行数:8,代码来源:CommCalc.cs

示例11: getTransactionFillDetailsAmountBasedOrderByGoalSeek

        protected virtual TransactionFillDetails getTransactionFillDetailsAmountBasedOrderByGoalSeek(
            Money grossAmount, Side side, bool isCommissionRelevant, bool isValueInclComm,
            DateTime settlementDate, Price price, IExchange exchange,
            ICommRule rule, ICommClient client, decimal servChargePerc, int precision)
        {
            decimal realAmount;
            decimal guess = grossAmount.Abs().CalculateSize(price).Quantity;
            FinancialMath.MaxCycles = 200;

            // Check -> use Commission
            bool useComm = true;
            bool useAddComm = false;
            if (!isCommissionRelevant || rule == null)
                useComm = false;

            if (useComm)
                useAddComm = (rule.AdditionalCalculation != null);

            realAmount = FinancialMath.GoalSeek(x =>
                new InstrumentSize(x, this).CalculateAmount(price).Quantity +
                (useComm ? rule.CommCalculation.Calculate(client.GetNewInstance(new InstrumentSize(x, this), price, (useAddComm ? rule.AdditionalCalculation.Calculate(client.GetNewInstance(new InstrumentSize(x, this), price)) : null))).Quantity : 0M) +
                (useAddComm ? rule.AdditionalCalculation.Calculate(client.GetNewInstance(new InstrumentSize(x, this), price)).Quantity : 0M) +
                (new InstrumentSize(x, this).CalculateAmount(price).Abs().Quantity * servChargePerc),
                grossAmount.Abs().Quantity, guess, precision);

            InstrumentSize size = new InstrumentSize(realAmount, this);
            Money amount = size.CalculateAmount(price);
            InstrumentSize cleanSize = amount.CalculateSize(price);

            Money servCh = (amount.Abs() * servChargePerc);
            Money comm = amount.ZeroedAmount();
            Money addComm = amount.ZeroedAmount();
            if (useComm)
            {
                if (rule.AdditionalCalculation != null)
                    addComm = rule.AdditionalCalculation.Calculate(client.GetNewInstance(cleanSize, price));
                comm = rule.CommCalculation.Calculate(client.GetNewInstance(cleanSize, price, addComm));

                // if sell -> comm is already in the amount
                if (side == Side.Sell && (comm + addComm) != null && (comm + addComm).IsNotZero)
                {
                    amount += (comm + addComm);
                    cleanSize = amount.CalculateSize(price);
                    if (!isValueInclComm)
                    {
                        if (rule.AdditionalCalculation != null)
                            addComm = rule.AdditionalCalculation.Calculate(client.GetNewInstance(cleanSize, price));
                        comm = rule.CommCalculation.Calculate(client.GetNewInstance(cleanSize, price, addComm));
                    }
                }
            }
            return new TransactionFillDetails(cleanSize, amount, null, servCh, servChargePerc, comm + addComm, grossAmount.Abs(), side);
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:53,代码来源:TradeableInstrument.cs

示例12: CalculateBackwards

        /// <summary>
        /// Calculates a fee so that the fee plus the net amount (of the order) equals the gross amount.
        /// </summary>
        /// <param name="grossAmount">The gross amount.</param>
        /// <param name="side">The side of the order/transaction.</param>
        /// <param name="price">The price of the order/transaction.</param>
        /// <param name="fee">The calculated fee (<b>out</b> parameter).</param>
        /// <returns><b>true</b> if fee could be calculated (net amount fell on this line), <b>false</b> if not.</returns>
        public virtual bool CalculateBackwards(Money grossAmount, Price price, Side side, out Tuple<InstrumentSize, Money> result)
        {
            bool success = false;

            if (price == null)
                throw new ApplicationException("It is not possible to calculate the commission when there is no current price.");

            decimal sideFactor = (side == Side.Buy ? 1M : -1M);
            Money fixedSetup = Parent.FixedSetup + StaticChargeAmount;
            Money nettAmount = (grossAmount.Abs() - (fixedSetup * sideFactor)) / ((Tariff.CalculateSize(price).Quantity + sideFactor));

            Money fee = grossAmount.Abs() - (nettAmount * sideFactor);
            InstrumentSize size = nettAmount.CalculateSize(price);

            result = new Tuple<InstrumentSize, Money>(size, fee);

            // Check if within range
            if (Envelops(size.Abs()))
                success = true;
            return success;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:29,代码来源:CommCalcLineSizeBased.cs

示例13: IsOrderValueWithinTolerance

        /// <summary>
        /// Checks the value against the tolerance parameters (but only wheb they are set)
        /// </summary>
        /// <param name="orderValue">The value to check</param>
        /// <param name="totalPortfolioValue">The total portfolio value</param>
        /// <returns></returns>
        public bool IsOrderValueWithinTolerance(Money orderValue, Money totalPortfolioValue)
        {
            bool retVal = false;
            Money orderVal;

            if (IsToleranceParameterSet)
            {
                switch (PricingType)
                {
                    case PricingTypes.Direct:
                        orderVal = orderValue.Abs();
                        if (!orderVal.Underlying.Equals(MinimumRebalanceAmount.Underlying))
                            orderVal = orderVal.Convert((ICurrency)MinimumRebalanceAmount.Underlying);

                        if (orderVal >= MinimumRebalanceAmount)
                            retVal = true;
                        break;
                    case PricingTypes.Percentage:
                        orderVal = orderValue.Abs();
                        if (!orderVal.Underlying.Equals(totalPortfolioValue.Underlying))
                            orderVal = orderVal.Convert((ICurrency)totalPortfolioValue.Underlying);

                        decimal perc = orderVal.Quantity / totalPortfolioValue.Abs().Quantity;
                        if (perc >= MinimumRebalancePercentage)
                            retVal = true;
                        break;
                }
            }
            else
                retVal = true;
            return retVal;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:38,代码来源:InstructionEngineParameters.cs

示例14: AddTransferFee

        public bool AddTransferFee(Money transferFee, IGLLookupRecords lookups, string description)
        {
            bool success = false;
            if (transferFee == null || lookups == null)
                throw new ApplicationException("It is not possible to add transfer fee since not all parameters are valid.");

            IGeneralOperationsComponent comp = Components.Where(u => u.BookingComponentType == BookingComponentTypes.CashTransfer).FirstOrDefault();
            if (!(comp != null && comp.MainLine != null && comp.MainLine.IsAllowedToAddTransferFee))
                throw new ApplicationException("It is not possible to add transfer fee to this transfer.");

            if (TransferFee != null && TransferFee.IsNotZero)
                throw new ApplicationException("It is not possible to add transfer fee more than once.");

            if (transferFee.Sign || transferFee.Abs().Quantity > TransferAmount.Abs().Quantity)
                throw new ApplicationException("The transfer fee can not be higher than the transfer amount.");

            if (transferFee != null && transferFee.IsNotZero)
            {
                ICashTransferComponent newComponent = new CashTransferComponent(this, BookingComponentTypes.CashTransferFee, this.CreationDate);
                newComponent.AddLinesToComponent(transferFee, BookingComponentTypes.CashTransferFee, true, false, false, lookups, Account);
                newComponent.Component.SetDescription(description);
                this.Components.Add(newComponent);
                success = true;
            }
            return success;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:26,代码来源:CashTransfer.cs


注:本文中的Money.Abs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。