Exemplo n.º 1
0
        /// <summary>
        /// Ensure the parameters are correct.
        /// </summary>
        /// <param name='p_Context'>
        /// The underlying project.
        /// </param>
        /// <returns>
        /// False if the parameter were correct.
        /// </returns>
        public bool Parse(IProject p_Context)
        {
            bool errors             = false;
            List <IExportable> list = this.ExportObjects(false);

            foreach (IExportable parameter in list)
            {
                if (parameter is IParsable)
                {
                    BoolHelper.AddBool(errors, (parameter as IParsable).Parse(p_Context));
                }
            }

            if (this.zrReference.Expression.IndexOf("@") == -1)
            {
                p_Context.AddError(this.zrReference.Expression +
                                   " is not a reference to a zero rate curve");
            }

            if (this.dyReference.Expression.IndexOf("@") == -1)
            {
                p_Context.AddError(this.dyReference.Expression +
                                   " is not a reference to a dividend yield curve");
            }

            return(RetrieveCurve(p_Context, errors));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ensure the parameters are correct.
        /// </summary>
        /// <param name='context'>
        /// The underlying project.
        /// </param>
        /// <returns>
        /// False if there were no parse errors.
        /// </returns>
        public bool Parse(IProject context)
        {
            bool errors = false;

            errors = BoolHelper.AddBool(errors, this.startingValue1.Parse(context));
            errors = BoolHelper.AddBool(errors, this.startingValue2.Parse(context));
            errors = BoolHelper.AddBool(errors, this.k1.Parse(context));
            errors = BoolHelper.AddBool(errors, this.k2.Parse(context));
            errors = BoolHelper.AddBool(errors, this.theta1.Parse(context));
            errors = BoolHelper.AddBool(errors, this.theta2.Parse(context));
            errors = BoolHelper.AddBool(errors, this.sigma1.Parse(context));
            errors = BoolHelper.AddBool(errors, this.sigma2.Parse(context));

            errors = BoolHelper.AddBool(errors, this.ZRReference.Parse(context));

            // Stores some temporary parameters derived from the main model parameters.
            if (!errors)
            {
                this.zr = (Function)this.ZRReference.fVRef();

                // In this way they are not stochastic.
                this.k12     = Math.Pow(this.k1.fV(), 2);
                this.k22     = Math.Pow(this.k2.fV(), 2);
                this.sigma12 = Math.Pow(this.sigma1.fV(), 2);
                this.sigma22 = Math.Pow(this.sigma2.fV(), 2);
                this.gamma1  = Math.Sqrt(this.k12 + 2 * this.sigma12);
                this.gamma2  = Math.Sqrt(this.k22 + 2 * this.sigma22);
            }

            return(errors);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Ensure the parameters are correct.
        /// </summary>
        /// <param name='context'>
        /// The underlying project.
        /// </param>
        /// <returns>
        /// False if there were no parse errors.
        /// </returns>
        public bool Parse(IProject context)
        {
            bool errors = false;

            BoolHelper.AddBool(errors, this.s0.Parse(context));
            BoolHelper.AddBool(errors, this.theta.Parse(context));
            BoolHelper.AddBool(errors, this.sigma.Parse(context));
            BoolHelper.AddBool(errors, this.nu.Parse(context));
            BoolHelper.AddBool(errors, this.rate.Parse(context));
            BoolHelper.AddBool(errors, this.dividend.Parse(context));
            return(errors);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Ensure the parameters are correct.
        /// </summary>
        /// <param name='p_Context'>
        /// The underlying project.
        /// </param>
        /// <returns>
        /// False if the parameter were correct.
        /// </returns>
        public bool Parse(IProject p_Context)
        {
            bool errors             = false;
            List <IExportable> list = this.ExportObjects(false);

            foreach (IExportable parameter in list)
            {
                if (parameter is IParsable)
                {
                    BoolHelper.AddBool(errors, (parameter as IParsable).Parse(p_Context));
                }
            }

            return(errors);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parses the process (in this case nothing has to be done).
        /// </summary>
        /// <param name="context">The project representing the context of the parsing.</param>
        /// <returns>true if the the parsing caused errors; otherwise false.</returns>
        public bool Parse(IProject context)
        {
            bool errors = false;

            errors = this.s0.Parse(context);
            errors = BoolHelper.AddBool(errors, this.q.Parse(context));
            errors = BoolHelper.AddBool(errors, this.r.Parse(context));
            errors = BoolHelper.AddBool(errors, this.localVol.Parse(context));

            this.context          = new DupireContext();
            this.context.s0       = this.s0.fV();
            this.context.q        = this.q.fVRef() as IFunction;
            this.context.r        = this.r.fVRef() as IFunction;
            this.context.localVol = this.localVol.fVRef() as IFunction;

            return(RetrieveCurve(context, errors));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Ensure the parameters are correct.
        /// </summary>
        /// <param name='context'>
        /// The underlying project.
        /// </param>
        /// <returns>
        /// False if there were no parse errors.
        /// </returns>
        public bool Parse(IProject context)
        {
            bool errors = false;

            BoolHelper.AddBool(errors, this.k.Parse(context));
            BoolHelper.AddBool(errors, this.theta.Parse(context));
            BoolHelper.AddBool(errors, this.sigma.Parse(context));
            BoolHelper.AddBool(errors, this.r0.Parse(context));

            if (!errors)
            {
                this.alphaTemp = this.k.fV();
                this.gammaTemp = this.theta.fV();
                this.sigmaTemp = this.sigma.fV();
            }

            return(errors);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Ensure the parameters are correct.
        /// </summary>
        /// <param name='p_Context'>
        /// The underlying project.
        /// </param>
        /// <returns>
        /// False if there were no parse errors.
        /// </returns>
        public bool Parse(IProject p_Context)
        {
            bool errors = false;

            BoolHelper.AddBool(errors, this.a1.Parse(p_Context));
            BoolHelper.AddBool(errors, this.sigma1.Parse(p_Context));

            if (this.zr.Expression.IndexOf("@") == -1)
            {
                p_Context.AddError(this.zr.Expression + " is not a reference to a zero rate curve");
            }

            object zrReference = Engine.Parser.EvaluateAsReference(this.zr.Expression);

            if (!Engine.Parser.GetParserError())
            {
                this.zeroRateCurve = zrReference as Function;
                if (this.zeroRateCurve == null)
                {
                    errors = true;

                    p_Context.AddError("Cannot find the Zero Rate Curve! " + this.zr.Expression);
                }
            }
            else
            {
                errors = true;
            }

            if (!errors)
            {
                this.alpha1Temp        = this.a1.fV();
                this.sigma1Temp        = this.sigma1.fV();
                this.sigma1SquaredTemp = Math.Pow(this.sigma1Temp, 2);
                CalculateGamma();
            }

            return(errors);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Parses the data and ensures the parameters are correct.
        /// </summary>
        /// <param name='p_Context'>
        /// The underlying project.
        /// </param>
        /// <returns>
        /// False if there were no parse errors.
        /// </returns>
        public bool Parse(IProject p_Context)
        {
            this.context = p_Context as Project;
            bool errors = false;

            BoolHelper.AddBool(errors, this._a1.Parse(p_Context));
            BoolHelper.AddBool(errors, this._a2.Parse(p_Context));

            BoolHelper.AddBool(errors, this._s1.Parse(p_Context));
            BoolHelper.AddBool(errors, this._s2.Parse(p_Context));
            BoolHelper.AddBool(errors, this._rho.Parse(p_Context));

            BoolHelper.AddBool(errors, this.driftAdjustment.Parse(p_Context));

            if (this._zr.Expression.IndexOf("@") == -1)
            {
                p_Context.AddError(this._zr.Expression +
                                   " is not a reference to a zero rate curve");
            }

            // Checks for the model constraints: alpha1 != alhpa2
            if (Math.Abs(this._a1.fV() - this._a2.fV()) < 10e-5)
            {
                p_Context.AddError("H&W2:  alpha1 and alpha2 must be different");
            }

            object zr_reference = Engine.Parser.EvaluateAsReference(this._zr.Expression);

            if (!Engine.Parser.GetParserError())
            {
                this.zeroRateCurve = zr_reference as Function;
                if (this.zeroRateCurve == null)
                {
                    errors = true;
                    p_Context.AddError("Cannot find the Zero Rate Curve! " + this._zr.Expression);
                }
            }
            else
            {
                errors = true;
            }

            if (!errors)
            {
                base.alpha1     = this._a1.fV();
                base.sigma1     = this._s1.fV();
                this.sigma1Pow2 = System.Math.Pow(this._s1.fV(), 2);
            }

            CorrelationMatrix R = (p_Context as ProjectProcess).Processes.r;
            int index           = (p_Context as ProjectProcess).Processes.GetProcessCorrelationIndex(this);

            // Index is -1 is when the process is not still in the process list.
            if (index != -1)
            {
                // Updates the correlation in the global correlation matrix.
                R.Set(index, index + 1, this._rho);
            }

            return(errors);
        }