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


C# Money.CalculateSize方法代码示例

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


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

示例1: PriceChanged

        public static void PriceChanged(OrderFillView orderFillView)
        {
            IDalSession session = NHSessionFactory.CreateSession();

            try
            {
                Price price;
                InstrumentSize size;
                Money amount;
                ITradeableInstrument tradedInstrument;

                IOrder order = OrderMapper.GetOrder(session, orderFillView.OrderId);

                if (!orderFillView.IsSizeBased)
                {
                    // Exchange rate (in base currency)
                    tradedInstrument = ((IOrderAmountBased)order).TradedInstrument;
                    price = new Price(orderFillView.Price, tradedInstrument.CurrencyNominal, tradedInstrument);
                    amount = new Money(orderFillView.Amount, (ICurrency)order.Value.Underlying);
                    if (tradedInstrument.CurrencyNominal.Key != amount.Underlying.Key)
                    {
                        if (!(tradedInstrument.CurrencyNominal.IsObsoleteCurrency && tradedInstrument.CurrencyNominal.ParentInstrument.Key == amount.Underlying.Key))
                            throw new ApplicationException("It is not possible to fill an order in a different currency.");
                    }
                    size = amount.CalculateSize(price);
                    orderFillView.Size = size.Quantity;
                }
                else
                {
                    tradedInstrument = ((IOrderSizeBased)order).TradedInstrument;
                    price = new Price(orderFillView.Price, tradedInstrument.CurrencyNominal, tradedInstrument);
                    size = new InstrumentSize(orderFillView.Size, tradedInstrument);
                    amount = size.CalculateAmount(price);
                    amount.XRate = orderFillView.ExchangeRate;
                    orderFillView.Amount = amount.Quantity;
                }

                // Check if the Price is still reliable
                IPriceDetail lastValidHistoricalPrice = HistoricalPriceMapper.GetLastValidHistoricalPrice(
                                                                                    session, tradedInstrument, orderFillView.TransactionDate);
                if (lastValidHistoricalPrice == null || lastValidHistoricalPrice.Price.IsZero)
                    orderFillView.Warning = string.Format("No price was found for {0:d}, so validation is not very reliable.",
                                                             orderFillView.TransactionDate);
                else
                {
                    // check if the price is within 1% of the last historical price
                    decimal rate = lastValidHistoricalPrice.Price.Quantity;

                    decimal diff = (price.Quantity - rate) / rate;
                    decimal diffPct = Math.Round(Math.Abs(diff), 4) * 100;
                    if (diffPct > 1)
                        orderFillView.Warning = string.Format("The price entered is {0:0.##}% {1} than the last known price for {2:d} ({3}).",
                                                              diffPct, (diff < 0 ? "lower" : "higher"), orderFillView.TransactionDate,
                                                              lastValidHistoricalPrice.Price.ShortDisplayString);

                    if (lastValidHistoricalPrice.WasOldDateBy(orderFillView.TransactionDate))
                        orderFillView.Warning += (orderFillView.Warning != string.Empty ? "\n" : "") +
                            string.Format("The last known price for {0:d} is {1} days old (last updated on {2:d}), so validation is not very reliable.",
                                          orderFillView.TransactionDate, (orderFillView.TransactionDate - lastValidHistoricalPrice.Date).Days,
                                          lastValidHistoricalPrice.Date);
                }
            }
            finally
            {
                session.Close();
            }
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:67,代码来源:ManualDeskAdapter.cs

示例2: PredictSize

        /// <summary>
        /// Get the educated guess of the size of a instrument for a amount of money
        /// </summary>
        /// <param name="inputAmount"></param>
        /// <returns></returns>
        public override PredictedSize PredictSize(Money inputAmount)
        {
            PredictedSize retVal = new PredictedSize(PredictedSizeReturnValue.NoRate);
            Money amount;

            if (CurrentPrice != null)
            {
                retVal.RateDate = CurrentPrice.Date;
                if (inputAmount.Underlying.Equals(CurrentPrice.Price.Underlying))
                    retVal.Size = inputAmount.CalculateSize(CurrentPrice.Price);
                else
                {
                    amount = inputAmount.Convert(CurrentPrice.Price.Underlying);
                    retVal.Size = amount.CalculateSize(CurrentPrice.Price);
                }
                retVal.Rate = currentPrice.Price.ToString();
            }
            return retVal;
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:24,代码来源:TradeableInstrument.cs

示例3: CalculateSizeBackwards

        public InstrumentSize CalculateSizeBackwards(Money amount, Price price, DateTime settlementDate)
        {
            if (price == null)
                throw new ApplicationException(string.Format("It is not possible to calculate the size of {0} without a price", Name));

            if (Util.IsNullDate(settlementDate))
                throw new ApplicationException(string.Format("It is not possible to calculate the size of {0} without a valid settlement date", Name));

            DateTime lastCouponPaymentDate;
            DateTime nextCouponPaymentDate;
            decimal factor = ai_Factor(settlementDate, null, out lastCouponPaymentDate, out nextCouponPaymentDate);

            // Calculate backwards the number of bonds
            return amount.CalculateSize((price + price.Clone(factor * GetCouponRate(lastCouponPaymentDate, settlementDate))));
        }
开发者ID:kiquenet,项目名称:B4F,代码行数:15,代码来源:Bond.cs


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