Пример #1
0
        public ScenarioUnit AddAdditionalUnit(ScenarioUnitPoint unitPoint, IEnumerable<RiskFactorDimension> riskFactorDimensions)
        {
            ScenarioUnit unit = new ScenarioUnit();
            unit.Default(Context.UserName);

            ScenarioDetail scenarioDetail = unitPoint.ScenarioUnit.ScenarioDetail;

            unit.ScenarioDetail = scenarioDetail;
            scenarioDetail.ScenarioUnits.Add(unit);

            ScenarioUnitPoint scenarioUnitPoint = new ScenarioUnitPoint();
            scenarioUnitPoint.ScenarioUnit = unit;
            scenarioUnitPoint.ScenarioPoint = unitPoint.ScenarioPoint;
            unit.ScenarioUnitPoints.Add(scenarioUnitPoint);

            for (int points = 0; points < Math.Pow(2, riskFactorDimensions.Count()-1); points++)
            {
                ScenarioPoint point = AddPoint(scenarioDetail, riskFactorDimensions);
                scenarioUnitPoint.Default(Context.UserName);
                scenarioUnitPoint.ScenarioUnit = unit;
                scenarioUnitPoint.ScenarioPoint = point;
                unit.ScenarioUnitPoints.Add(scenarioUnitPoint);
            }

            if (scenarioDetail.Status == EntityStatus.Approved)
                scenarioDetail.Modified(Context.UserName);

            return unit;
        }
Пример #2
0
        private static void AddScenarioPoints3(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;

            ScenarioDetail scenario = context.ScenarioDetails.Where(x => x.Name == "Scenario IR Volatility").First();

            ScenarioPoint point11 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point11.ShockValue = 1.5;
            point11.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point11);

            ScenarioPoint point12 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point12.ShockValue = 0.7;
            point12.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point12);

            ScenarioPoint point13 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point13.ShockValue = 0.65;
            point13.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point13);

            ScenarioPoint point14 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point14.ShockValue = 0.33;
            point14.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point14);

            ScenarioPoint point21 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point21.ShockValue = 0.3;
            point21.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point21);

            ScenarioPoint point22 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point22.ShockValue = 0.3;
            point22.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point22);

            ScenarioPoint point23 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point23.ShockValue = 0.85;
            point23.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point23);

            ScenarioPoint point24 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point24.ShockValue = 1.15;
            point24.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point24);

            ScenarioPoint point31 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point31.ShockValue = 0.8;
            point31.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point31);

            ScenarioPoint point32 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point32.ShockValue = 1.3;
            point32.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point32);

            ScenarioPoint point33 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point33.ShockValue = 0.95;
            point33.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point33);

            ScenarioPoint point34 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point34.ShockValue = 1.35;
            point34.ScenarioShockType = ScenarioShockType.ABS;
            scenario.ScenarioPoints.Add(point34);

            ScenarioUnit unit11 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit11.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit11);

            ScenarioUnit unit12 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit12.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit12);

            ScenarioUnit unit13 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit13.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit13);

            ScenarioUnit unit21 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit21.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit21);

            ScenarioUnit unit22 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit22.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit22);

            ScenarioUnit unit23 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit23.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit23);

            ScenarioUnit unit4 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit22.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit22);

            ScenarioUnitPoint unitPoint;
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point11, ScenarioUnit = unit11, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point21, ScenarioUnit = unit11, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point22, ScenarioUnit = unit11, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point12, ScenarioUnit = unit11, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point12, ScenarioUnit = unit12, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point22, ScenarioUnit = unit12, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point23, ScenarioUnit = unit12, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point13, ScenarioUnit = unit12, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point13, ScenarioUnit = unit13, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point23, ScenarioUnit = unit13, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point24, ScenarioUnit = unit13, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point14, ScenarioUnit = unit13, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point21, ScenarioUnit = unit21, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point31, ScenarioUnit = unit21, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point32, ScenarioUnit = unit21, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point22, ScenarioUnit = unit21, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point22, ScenarioUnit = unit22, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point32, ScenarioUnit = unit22, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point33, ScenarioUnit = unit22, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point23, ScenarioUnit = unit22, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point23, ScenarioUnit = unit23, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point33, ScenarioUnit = unit23, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point34, ScenarioUnit = unit23, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);
            unitPoint = new ScenarioUnitPoint() { ScenarioPoint = point24, ScenarioUnit = unit23, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.ScenarioUnitPoints.Add(unitPoint);

            ScenarioPointCoordinate coordinate;
            RiskFactorDimItemDetail dimItem;

            RiskFactorDimension dimension = scenario.RiskFactorType.RiskFactorTypeDimensions.Where(d => d.RiskFactorDimension.RiskFactorDimensionDetail.Name == "Instrument Tenor").First().RiskFactorDimension;

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point11.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point21.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point31.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point12.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point22.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point32.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point13.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point23.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point33.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point14.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point24.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point34.ScenarioPointCoordinates.Add(coordinate);

            dimension = scenario.RiskFactorType.RiskFactorTypeDimensions.Where(d => d.RiskFactorDimension.RiskFactorDimensionDetail.Name == "Underlying Tenor").First().RiskFactorDimension;

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point11.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point21.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point31.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "2D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point12.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "2D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point22.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "2D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point32.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point13.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point23.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point33.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point14.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point24.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point34.ScenarioPointCoordinates.Add(coordinate);
        }
