Skip to content

Commit

Permalink
TRS support specific initial asset fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Sep 29, 2023
1 parent fcb5cc9 commit 385d654
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 6 deletions.
19 changes: 17 additions & 2 deletions src/Qwack.Core/Instruments/Asset/AssetTRS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class AssetTrs : IAssetInstrument
public AssetTrs() { }

public AssetTrs(ITrsUnderlying underlying, TrsLegType assetLegResetType, SwapLegType fundingLegType, TrsLegType fundingLegResetType, FloatRateIndex rateIndex,
double notional, double fundingFixedRateOrMargin, FxConversionType fxConversionType, DateTime startDate, DateTime endDate, Currency currency, Calendar settleCalendar, SwapPayReceiveType assetLegDirection=SwapPayReceiveType.Rec )
double notional, double fundingFixedRateOrMargin, FxConversionType fxConversionType, DateTime startDate, DateTime endDate, Currency currency, Calendar settleCalendar,
SwapPayReceiveType assetLegDirection=SwapPayReceiveType.Rec, string paymentOffset = "2b", double? initialFixing = null)
{
Underlying = underlying;
AssetLegResetType = assetLegResetType;
Expand All @@ -30,6 +31,10 @@ public AssetTrs(ITrsUnderlying underlying, TrsLegType assetLegResetType, SwapLeg
EndDate = endDate;
Currency = currency;
SettleCalendar = settleCalendar;
InitialAssetFixing = initialFixing;

FundingLegPaymentOffset = new Frequency(paymentOffset);
AssetLegPaymentOffset = new Frequency(paymentOffset);

FundingLeg = new GenericSwapLeg(StartDate, EndDate, rateIndex.HolidayCalendars, rateIndex.Currency,
rateIndex.ResetTenor, rateIndex.DayCountBasis)
Expand Down Expand Up @@ -80,6 +85,12 @@ public AssetTrs(TO_AssetTrs to, ICurrencyProvider currencyProvider, ICalendarPro

FlowScheduleFunding = new CashFlowSchedule(to.FlowScheduleFunding, calendarProvider, currencyProvider);
FlowScheduleAsset = new CashFlowSchedule(to.FlowScheduleAsset, calendarProvider, currencyProvider);

InitialAssetFixing = to.InitialAssetFixing;

FundingLegPaymentOffset = new Frequency(to.FundingLegPaymentOffset);
AssetLegPaymentOffset = new Frequency(to.AssetLegPaymentOffset);

}

public ITrsUnderlying Underlying { get; set; }
Expand Down Expand Up @@ -109,6 +120,8 @@ public AssetTrs(TO_AssetTrs to, ICurrencyProvider currencyProvider, ICalendarPro

public double FundingFixedRateOrMargin { get; set; }

public double? InitialAssetFixing { get; set; }

public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }

Expand Down Expand Up @@ -159,6 +172,7 @@ public double PV(IAssetFxModel model)
SettleCalendar = SettleCalendar,
FundingLegPaymentOffset = FundingLegPaymentOffset,
AssetLegPaymentOffset = AssetLegPaymentOffset,
InitialAssetFixing = InitialAssetFixing,
};

public string FxPair(IAssetFxModel model) => throw new NotImplementedException();
Expand Down Expand Up @@ -204,7 +218,8 @@ public Dictionary<string, List<DateTime>> PastFixingDates(DateTime valDate)
Underlying = Underlying.ToTransportObject(),
AssetLegPaymentOffset = AssetLegPaymentOffset.ToString(),
FundingLegPaymentOffset = FundingLegPaymentOffset.ToString(),
SettleCalendar = SettleCalendar.Name
SettleCalendar = SettleCalendar.Name,
InitialAssetFixing = InitialAssetFixing
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/Qwack.Core/Instruments/Cashflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public CashFlow()
public FlowType FlowType { get; set; }
public DayCountBasis Basis { get; set; }
public FloatRateIndex RateIndex { get; set; }
public double? InitialFixing { get; set; }

public CashFlow(TO_Cashflow to, ICalendarProvider calendarProvider, ICurrencyProvider currencyProvider)
{
Expand All @@ -57,6 +58,7 @@ public CashFlow(TO_Cashflow to, ICalendarProvider calendarProvider, ICurrencyPro
Dcf = to.Dcf;
CpiFixingLagInMonths = to.CpiFixingLagInMonths;
AssetId = to.AssetId;
InitialFixing = to.InitialFixing;
}

public CashFlow Clone() => new()
Expand All @@ -80,6 +82,7 @@ public CashFlow(TO_Cashflow to, ICalendarProvider calendarProvider, ICurrencyPro
Dcf = Dcf,
CpiFixingLagInMonths = CpiFixingLagInMonths,
AssetId = AssetId,
InitialFixing = InitialFixing
};

public TO_Cashflow GetTransportObject() => new ()
Expand All @@ -103,6 +106,7 @@ public CashFlow(TO_Cashflow to, ICalendarProvider calendarProvider, ICurrencyPro
Dcf = Dcf,
CpiFixingLagInMonths = CpiFixingLagInMonths,
AssetId = AssetId,
InitialFixing = InitialFixing
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/Qwack.Core/Instruments/CashflowSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public static double PV(this CashFlowSchedule schedule, Currency reportingCCy, I
{
var s = flow.AccrualPeriodStart;
var e = flow.AccrualPeriodEnd;
var priceS = assetFixings.TryGetValue(s, out var fs) ? fs : curve.GetPriceForFixingDate(s);
var priceS = flow.InitialFixing ?? (assetFixings.TryGetValue(s, out var fs) ? fs : curve.GetPriceForFixingDate(s));
var priceE = assetFixings.TryGetValue(e, out var fe) ? fe : curve.GetPriceForFixingDate(e);
var rateLin = priceE / priceS - 1.0;
rateLin += flow.FixedRateOrMargin;
Expand Down
8 changes: 8 additions & 0 deletions src/Qwack.Core/Instruments/Funding/GenericSwapLeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private void SetAllCalendars(Calendar calendars)
public SwapPayReceiveType Direction { get; set; }
public TrsLegType? TrsLegType { get; set; }
public string AssetId { get; set; }
public double? InitialFixing { get; set; }

public GenericSwapLeg Clone() => new()
{
Expand Down Expand Up @@ -129,6 +130,7 @@ private void SetAllCalendars(Calendar calendars)
TerminationDate = TerminationDate,
TrsLegType = TrsLegType,
AssetId = AssetId,
InitialFixing = InitialFixing,
};

public TO_GenericSwapLeg GetTransportObject() => new()
Expand Down Expand Up @@ -160,6 +162,7 @@ private void SetAllCalendars(Calendar calendars)
Direction = Direction,
TrsLegType = TrsLegType,
AssetId = AssetId,
InitialFixing = InitialFixing
};


Expand Down Expand Up @@ -206,10 +209,15 @@ public CashFlowSchedule GenerateSchedule()
FixedRateOrMargin = 0,
AssetId = AssetId,
Currency = Currency,
InitialFixing = InitialFixing,
});
f.Flows = lf;
return f;
}
else if(LegType == SwapLegType.AssetPerformance)
{
throw new NotImplementedException("Only bullet asset legs are currently supported");
}

if (NotionalExchange is ExchangeType.FrontOnly or ExchangeType.Both)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ public class TO_AssetTrs

[ProtoMember(24)]
public Dictionary<string, string> MetaData { get; set; }

[ProtoMember(25)]
public double? InitialAssetFixing { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ public class TO_Cashflow
public TO_FloatRateIndex RateIndex { get; set; }
[ProtoMember(19)]
public string AssetId { get; set; }
[ProtoMember(20)]
public double? InitialFixing { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ public class TO_GenericSwapLeg
public TrsLegType? TrsLegType { get; set; }
[ProtoMember(27)]
public string AssetId { get; set; }
[ProtoMember(28)]
public double? InitialFixing { get; set; }
}
}
2 changes: 1 addition & 1 deletion test/Qwack.Core.Tests/Instruments/TrsFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void AssetTrs()
var swp = new AssetTrs(ul, TrsLegType.Bullet, SwapLegType.Float, TrsLegType.Resetting, ix, 1e6, 0, FxConversionType.None, startDate, maturity, usd, usd.SettlementCalendar)
{ ForecastFundingCurve = "USD.DISCO", DiscountCurve="USD.DISCO"};
var pv = swp.PV(aModel);
Assert.Equal(9399.28384704169, pv, 8);
Assert.Equal(9406.739119358499, pv, 8);


}
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.7.37</VersionPrefix>
<VersionPrefix>0.7.38</VersionPrefix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.37
0.7.38

0 comments on commit 385d654

Please sign in to comment.