/// <summary> /// Get the SABR Calibration engine parameter for the provided options /// The exercise/tenor pair form the key to the correct calibration engine /// from an underlying store. /// </summary> /// <param name="param">The parameter type to return</param> /// <param name="engineHandle">The engine to use</param> /// <returns></returns> public decimal GetSABRParameter(CalibrationParameter param, string engineHandle) { SmileCalibrationEngine smileEngine; if (_sabrEngines.ContainsKey(engineHandle)) { smileEngine = _sabrEngines[engineHandle]; } else { throw new ArgumentException("SABR Smile Calibration engine not found."); } var calibrationEngine = smileEngine.SABRCalibrationEngine; SABRParameters parameters = calibrationEngine.GetSABRParameters; switch (param) { case CalibrationParameter.Alpha: return(parameters.Alpha); case CalibrationParameter.Beta: return(parameters.Beta); case CalibrationParameter.Nu: return(parameters.Nu); case CalibrationParameter.Rho: return(parameters.Rho); default: throw new ArgumentException("Unknown Calibration Parameter request"); } }
private void Load() { int noOfParameters; using (StreamReader sr = new StreamReader(FileName)) { Upper.AppendLine(sr.ReadLine()); Upper.AppendLine(sr.ReadLine()); Upper.AppendLine(sr.ReadLine()); string s = sr.ReadLine(); Upper.AppendLine(s); noOfParameters = int.Parse(s.Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[0]); while ((s = sr.ReadLine())!="* parameter data") Upper.AppendLine(s); Upper.AppendLine(s); for (int i = 0; i < noOfParameters; i++) { string[] splitted = sr.ReadLine().Split(new string[] { "\t" }, StringSplitOptions.None); CalibrationParameter cp = new CalibrationParameter(); cp.ShortName = splitted[0]; ParameterType p; if (Enum.TryParse<ParameterType>(splitted[1], true, out p )) cp.ParType = p; cp.ParChgLim = splitted[2]; cp.CurrentValue = double.Parse(splitted[3]); cp.MinValue = double.Parse(splitted[4]); cp.MaxValue = double.Parse(splitted[5]); var g = Groups.FirstOrDefault(var => var.Name.ToLower() == splitted[6].ToLower()); if (g == null) { g = new ParameterGroup(); g.Name = splitted[6]; Groups.Add(g); } cp.Group = g; cp.Scale = double.Parse(splitted[7]); cp.Offset = double.Parse(splitted[8]); cp.Dercom = double.Parse(splitted[9]); Parameters.Add(cp); } for (int i=0;i< Parameters.Count(var=>var.ParType == ParameterType.tied);i++) { string[] splitted = sr.ReadLine().Split(new string[] { " ","\t" }, StringSplitOptions.None); var cp = Parameters.Single(var => var.ShortName == splitted[0]); cp.TiedTo = Parameters.Single(var => var.ShortName == splitted[1]); } Lower.Append(sr.ReadToEnd()); } }
public CalibrationParameterViewModel(CalibrationParameter CP) { cp = CP; DisplayName = cp.ShortName; //Default boundaries one order of magnitude to each side MaxValue = Math.Pow(10, Math.Round(Math.Log10(CurrentValue)) + 1); MinValue = Math.Pow(10, Math.Round(Math.Log10(CurrentValue)) - 1); //statDistribution = new LogNormal(CurrentValue, CurrentValue / 10); }
/// <summary> /// 页面切换事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e) { if (xtraTabControl1.SelectedTabPageIndex == 0) { xtraTabPage2.Controls.Clear(); //xtraTabPage3.Controls.Clear(); if (projectParameter == null) { projectParameter = new ProjectParameter(); projectParameter.AssayProInfoEvent += AssayProInfo_Event; } projectParameter.ProjectParameter_Load(null, null); xtraTabPage1.Controls.Add(projectParameter); } else if (xtraTabControl1.SelectedTabPageIndex == 1) { xtraTabPage1.Controls.Clear(); //xtraTabPage3.Controls.Clear(); if (calibrationParameter == null) { calibrationParameter = new CalibrationParameter(); calibrationParameter.AssayProInfoForCalibParamEvent += AssayProInfo_Event; } if (lstAssayProInfos.Count != 0) { calibrationParameter.ListAssayprojectInfos = lstAssayProInfos; } calibrationParameter.CalibrationParameter_Load(null, null); xtraTabPage2.Controls.Add(calibrationParameter); } //else if (xtraTabControl1.SelectedTabPageIndex == 2) //{ // xtraTabPage1.Controls.Clear(); // xtraTabPage2.Controls.Clear(); // if (rangeParameter == null) // { // rangeParameter = new RangeParameter(); // rangeParameter.AssayProInfoForRangeParamEvent += AssayProInfo_Event; // } // if (lstAssayProInfos.Count != 0) // { // rangeParameter.ListAssayprojectInfos = lstAssayProInfos; // } // xtraTabPage3.Controls.Add(rangeParameter); //} }
public void Load(string FileName) { this.FileName = FileName; using (StreamReader sr = new StreamReader(FileName)) { sr.ReadLine(); int noofsamples = int.Parse(sr.ReadLine().Trim()); int noofpars = int.Parse(sr.ReadLine().Trim()); sr.ReadLine(); List<double[]> data = new List<double[]>(); for (int i = 0; i < noofpars; i++) { data.Add(new double[noofsamples]); } for (int i = 0; i < noofsamples; i++) { var splits = sr.ReadLine().Split(new string[] { "\t" }, StringSplitOptions.None); for (int j = 0; j < noofpars; j++) data[j][i] = double.Parse(splits[j]); } int k = 0; while (!sr.EndOfStream && sr.ReadLine().ToLower() != "Default Truncations:".ToLower()) ; if (!sr.EndOfStream) { sr.ReadLine(); sr.ReadLine(); sr.ReadLine(); for (int i = 0; i < noofpars; i++) { sr.ReadLine(); CalibrationParameter par = new CalibrationParameter(); par.ShortName = sr.ReadLine().Trim(); Samples.Add(par, data[i]); sr.ReadLine(); sr.ReadLine(); sr.ReadLine(); } } } }
/// <summary> /// Get the SABR Calibration engine parameter for the provided options /// The exercise/tenor pair form the key to the correct calibration engine /// from an underlying store. /// </summary> /// <param name="param">The parameter type to return</param> /// <param name="engine">The engine to use</param> /// <param name="pExercise">The exercise (option expiry) part of the key</param> /// <param name="pTenor">The tenor (asset code) part of the key</param> /// <returns></returns> public decimal GetSABRParameter(CalibrationParameter param, string engine, string pExercise, string pTenor) { string exercise = SABRHelper.GenerateTenorLabel(pExercise); string tenor = SABRHelper.GenerateTenorLabel(pTenor); if (!_sabrEngines.ContainsKey(engine)) { throw new ArgumentException("Calibration Engine " + engine + " not found."); } SortedDictionary <SABRKey, SABRCalibrationEngine> sabrEngines = _sabrEngines[engine]; var key = new SABRKey(exercise, tenor); if (!sabrEngines.ContainsKey(key)) { throw new ArgumentException("The Calibration Engine with Key(" + exercise + "," + tenor + ") not found."); } SABRCalibrationEngine calibrationEngine = sabrEngines[key]; SABRParameters parameters = calibrationEngine.GetSABRParameters; switch (param) { case CalibrationParameter.Alpha: return(parameters.Alpha); case CalibrationParameter.Beta: return(parameters.Beta); case CalibrationParameter.Nu: return(parameters.Nu); case CalibrationParameter.Rho: return(parameters.Rho); default: throw new ArgumentException("Unknown Calibration Parameter request"); } }