/// <summary> /// Get a point from the implied vol surface /// </summary> /// <param name="t">date in double</param> /// <param name="k">strike</param> /// <returns></returns> public double GetValue(double t, double k) { //check if the point is out of range var axisX1InDouble = RowGrid.Select(item => _dayCount.CalcDayCountFraction(ValuationDate, item)).ToList(); if (t < axisX1InDouble.Min() || t > axisX1InDouble.Max() || k < ColGrid.Min() || k > ColGrid.Max()) { throw new PricingLibraryException(String.Format("Date - strike pair ({0},{1}) is out of range. Extrapolation is not implemented yet", t, k)); } //find the two indices which on the two sides of the input date. If cannot find in the for loop, then i = 0 automatically. int i = 0; for (int j = 0; j < axisX1InDouble.Count - 1; j++) { if ((axisX1InDouble[j] < t) && (t <= axisX1InDouble[j + 1])) { i = j; } } // get the left and right value of the sabr interpolated vol with the same strike s var leftValue = SABRVolFineTune( OptimizerResults[i].BestAlpha, OptimizerResults[i].BestBeta, OptimizerResults[i].BestRho, OptimizerResults[i].BestNu, _spotPrice, k, OptimizerResults[i].Maturity, _useFineTune); var rightValue = SABRVolFineTune( OptimizerResults[i + 1].BestAlpha, OptimizerResults[i + 1].BestBeta, OptimizerResults[i + 1].BestRho, OptimizerResults[i + 1].BestNu, _spotPrice, k, OptimizerResults[i + 1].Maturity, _useFineTune); var w = Weight((OptimizerResults[i + 1].Maturity - t) / (OptimizerResults[i + 1].Maturity - OptimizerResults[i].Maturity)); return(w * leftValue + (1 - w) * rightValue); }
protected void BuildRowBtn_Click(object sender, EventArgs e) { Built = true; abstractionGrid.Visible = abstractionResults.Visible = false; directNone.Visible = direct.Visible = directGrid.Visible = false; indirectNone.Visible = indirectGrid.Visible = indirect.Visible = false; ColumnGrid.Visible = ColumnResults.Visible = false; RowGrid.Visible = RowResults.Visible = true; using (VirusDescriptionActions usersVirus = new VirusDescriptionActions()) { List <Matrix_Cell> rowTrue = new List <Matrix_Cell>(); List <Trojan.Models.Attribute> results = new List <Trojan.Models.Attribute>(); Trojan.Models.Attribute temp = new Trojan.Models.Attribute(); String virusId = usersVirus.GetVirusId(); VirusDescriptionActions.VirusDescriptionUpdates[] currentBuild = new VirusDescriptionActions.VirusDescriptionUpdates[DescriptionList.Rows.Count]; for (int i = 0; i < DescriptionList.Rows.Count; i++) { IOrderedDictionary rowValues = new OrderedDictionary(); rowValues = GetValues(DescriptionList.Rows[i]); currentBuild[i].AttributeId = Convert.ToInt32(rowValues["AttributeID"]); if (usersVirus.Get_OnOff(virusId, currentBuild[i].AttributeId)) { rowTrue = scanRowTrue(currentBuild[i].AttributeId, null); foreach (Matrix_Cell A in rowTrue) { temp = getAttribute(A.ColumnId); if (!results.Contains(temp)) { results.Add(temp); } temp = null; } } } RowGrid.DataSource = results; RowGrid.DataBind(); } }
private void Calibrate(double spotPrice, IYieldCurve yieldCurve, bool estimateAlpha, bool useFineTune, double initAlpha, double initBeta, double initNu, double initRho) { // set ATM vols var tempCurve2D = new Curve2D <Date, double>(RowGrid, ColGrid, ValueOnGrids, x => x.ToOADate(), x => x, Interpolation2D.BiLinear); var atmVols = RowGrid.Select(d => tempCurve2D.GetValue(d, spotPrice)).ToList(); _spotPrice = spotPrice; _yieldCurve = yieldCurve; _useFineTune = useFineTune; _estimateAlpha = estimateAlpha; OptimizerResults = Enumerable.Range(0, RowGrid.Count()) .Select(i => { var t = _dayCount.CalcDayCountFraction(ValuationDate, RowGrid[i]); var fowardPrice = _spotPrice / _yieldCurve.GetDf(ValuationDate, RowGrid[i]); //var optimizer = new SABRCoeffOptimizer(t, fowardPrice, atmVols[i], AxisX2, Matrix.GetColumn(i), estimateAlpha, useFineTune, initAlpha, initBeta, initNu, initRho); var optimizer = new SabrCoeffOptimizer(t, fowardPrice, atmVols[i], ColGrid, ValueOnGrids.GetRow(i), estimateAlpha, useFineTune, initAlpha, initBeta, initNu, initRho); return(optimizer.Result); }) .ToList(); }
public override double MinX() { return(RowGrid.Select(item => _dayCount.CalcDayCountFraction(ValuationDate, item)).ToList().Min()); }
private void UserDataEditor_FormClosing(object sender, FormClosingEventArgs e) { string name, command; if (AnnotationTable && Modified) { // see if want to save changes to annotation table name = Uo.Name; if (name == "") { name = "this new annotation table"; } DialogResult dr = MessageBoxMx.Show( "Do you want to save the changes to " + name + "?", UmlautMobius.String, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) // yes try to save them { if (!IsValidDefinition()) { return; } if (!SaveAnnotationTableDialog()) // save cancelled { e.Cancel = true; return; } } else if (dr == DialogResult.Cancel) // cancel the close { e.Cancel = true; return; } else { } // must be DialogResult.No, fall through to hide form without saving } else if (UserDatabase && Modified) { // see if want to save changes to user database name = Uo.Name; if (name == "") { name = "this new user compound database"; } DialogResult dr = MessageBoxMx.Show( "Do you want to save the changes to " + name + "?", UmlautMobius.String, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) // yes try to save them { if (!SaveDatabaseDialog()) // save cancelled { e.Cancel = true; return; } } else if (dr == DialogResult.Cancel) // cancel the close { e.Cancel = true; return; } else { } // must be DialogResult.No, fall through to hide form without saving } if (RowGrid != null && DataFormatterOpen) { RowGrid.StopGridDisplay(); // close display of any molecule grid } //if (UserDatabase && Saved && // need to start process to update model data? // Udb.PendingStatus == UcdbWaitState.ModelPredictions && !Udbs.UpdateIsRunning(Udb.DatabaseId)) //{ // command = "UpdateUcdbModelResults Pending " + Udb.DatabaseId; // CommandLine.StartBackgroundSession(command); //} return; }