internal static void AddCurves(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; var curve1 = new Curve() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; var curveDetail1 = new CurveDetail() { Name = "SWAPSOIS", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; curve1.CurveDetails.Add(curveDetail1); var curve2 = new Curve() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; var curveDetail2 = new CurveDetail() { Name = "SWAPSOISRISK", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; curve2.CurveDetails.Add(curveDetail2); CurveFamily item = context.CurveFamilies.Where(x => x.Name == "SWAPS").First(); curveDetail1.CurveFamily = item; curveDetail2.CurveFamily = item; TargetSystem system = context.TargetSystems.Where(x => x.Name == "Simra").First(); curveDetail1.TargetSystem = system; curveDetail2.TargetSystem = system; context.Curves.Add(curve1); context.Curves.Add(curve2); context.SaveChanges(); }
internal static void AddScenarioPointsAndUnits(ScenarioGeneratorModel context) { AddScenarioPoints1(context); AddScenarioPoints2(context); AddScenarioPoints3(context); context.SaveChanges(); }
internal static void AddConstituents(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; var curveDetail = context.CurveDetails.Where(x => x.Name == "SWAPSOIS").First(); var curve = curveDetail.Curve; var riskFactorDimType = context.RiskFactorDimTypes.Include("RiskFactorDimensionDetails").Where(x => x.Name == "Tenor").First(); var riskDimension = riskFactorDimType.RiskFactorDimensionDetails.First().RiskFactorDimension; var curveDimension = new CurveDimension() { RiskFactorDimension = riskDimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; curve.CurveDimensions.Add(curveDimension); RiskFactorDimItemDetail dimItemDetail = context.RiskFactorDimItemDetails.Where(x => x.Name == "1D").First(); curveDimension.CurveConstituents.Add(new CurveConstituent() { CurveDimension = curveDimension, RiskFactorDimItem = dimItemDetail.RiskFactorDimItem, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }); dimItemDetail = context.RiskFactorDimItemDetails.Where(x => x.Name == "2D").First(); curveDimension.CurveConstituents.Add(new CurveConstituent() { CurveDimension = curveDimension, RiskFactorDimItem = dimItemDetail.RiskFactorDimItem, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }); dimItemDetail = context.RiskFactorDimItemDetails.Where(x => x.Name == "3D").First(); curveDimension.CurveConstituents.Add(new CurveConstituent() { CurveDimension = curveDimension, RiskFactorDimItem = dimItemDetail.RiskFactorDimItem, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }); dimItemDetail = context.RiskFactorDimItemDetails.Where(x => x.Name == "4D").First(); curveDimension.CurveConstituents.Add(new CurveConstituent() { CurveDimension = curveDimension, RiskFactorDimItem = dimItemDetail.RiskFactorDimItem, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }); dimItemDetail = context.RiskFactorDimItemDetails.Where(x => x.Name == "5D").First(); curveDimension.CurveConstituents.Add(new CurveConstituent() { CurveDimension = curveDimension, RiskFactorDimItem = dimItemDetail.RiskFactorDimItem, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }); context.SaveChanges(); }
internal static void AddScenarioLocuses(ScenarioGeneratorModel context) { AddScenarioLocuses1(context); AddScenarioLocuses2(context); AddScenarioLocuses3(context); context.SaveChanges(); }
internal static void AddScenarioGroups(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; ScenarioGroup sg = new ScenarioGroup() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; context.ScenarioGroups.Add(sg); ScenarioGroupDetail sgd; sgd = new ScenarioGroupDetail() { Name = "Macro (v1)", StartTime = now.AddDays(-100), EndTime = now.AddDays(-50), CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = false }; sg.ScenarioGroupDetails.Add(sgd); sgd = new ScenarioGroupDetail() { Name = "Macro (v2)", StartTime = now.AddDays(-50), EndTime = now.AddDays(-20), CreatedAt = now.AddDays(-75), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", ModifiedAt = now.AddDays(-60), ModifiedBy = "C", Latest = false }; sg.ScenarioGroupDetails.Add(sgd); sgd = new ScenarioGroupDetail() { Name = "Macro (v3)", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-30), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", ModifiedAt = now.AddDays(-35), ModifiedBy = "C", Latest = false }; sg.ScenarioGroupDetails.Add(sgd); sgd = new ScenarioGroupDetail() { Name = "Macro", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-10), CreatedBy = "A", ModifiedAt = now.AddDays(-5), ModifiedBy = "C", Latest = true }; sg.ScenarioGroupDetails.Add(sgd); ScenarioGroup sgc = new ScenarioGroup() { StartTime = now.AddDays(-80), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.ScenarioGroups.Add(sgc); sgd = new ScenarioGroupDetail() { Name = "Cyprus Contagion (v1)", StartTime = now.AddDays(-80), EndTime = now.AddDays(-40), CreatedAt = now.AddDays(-80), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", ModifiedAt = now.AddDays(-80), ModifiedBy = "C", Latest = false }; sgc.ScenarioGroupDetails.Add(sgd); sgd.ScenarioGroupParent = sg; sgd = new ScenarioGroupDetail() { Name = "Cyprus Contagion (v2)", StartTime = now.AddDays(-40), EndTime = now.AddDays(-10), CreatedAt = now.AddDays(-50), CreatedBy = "A", ApprovedAt = now.AddDays(-40), ApprovedBy = "B", ModifiedAt = now.AddDays(-45), ModifiedBy = "C", Latest = false }; sgc.ScenarioGroupDetails.Add(sgd); sgd.ScenarioGroupParent = sg; sgd = new ScenarioGroupDetail() { Name = "Cyprus Contagion (v3)", StartTime = now.AddDays(-10), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-20), CreatedBy = "A", ApprovedAt = now.AddDays(-10), ApprovedBy = "B", ModifiedAt = now.AddDays(-12), ModifiedBy = "C", Latest = false }; sgc.ScenarioGroupDetails.Add(sgd); sgd.ScenarioGroupParent = sg; sgd = new ScenarioGroupDetail() { Name = "Cyprus Contagion", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-5), CreatedBy = "A", ModifiedAt = now.AddDays(-3), ModifiedBy = "C", Latest = true }; sgc.ScenarioGroupDetails.Add(sgd); sgd.ScenarioGroupParent = sg; sgc = new ScenarioGroup() { StartTime = now.AddDays(-55), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-55), ApprovedBy = "B", Latest = true }; context.ScenarioGroups.Add(sgc); sgd = new ScenarioGroupDetail() { Name = "Double Dip Recession (v1)", StartTime = now.AddDays(-55), EndTime = now.AddDays(-17), CreatedAt = now.AddDays(-80), CreatedBy = "A", ApprovedAt = now.AddDays(-55), ApprovedBy = "B", ModifiedAt = now.AddDays(-80), ModifiedBy = "C", ScenarioGroupParent = sg, Latest = false }; sgc.ScenarioGroupDetails.Add(sgd); sgd.ScenarioGroupParent = sg; sgd = new ScenarioGroupDetail() { Name = "Double Dip Recession", StartTime = now.AddDays(-17), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-50), CreatedBy = "A", ApprovedAt = now.AddDays(-17), ApprovedBy = "B", ModifiedAt = now.AddDays(-18), ModifiedBy = "C", ScenarioGroupParent = sg, Latest = true }; sgc.ScenarioGroupDetails.Add(sgd); sgd.ScenarioGroupParent = sg; sgc = new ScenarioGroup() { StartTime = now.AddDays(-25), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-55), ApprovedBy = "B", Latest = true }; context.ScenarioGroups.Add(sgc); sgd = new ScenarioGroupDetail() { Name = "Euro Breaks Up", StartTime = now.AddDays(-25), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-80), CreatedBy = "A", ModifiedAt = now.AddDays(-18), ModifiedBy = "C", Latest = true }; sgc.ScenarioGroupDetails.Add(sgd); sgd.ScenarioGroupParent = sg; sgc = new ScenarioGroup() { StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-80), CreatedBy = "A", Latest = true }; context.ScenarioGroups.Add(sgc); sgd = new ScenarioGroupDetail() { Name = "Eurozone Crisis", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-80), CreatedBy = "A", Latest = true }; sgc.ScenarioGroupDetails.Add(sgd); context.SaveChanges(); }
internal static void AddFamilies(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; var parent = new CurveFamily() { Name = "LBG", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; context.CurveFamilies.Add(parent); var child = new CurveFamily() { Name = "SWAPS", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; child.CurveFamilyParent = parent; context.CurveFamilies.Add(child); context.SaveChanges(); }
public void TestSaveNewScenarioGroup() { string name = "New Scenario Group"; ScenarioGroup main; ScenarioGroupDetail detail; using (var context = new ScenarioGeneratorModel(UserName, Connection)) { main = new ScenarioGroup(); main.Default(UserName); context.ScenarioGroups.Add(main); detail = new ScenarioGroupDetail(); detail.Default(UserName); detail.Name = name; main.ScenarioGroupDetails.Add(detail); context.SaveChanges(); } using (var context = new ScenarioGeneratorModel(UserName, Connection)) { context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); Assert.AreEqual(1, context.ScenarioGroupDetails.Where(x => x.Name == name).Count()); detail = context.ScenarioGroupDetails.Where(x => x.Name == name).FirstOrDefault(); main = detail.ScenarioGroup; Assert.AreEqual(name, detail.Name); Assert.AreEqual(true, detail.Latest); Assert.AreEqual(DateTime.MinValue, detail.StartTime); Assert.AreEqual(DateTime.MaxValue, detail.EndTime); Assert.AreEqual(EntityStatus.Unapproved, detail.Status); Assert.AreEqual(true, main.Latest); Assert.AreEqual(DateTime.MinValue, main.StartTime); Assert.AreEqual(DateTime.MaxValue, main.EndTime); Assert.AreEqual(DateTime.MaxValue, main.EndTime); Assert.AreEqual(EntityStatus.Unapproved, main.Status); } }
internal static void AddTypeGroups(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; RiskFactorTypeGroup ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "Credit"; context.RiskFactorTypeGroups.Add(ftg); RiskFactorTypeGroup ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Spread"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "FX"; context.RiskFactorTypeGroups.Add(ftg); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Rate"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Volatility"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "IL"; context.RiskFactorTypeGroups.Add(ftg); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Rate"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Volatility"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftg = new RiskFactorTypeGroup(); ftg.Default(context.UserName); ftg.Name = "IR"; context.RiskFactorTypeGroups.Add(ftg); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Spread"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Rate"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); ftgc = new RiskFactorTypeGroup(); ftgc.Default(context.UserName); ftgc.Name = "Volatility"; ftg.RiskFactorTypeGroupChildren.Add(ftgc); context.SaveChanges(); }
internal static void AddTypeDimensions(ScenarioGeneratorModel context) { RiskFactorTypeDetail rft; RiskFactorDimensionDetail rfd; RiskFactorTypeDimension rftd; rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "FX Rate" && d.Latest==true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Currency" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID } ; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "FX Volatility" && d.Latest == true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Currency" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Country of Origin" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "Credit Asset Swap Spread" && d.Latest == true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Sector" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Obligor Rating" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rft = context.RiskFactorTypeDetails.Where(d => (d.Name == "IR Volatility" && d.Latest == true)).First(); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Currency" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Instrument Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); rfd = context.RiskFactorDimensionDetails.Where(d => (d.Name == "Underlying Tenor" && d.Latest == true)).First(); rftd = new RiskFactorTypeDimension() { RiskFactorDimensionID = rfd.RiskFactorDimensionID, RiskFactorTypeID = rft.RiskFactorTypeID }; rftd.Default(context.UserName); context.RiskFactorTypeDimensions.Add(rftd); context.SaveChanges(); }
internal static void AddTypes(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; RiskFactorType rft; RiskFactorTypeDetail rftd; rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "Credit Asset Swap Spread", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-25), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x =>x.RiskFactorTypeGroupParent.Name == "Credit").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "Credit CDS Composites Spread", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-25), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "Credit").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "Credit CDS Index Spread", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-25), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "Credit").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "FX Rate", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Rate").Where(x => x.RiskFactorTypeGroupParent.Name == "FX").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-50), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "FX Volatility", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Volatility").Where(x => x.RiskFactorTypeGroupParent.Name == "FX").First(); rft = new RiskFactorType() { StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IL Rate", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-150), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Rate").Where(x => x.RiskFactorTypeGroupParent.Name == "IL").First(); rft = new RiskFactorType() { StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IL Volatility", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-150), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Volatility").Where(x => x.RiskFactorTypeGroupParent.Name == "IL").First(); rft = new RiskFactorType() { StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IR Volatility", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-150), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Volatility").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rft = new RiskFactorType() { StartTime = now.AddDays(-80), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; context.RiskFactorTypes.Add(rft); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread (v1)", StartTime = now.AddDays(-100), EndTime = now.AddDays(-50), CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = false }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread (v2)", StartTime = now.AddDays(-50), EndTime = now.AddDays(-10), CreatedAt = now.AddDays(-90), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", Latest = false }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread (v3)", StartTime = now.AddDays(-10), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-40), CreatedBy = "A", ApprovedAt = now.AddDays(-10), ApprovedBy = "B", Latest = false }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Rate").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); rftd = new RiskFactorTypeDetail() { Name = "IR LIBOR Spread", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-30), CreatedBy = "A", Latest = true }; rft.RiskFactorTypeDetails.Add(rftd); rftd.RiskFactorTypeGroup = context.RiskFactorTypeGroups.Where(x => x.Name == "Spread").Where(x => x.RiskFactorTypeGroupParent.Name == "IR").First(); context.SaveChanges(); }
internal static void AddScenarios(ScenarioGeneratorModel context) { DateTime now = context.AsOfDate; ScenarioGroup sg1 = context.ScenarioGroupDetails.Where(x => x.Name == "Cyprus Contagion").First().ScenarioGroup; ScenarioGroup sg2 = context.ScenarioGroupDetails.Where(x => x.Name == "Double Dip Recession").First().ScenarioGroup; ScenarioGroup sg3 = context.ScenarioGroupDetails.Where(x => x.Name == "Eurozone Crisis").First().ScenarioGroup; RiskFactorType rft1 = context.RiskFactorTypeDetails.Where(x => x.Name == "IR Volatility").First().RiskFactorType; RiskFactorType rft2 = context.RiskFactorTypeDetails.Where(x => x.Name == "FX Rate").First().RiskFactorType; RiskFactorType rft3 = context.RiskFactorTypeDetails.Where(x => x.Name == "FX Volatility").First().RiskFactorType; ScenarioDetail scd; Scenario sc = new Scenario() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B" }; context.Scenarios.Add(sc); scd = new ScenarioDetail() { Name = "Scenario IR Rate (v1)", StartTime = now.AddDays(-80), EndTime = now.AddDays(-50), CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-80), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", ScenarioGroup = sg1, RiskFactorType = rft2, Latest = false }; sc.ScenarioDetails.Add(scd); scd = new ScenarioDetail() { Name = "Scenario IR Rate (v2)", StartTime = now.AddDays(-50), EndTime = now.AddDays(-20), CreatedAt = now.AddDays(-75), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", ModifiedAt = now.AddDays(-60), ModifiedBy = "C", ScenarioGroup = sg1, RiskFactorType = rft2, Latest = false }; sc.ScenarioDetails.Add(scd); scd = new ScenarioDetail() { Name = "Scenario IR Rate (v3)", StartTime = now.AddDays(-20), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-30), CreatedBy = "A", ApprovedAt = now.AddDays(-20), ApprovedBy = "B", ModifiedAt = now.AddDays(-35), ModifiedBy = "C", ScenarioGroup = sg1, RiskFactorType = rft2, Latest = false }; sc.ScenarioDetails.Add(scd); scd = new ScenarioDetail() { Name = "Scenario IR Rate", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-10), CreatedBy = "A", ModifiedAt = now.AddDays(-5), ModifiedBy = "C", ScenarioGroup = sg1, RiskFactorType = rft2, Latest = true }; sc.ScenarioDetails.Add(scd); Scenario sc2 = new Scenario() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", BaseScenario = sc }; context.Scenarios.Add(sc2); scd = new ScenarioDetail() { Name = "Scenario IR Volatility (v1)", StartTime = now.AddDays(-50), EndTime = now.AddDays(-25), CreatedAt = now.AddDays(-30), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", ModifiedAt = now.AddDays(-550), ModifiedBy = "C", ScenarioGroup = sg2, RiskFactorType = rft1, Latest = false }; sc2.ScenarioDetails.Add(scd); scd = new ScenarioDetail() { Name = "Scenario IR Volatility (v2)", StartTime = now.AddDays(-25), EndTime = now.AddDays(-10), CreatedAt = now.AddDays(-38), CreatedBy = "A", ApprovedAt = now.AddDays(-25), ApprovedBy = "B", ModifiedAt = now.AddDays(-30), ModifiedBy = "C", ScenarioGroup = sg2, RiskFactorType = rft1, Latest = false }; sc2.ScenarioDetails.Add(scd); scd = new ScenarioDetail() { Name = "Scenario IR Volatility (v3)", StartTime = now.AddDays(-10), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-15), CreatedBy = "A", ApprovedAt = now.AddDays(-10), ApprovedBy = "B", ModifiedAt = now.AddDays(-17), ModifiedBy = "C", ScenarioGroup = sg2, RiskFactorType = rft1, Latest = false }; sc2.ScenarioDetails.Add(scd); scd = new ScenarioDetail() { Name = "Scenario IR Volatility", StartTime = DateTime.MinValue, EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-5), CreatedBy = "A", ModifiedAt = now.AddDays(-3), ModifiedBy = "C", ScenarioGroup = sg3, RiskFactorType = rft1, Latest = true }; sc2.ScenarioDetails.Add(scd); Scenario sc3 = new Scenario() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-80), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B"}; context.Scenarios.Add(sc3); scd = new ScenarioDetail() { Name = "IR Bond Swap Spread", StartTime = now.AddDays(-50), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-80), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", ScenarioGroup = sg3, RiskFactorType = rft1, Latest = true }; sc3.ScenarioDetails.Add(scd); scd.Scenario = sc3; Scenario sc4 = new Scenario() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-80), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B" }; context.Scenarios.Add(sc4); scd = new ScenarioDetail() { Name = "FX Volatility", StartTime = now.AddDays(-50), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-80), CreatedBy = "A", ApprovedAt = now.AddDays(-50), ApprovedBy = "B", ScenarioGroup = sg3, RiskFactorType = rft3, Latest = true }; sc4.ScenarioDetails.Add(scd); scd.Scenario = sc4; context.SaveChanges(); }