Exemple #1
0
        private double get_amorlinc(double fCost, DateTime nDate, DateTime nFirstPer, double fRestVal, int nPer, double fRate, int nBase)
        {
            double num  = fCost * fRate;
            double num2 = fCost - fRestVal;
            object obj2 = new CalcYearFracFunction().Evaluate(new object[] { nDate, nFirstPer, (int)nBase });

            if (!(obj2 is CalcError))
            {
                double num3 = (double)((double)obj2);
                double num4 = (num3 * fRate) * fCost;
                double num5 = ((fCost - fRestVal) - num4) / num;
                int    num6 = Convert.ToInt32((double)(((fCost - fRestVal) - num4) / num));
                if (nPer == 0)
                {
                    return(num4);
                }
                if (nPer <= num6)
                {
                    return(num * ((num5 < 1.0) ? num5 : 1.0));
                }
                if (nPer == (num6 + 1))
                {
                    return((num2 - (num * num6)) - num4);
                }
            }
            return(0.0);
        }
Exemple #2
0
        private double get_yieldmat(DateTime nSettle, DateTime nMat, DateTime nIssue, double fRate, double fPrice, int nBase)
        {
            CalcYearFracFunction function = new CalcYearFracFunction();
            double num  = function.Yearfrac(nIssue, nMat, nBase);
            double num2 = function.Yearfrac(nIssue, nSettle, nBase);
            double num3 = function.Yearfrac(nSettle, nMat, nBase);
            double num4 = 1.0 + (num * fRate);

            num4 /= (fPrice / 100.0) + (num2 * fRate);
            num4--;
            return(num4 / num3);
        }
Exemple #3
0
        private double get_amordegrc(double fCost, DateTime nDate, DateTime nFirstPer, double fRestVal, int nPer, double fRate, int nBase)
        {
            double num2;
            double num5 = 1.0 / fRate;

            if (num5 < 3.0)
            {
                num2 = 1.0;
            }
            else if (num5 < 5.0)
            {
                num2 = 1.5;
            }
            else if (num5 <= 6.0)
            {
                num2 = 2.0;
            }
            else
            {
                num2 = 2.5;
            }
            fRate *= num2;
            object obj2 = new CalcYearFracFunction().Evaluate(new object[] { nDate, nFirstPer, (int)nBase });

            if (obj2 is CalcError)
            {
                return(0.0);
            }
            double num6 = (double)((double)obj2);
            double num3 = Math.Floor((double)(((num6 * fRate) * fCost) + 0.5));

            fCost -= num3;
            double num4 = fCost - fRestVal;

            for (int i = 0; i < nPer; i++)
            {
                num3  = Math.Floor((double)((fRate * fCost) + 0.5));
                num4 -= num3;
                if (num4 < 0.0)
                {
                    switch ((nPer - i))
                    {
                    case 0:
                    case 1:
                        return(Math.Floor((double)((fCost * 0.5) + 0.5)));
                    }
                    return(0.0);
                }
                fCost -= num3;
            }
            return(num3);
        }
Exemple #4
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> annual yield for a discounted security.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 4 - 5 items: settlement, maturity, pr, redemption, [basis].
        /// </para>
        /// <para>
        /// Settlement is the security's settlement date.
        /// The security settlement date is the date after the issue date when the security is traded to the buyer.
        /// </para>
        /// <para>
        /// Maturity is the security's maturity date.
        /// The maturity date is the date when the security expires.
        /// </para>
        /// <para>
        /// Pr is the security's price per $100 face value.
        /// </para>
        /// <para>
        /// Redemption is the security's redemption value per $100 face value.
        /// </para>
        /// <para>
        /// Basis is the type of day count basis to use.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            DateTime             time     = CalcConvert.ToDateTime(args[0]);
            DateTime             time2    = CalcConvert.ToDateTime(args[1]);
            double               num      = CalcConvert.ToDouble(args[2]);
            double               num2     = CalcConvert.ToDouble(args[3]);
            int                  basis    = CalcHelper.ArgumentExists(args, 4) ? CalcConvert.ToInt(args[4]) : 0;
            CalcYearFracFunction function = new CalcYearFracFunction();

            if ((basis < 0) || (basis > 4))
            {
                return(CalcErrors.Number);
            }
            if (((num2 <= 0.0) || (num <= 0.0)) || (DateTime.Compare(time, time2) >= 0))
            {
                return(CalcErrors.Number);
            }
            double num4 = (num2 / num) - 1.0;
            double num5 = function.Yearfrac(time, time2, basis);

            return((double)(num4 / num5));
        }