Exemple #1
0
 private static Price MathOperation(Price lhs, Price rhs, MathOperator op)
 {
     if (((Object)rhs == null) && ((Object)lhs == null))
     {
         //throw new ApplicationException("Both Prices may not be Null!");
         return null;
     }
     else if (((Object)rhs == null) || ((Object)lhs == null))
     {
         if ((Object)rhs == null)
         {
             return (Price)lhs.MemberwiseClone();
         }
         else
         {
             switch (op)
             {
                 case MathOperator.Add:
                     return (Price)rhs.MemberwiseClone();
                 case MathOperator.Subtract:
                     return (rhs * -1);
                 default:
                     throw new ApplicationException("You did not select a valid math operation");
             }
         }
     }
     else
     {
         // Use Eq because it is not possible to do operator overloading on an interface
         if (!(lhs.Underlying.Equals(rhs.Underlying)))
         {
             throw new ApplicationException("Cannot add Two different currencies!");
         }
         else if (!(lhs.Instrument.Equals(rhs.Instrument)))
         {
             throw new ApplicationException("Cannot add Two different instruments!");
         }
         else
         {
             switch (op)
             {
                 case MathOperator.Add:
                     return lhs.Clone(lhs.Quantity + rhs.Quantity);
                 case MathOperator.Subtract:
                     return lhs.Clone(lhs.Quantity - rhs.Quantity);
                 default:
                     throw new ApplicationException("You did not select a valid math operation");
             }
         }
     }
 }
Exemple #2
0
        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))));
        }