public static ParseInputResult CustomBuildIRCurve(string curveName_, string givenString_) { if (string.IsNullOrEmpty(givenString_)) { return new ParseInputResult() { ErrorString = "Example of possible IR curve entries" }; } var matches = irRegex.Matches(givenString_); if (matches.Count < 1 || matches.Count > 3) { return new ParseInputResult() { ErrorString = "Invalid entry" }; } var buildingBlocks = (from Match match in matches select getxYyY(match)).ToArray(); // any returned error ? var errors = buildingBlocks.Where(x => !string.IsNullOrEmpty(x.Item1)); if (errors.Any()) { var b = new StringBuilder("There was a problem with the entered structure string:"); b.AppendLine(); foreach (var v in errors) b.AppendLine(v.Item1); return new ParseInputResult() { ErrorString = "Error in entered structure" }; } var userConfigItem = new UserListItem { CurveName=curveName_, UserName=SymmetryEnvironment.UserName, SType=Enums.StructureType.Swap }; switch (buildingBlocks.Length) { case 1: // need to create Outright { userConfigItem.Points = new[] { GetPointDef(buildingBlocks[0], 1d) }; } break; case 2: // need to create Curve { userConfigItem.Points = new[] { GetPointDef(buildingBlocks[0], -1d), GetPointDef(buildingBlocks[1], 1d) }; } break; case 3: { userConfigItem.Points = new[] { GetPointDef(buildingBlocks[0],-1d), GetPointDef(buildingBlocks[1], 2d), GetPointDef(buildingBlocks[2], -1d) }; } break; } return new ParseInputResult() { ParseResult=userConfigItem }; }
public static ParseInputResult CustomBuildFutures(string curveName_, string givenString_) { if (string.IsNullOrEmpty(givenString_)) { return new ParseInputResult() { ErrorString = "Example of possible entries for futures" }; } var matches = futRegex.Matches(givenString_); if (matches.Count < 1 || matches.Count > 4) { return new ParseInputResult() { ErrorString = "Invalid Entry" }; } var curvePoints = (from Match match in matches select new Tuple<int, double>( int.Parse(match.Groups["Number"].ToString()), match.Groups["Mult"].Success == false ? double.NaN : double.Parse(match.Groups["Mult"].Value))) .ToArray(); if (curvePoints.Any(x => x.Item1 < 1 || x.Item1 > CurveNames.GetNumberOfContractsForFutures(curveName_))) { return new ParseInputResult() { ErrorString = string.Format("Invalid entry - max contract number is {0} and Minimum is 1", CurveNames.GetNumberOfContractsForFutures(curveName_)) }; } if (curvePoints.Length < 1 || curvePoints.Length > 4) { return new ParseInputResult() { ErrorString = "Maximum number of terms is 4 and minimum is 1" }; } UserListItem conf = new UserListItem { CurveName=curveName_, SType=Enums.StructureType.Future, UserName=SymmetryEnvironment.UserName }; switch (curvePoints.Length) { case 1: { conf.Points = new[] { GetFutureDef(curvePoints[0],1d) }; } break; case 2: { conf.Points = new[] { GetFutureDef(curvePoints[0],-1d), GetFutureDef(curvePoints[1],1d) }; } break; case 3: { conf.Points = new[] { GetFutureDef(curvePoints[0], -1d), GetFutureDef(curvePoints[1], 2d), GetFutureDef(curvePoints[2], -1d) }; } break; case 4: { conf.Points = new[] { GetFutureDef(curvePoints[0], 1d), GetFutureDef(curvePoints[1], -3d), GetFutureDef(curvePoints[2], 3d), GetFutureDef(curvePoints[3], -1d) }; } break; } return new ParseInputResult() { //Task = productCreationtask ParseResult = conf }; }
//internal Task<InstrumentWithStats> CreateInstrumentAsync() //{ // return Task.Run(() => CreateInstrument()); //} internal bool IsSameAs(UserListItem other_) { return other_ != null && GenerateFullMoniker().Equals(other_.GenerateFullMoniker()); }