Skip to content

Commit

Permalink
Parallel gamma fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Jul 11, 2024
1 parent 7443e00 commit 78eabb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/Qwack.Models/Risk/BasicMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,8 @@ private static IPriceCurve GetBumpedCurve(double bumpSize, IPriceCurve curveObjX
Currency = cpc.Currency,
AssetId = AssetId,
SpotCalendar = cpc.SpotCalendar,
SpotLag = cpc.SpotLag
SpotLag = cpc.SpotLag,
Units = cpc.Units,
},

// if (bCurve.Value.UnderlyingsAreForwards) //de-discount delta
Expand All @@ -1451,7 +1452,9 @@ private static IPriceCurve GetBumpedCurve(double bumpSize, IPriceCurve curveObjX
Currency = pc.Currency,
AssetId = AssetId,
SpotCalendar = pc.SpotCalendar,
SpotLag = pc.SpotLag
SpotLag = pc.SpotLag,
RefDate = pc.RefDate,
Units = pc.Units,
},
_ => throw new Exception("Unable to handle curve type for flat shift"),
};
Expand Down Expand Up @@ -1497,6 +1500,8 @@ public static ICube AssetParallelDeltaGamma(this IPvModel pvModel, ICurrencyProv
if (subPortfolio.Instruments.Count == 0)
continue;

var bumpForCurve = bumpSize / 10 * curveObj.GetPriceForDate(model.BuildDate);

var lastDateInBook = subPortfolio.LastSensitivityDate;

var baseModel = pvModel.Rebuild(model, subPortfolio);
Expand All @@ -1507,8 +1512,8 @@ public static ICube AssetParallelDeltaGamma(this IPvModel pvModel, ICurrencyProv
var tTypeIx = pvCube.GetColumnIndex(TradeType);


var bumpedCurveUp = GetBumpedCurve(bumpSize, curveObj, model.VanillaModel, currencyProvider);
var bumpedCurveDown = GetBumpedCurve(-bumpSize, curveObj, model.VanillaModel, currencyProvider);
var bumpedCurveUp = GetBumpedCurve(bumpForCurve, curveObj, model.VanillaModel, currencyProvider);
var bumpedCurveDown = GetBumpedCurve(-bumpForCurve, curveObj, model.VanillaModel, currencyProvider);

var newVanillaModelUp = model.Clone();
newVanillaModelUp.AddPriceCurve(curveName, bumpedCurveUp);
Expand All @@ -1529,8 +1534,8 @@ public static ICube AssetParallelDeltaGamma(this IPvModel pvModel, ICurrencyProv

for (var i = 0; i < pvRows.Length; i++)
{
var deltaUp = (bumpedRowsUp[i].Value - pvRows[i].Value) / bumpSize;
var deltaDown = (pvRows[i].Value - bumpedRowsDown[i].Value) / bumpSize;
var deltaUp = (bumpedRowsUp[i].Value - pvRows[i].Value) / bumpForCurve;
var deltaDown = (pvRows[i].Value - bumpedRowsDown[i].Value) / bumpForCurve;
var delta = (deltaUp + deltaDown) / 2;
if (delta != 0.0)
{
Expand All @@ -1552,7 +1557,7 @@ public static ICube AssetParallelDeltaGamma(this IPvModel pvModel, ICurrencyProv
cube.AddRow(row, delta);
}

var gamma = (deltaUp - deltaDown) / bumpSize;
var gamma = (deltaUp - deltaDown) / bumpForCurve;
if (gamma != 0.0)
{
var row = new Dictionary<string, object>
Expand Down
2 changes: 1 addition & 1 deletion version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<VersionPrefix>0.8.58</VersionPrefix>
<VersionPrefix>0.8.59</VersionPrefix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.58
0.8.59

0 comments on commit 78eabb0

Please sign in to comment.