public Dictionary <string, IPvModel> GenerateScenarios(IPvModel model) { var o = new Dictionary <string, IPvModel>(); var results = new KeyValuePair <string, IPvModel> [NScenarios * 2 + 1]; ParallelUtils.Instance.For(-NScenarios, NScenarios + 1, 1, (i) => { var thisShift = i * ShiftSize; var thisLabel = (string.IsNullOrWhiteSpace(AssetId) ? Ccy.Ccy : AssetId) + "~" + thisShift; if (thisShift == 0) { results[i + NScenarios] = new KeyValuePair <string, IPvModel>(thisLabel, model); } else { if (string.IsNullOrWhiteSpace(AssetId)) { IPvModel shifted; switch (ShiftType) { case MutationType.FlatShift: shifted = FlatShiftMutator.FxSpotShift(Ccy, thisShift, model); break; default: throw new Exception($"Unable to process shift type {ShiftType}"); } results[i + NScenarios] = new KeyValuePair <string, IPvModel>(thisLabel, shifted); } else { IPvModel shifted; switch (ShiftType) { case MutationType.FlatShift: shifted = FlatShiftMutator.AssetCurveShift(AssetId, thisShift, model); break; default: throw new Exception($"Unable to process shift type {ShiftType}"); } results[i + NScenarios] = new KeyValuePair <string, IPvModel>(thisLabel, shifted); } } }).Wait(); foreach (var kv in results) { o.Add(kv.Key, kv.Value); } return(o); }
private Dictionary <Tuple <string, string>, IPvModel> GenerateScenariosAssetFx(IPvModel model) { var o = new Dictionary <Tuple <string, string>, IPvModel>(); var axisLength = NScenarios * 2 + 1; var results = new KeyValuePair <Tuple <string, string>, IPvModel> [axisLength * axisLength]; ParallelUtils.Instance.For(-NScenarios, NScenarios + 1, 1, (i) => { var thisShiftAsset = i * ShiftSizeAsset; var thisLabelAsset = AssetId + "~" + thisShiftAsset; var assetIx = i + NScenarios; IPvModel shifted; if (thisShiftAsset == 0) { shifted = model; } else { switch (ShiftType) { case MutationType.FlatShift: shifted = FlatShiftMutator.AssetCurveShift(AssetId, thisShiftAsset, model); break; default: throw new Exception($"Unable to process shift type {ShiftType}"); } } for (var ifx = -NScenarios; ifx < NScenarios + 1; ifx++) { var fxIx = ifx + NScenarios; var thisShiftFx = ifx * ShiftSizeFx; var thisLabelFx = Ccy.Ccy + "~" + thisShiftFx; IPvModel shiftedFx; if (thisShiftAsset == 0) { shiftedFx = shifted; } else { shiftedFx = FlatShiftMutator.FxSpotShift(Ccy, thisShiftFx, shifted); } results[assetIx * axisLength + fxIx] = new KeyValuePair <Tuple <string, string>, IPvModel>( new Tuple <string, string>(thisLabelAsset, thisLabelFx), shiftedFx); } }).Wait(); foreach (var kv in results) { o.Add(kv.Key, kv.Value); } return(o); }