Пример #3
0
        private static void AddScenarioPoints2(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;

            ScenarioDetail scenario = context.ScenarioDetails.Where(x => x.Name == "FX Volatility").First();

            ScenarioPoint point1 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point1.ShockValue = -0.5;
            point1.ScenarioShockType = ScenarioShockType.REL;
            scenario.ScenarioPoints.Add(point1);

            ScenarioPoint point2 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point2.ShockValue = 0.7;
            point2.ScenarioShockType = ScenarioShockType.REL;
            scenario.ScenarioPoints.Add(point2);

            ScenarioPoint point3 = new ScenarioPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            point3.ShockValue = 0.3;
            point3.ScenarioShockType = ScenarioShockType.REL;
            scenario.ScenarioPoints.Add(point3);

            ScenarioUnit unit1 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit1.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit1);

            ScenarioUnit unit2 = new ScenarioUnit() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true }; ;
            unit2.ScenarioUnitType = ScenarioUnitType.LineCubic;
            scenario.ScenarioUnits.Add(unit2);

            ScenarioUnitPoint unitPoint;
            unitPoint = new ScenarioUnitPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            unitPoint.ScenarioPoint = point1;
            unit1.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            unitPoint.ScenarioPoint = point2;
            unit1.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            unitPoint.ScenarioPoint = point2;
            unit2.ScenarioUnitPoints.Add(unitPoint);

            unitPoint = new ScenarioUnitPoint() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            unitPoint.ScenarioPoint = point3;
            unit2.ScenarioUnitPoints.Add(unitPoint);

            RiskFactorDimension dimension = scenario.RiskFactorType.RiskFactorTypeDimensions.Where(d => d.RiskFactorDimension.RiskFactorDimensionDetail.Name == "Instrument Tenor").First().RiskFactorDimension;

            ScenarioDimEdgePolicy policy = new ScenarioDimEdgePolicy() { ScenarioDetailID = scenario.ScenarioDetailID, RiskFactorDimensionID = dimension.RiskFactorDimensionID, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            scenario.ScenarioDimEdgePolicies.Add(policy);

            ScenarioPointCoordinate coordinate;
            RiskFactorDimItemDetail dimItem;

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point1.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point2.ScenarioPointCoordinates.Add(coordinate);

            coordinate = new ScenarioPointCoordinate() { RiskFactorDimension = dimension, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-200), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            dimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D" && i.RiskFactorDimItem.RiskFactorDimTypeID == dimension.RiskFactorDimensionDetail.RiskFactorDimTypeID).First();
            coordinate.RiskFactorDimItem = dimItem.RiskFactorDimItem;
            point3.ScenarioPointCoordinates.Add(coordinate);
        }
