/// <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)); }
/// <summary> /// Parses the object and checks if all the restraints of the 2D Point Function /// have been respected, if not will return an error to the parser. /// </summary> /// <remarks> /// Note that this method caches the object status, so any changes done to its data /// will require this method to be called again in order to update the cache. /// </remarks> /// <param name="context">The project in which to parse the object.</param> /// <returns>True if an error occurred during the parsing, False otherwise.</returns> public override bool Parse(IProject context) { try { this.function = new CPointFunction2D(this.coordinatesX, this.coordinatesY, this.values, this.interpolationType, this.extrapolationType); CreateSymbol(context as Project); } catch (Exception e) { string msg = e.Message + " for the 2D Function " + base.Name; if (context != null) { context.AddError(msg); } else { throw e; } // Return true as an error was raised during the parsing. return(true); } // Return false as no error have raised during the parsing. return(false); }
/// <summary> /// Retrieves zr and dy curve from the model. /// </summary> /// <param name="p_Context">The parameter is not used.</param> /// <param name="errors"> /// The current status of errors, if errors happened previously to this call. /// </param> /// <returns>True if there have been errors during this call or before.</returns> private bool RetrieveCurve(IProject p_Context, bool errors) { // check the presence of a zero rate curve object zrref = Engine.Parser.EvaluateAsReference(this.zrReference.Expression); if (!Engine.Parser.GetParserError()) { this.zrCurve = zrref as Function; if (this.zrCurve == null) { errors = true; p_Context.AddError("Cannot find the zero rate curve " + this.zrReference.Expression); } } else { errors = true; } // check the presence of a dividend yield curve object dyref = Engine.Parser.EvaluateAsReference(this.dyReference.Expression); if (!Engine.Parser.GetParserError()) { this.dyCurve = dyref as Function; if (this.dyCurve == null) { errors = true; p_Context.AddError("Cannot find the dividend yield curve " + this.dyReference.Expression); } } else { errors = true; } return(errors); }
/// <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); }
/// <summary> /// Validates the data of the object. /// </summary> /// <returns>true if the data has been successfully validated, false otherwise.</returns> private bool Validation(IProject p_Context) { if (ValidVectorRef()) { return(true); } else { // The start date must antecede than the end date bool valid = this.StartDate.CompareTo(EndDate) <= 0; if (!valid && p_Context != null) { p_Context.AddError("Date Sequence " + VarName + " is not valid: 'Start Date' must antecede 'End Date'"); } return(valid); } }
/// <summary> /// Validates the data of the object. /// </summary> /// <returns>true if the data has been successfully validated, false otherwise.</returns> private bool Validation(IProject p_Context) { // The start date must antecede than the end date bool valid=this.StartDate.CompareTo(EndDate) <= 0; if (!valid && p_Context != null) { p_Context.AddError("Date Sequence " + VarName + " is not valid: 'Start Date' must antecede 'End Date'"); } return valid; }
/// <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; }
/// <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); }
/// <summary> /// Parses the object and checks if all the restraints of the 2D Point Function /// have been respected, if not will return an error to the parser. /// </summary> /// <remarks> /// Note that this method caches the object status, so any changes done to its data /// will require this method to be called again in order to update the cache. /// </remarks> /// <param name="context">The project in which to parse the object.</param> /// <returns>True if an error occurred during the parsing, False otherwise.</returns> public override bool Parse(IProject context) { try { this.function = new CPointFunction2D(this.coordinatesX, this.coordinatesY, this.values, this.interpolationType, this.extrapolationType); CreateSymbol(context as Project); } catch (Exception e) { string msg = e.Message + " for the 2D Function " + base.Name; if (context != null) { context.AddError(msg); } else { throw e; } // Return true as an error was raised during the parsing. return true; } // Return false as no error have raised during the parsing. return false; }
/// <summary> /// Retrieves zr and dy curve from the model. /// </summary> /// <param name="p_Context">The parameter is not used.</param> /// <param name="errors"> /// The current status of errors, if errors happened previously to this call. /// </param> /// <returns>True if there have been errors during this call or before.</returns> private bool RetrieveCurve(IProject p_Context, bool errors) { // check the presence of a zero rate curve object zrref = Engine.Parser.EvaluateAsReference(this.r.Expression); if (!Engine.Parser.GetParserError()) { this.zrCurve = zrref as Function; if (this.zrCurve == null) { errors = true; p_Context.AddError("Cannot find the zero rate curve " + this.r.Expression); } } else errors = true; // check the presence of a dividend yield curve object dyref = Engine.Parser.EvaluateAsReference(this.q.Expression); if (!Engine.Parser.GetParserError()) { this.dyCurve = dyref as Function; if (this.dyCurve == null) { errors = true; p_Context.AddError("Cannot find the dividend yield curve " + this.q.Expression); } } else errors = true; return errors; }
/// <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; }
/// <summary> /// Parses the object. /// </summary> /// <param name="context">The project in which to parse the object.</param> /// <returns>True if an error occurred during the parsing, False otherwise.</returns> public override bool Parse(IProject context) { try { function = new CPointFunction2D(cordinatesX, cordinatesY, values, interpolationType, extrapolationType); } catch (Exception e) { context.AddError(e.Message + " for the 2D Function " + base.Name); return false; } return base.Parse(context); }
/// <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); }