Пример #4
0
        public Scenario DeepCopy(Scenario scenario, string scenarioName = "")
        {
            Scenario copyScenario = new Scenario();
            Context.Scenarios.Add(copyScenario);

            //copy values from original and reset audit
            Context.Entry(copyScenario).CurrentValues.SetValues(scenario);
            copyScenario.Default(Context.UserName);

            ScenarioDetail copyDetail = new ScenarioDetail();
            Context.ScenarioDetails.Add(copyDetail);

            Context.Entry(copyDetail).CurrentValues.SetValues(scenario.ScenarioDetail);
            copyDetail.Default(Context.UserName);
            copyDetail.Name = scenarioName;

            copyScenario.ScenarioDetails.Add(copyDetail);

            //copy locuses
            foreach (ScenarioLocus locus in scenario.ScenarioDetail.ScenarioLocuses.ToList())
            {
                ScenarioLocus copyLocus = new ScenarioLocus();
                Context.ScenarioLocuses.Add(copyLocus);

                Context.Entry(copyLocus).CurrentValues.SetValues(locus);
                copyLocus.Default(Context.UserName);

                copyDetail.ScenarioLocuses.Add(copyLocus);

                //copy locus dim items
                foreach (ScenarioLocusDimItem dimItem in locus.ScenarioLocusDimItems.ToList())
                {
                    ScenarioLocusDimItem copyDimItem = new ScenarioLocusDimItem();
                    Context.ScenarioLocusDimItems.Add(copyDimItem);

                    Context.Entry(copyDimItem).CurrentValues.SetValues(dimItem);
                    copyDimItem.Default(Context.UserName);

                    copyLocus.ScenarioLocusDimItems.Add(copyDimItem);
                }

                //copy locus dim groups
                foreach (ScenarioLocusDimGroup dimGroup in locus.ScenarioLocusDimGroups.ToList())
                {
                    ScenarioLocusDimGroup copyDimGroup = new ScenarioLocusDimGroup();
                    Context.ScenarioLocusDimGroups.Add(copyDimGroup);

                    Context.Entry(copyDimGroup).CurrentValues.SetValues(dimGroup);
                    copyDimGroup.Default(Context.UserName);

                    copyLocus.ScenarioLocusDimGroups.Add(copyDimGroup);
                }
            }

            //copy points
            foreach (ScenarioPoint point in scenario.ScenarioDetail.ScenarioPoints.ToList())
            {
                ScenarioPoint copyPoint = new ScenarioPoint();
                Context.ScenarioPoints.Add(copyPoint);

                Context.Entry(copyPoint).CurrentValues.SetValues(point);
                copyPoint.Default(Context.UserName);

                copyDetail.ScenarioPoints.Add(copyPoint);

                //copy coordinates
                foreach (ScenarioPointCoordinate coordinate in point.ScenarioPointCoordinates.ToList())
                {
                    ScenarioPointCoordinate copyCoordinate = new ScenarioPointCoordinate();
                    Context.ScenarioPointCoordinates.Add(copyCoordinate);

                    Context.Entry(copyCoordinate).CurrentValues.SetValues(coordinate);
                    copyCoordinate.Default(Context.UserName);

                    copyPoint.ScenarioPointCoordinates.Add(copyCoordinate);
                }
            }

            //copy untis
            foreach (ScenarioUnit unit in scenario.ScenarioDetail.ScenarioUnits.ToList())
            {

                ScenarioUnit copyUnit = new ScenarioUnit();
                Context.ScenarioUnits.Add(copyUnit);

                Context.Entry(copyUnit).CurrentValues.SetValues(unit);
                copyUnit.Default(Context.UserName);

                copyDetail.ScenarioUnits.Add(copyUnit);

                //copy coordinates
                foreach (ScenarioUnitPoint unitPoint in unit.ScenarioUnitPoints.ToList())
                {
                    ScenarioUnitPoint copyUnitPoint = new ScenarioUnitPoint();
                    Context.ScenarioUnitPoints.Add(copyUnitPoint);

                    Context.Entry(copyUnitPoint).CurrentValues.SetValues(unitPoint);
                    copyUnitPoint.Default(Context.UserName);

                    copyUnit.ScenarioUnitPoints.Add(copyUnitPoint);
                }
            }

            return copyScenario;
        }