From 147f5159f564444e8cea9592866facc3ff3988d1 Mon Sep 17 00:00:00 2001 From: Gavin Brennan Date: Thu, 22 Sep 2022 21:31:17 +0200 Subject: [PATCH] TO fixes --- src/Qwack.Core/Instruments/CashWrapper.cs | 17 +++++++++++++++++ .../Instruments/Funding/CashBalance.cs | 7 +++++++ src/Qwack.Core/Instruments/InstrumentEx.cs | 1 + .../Instruments/InstrumentFactory.cs | 3 ++- .../BasicTypes/AssetInstrumentType.cs | 3 ++- .../Instruments/Asset/TO_CashBalance.cs | 18 ++++++++++++++++++ .../Instruments/Asset/TO_CashWrapper.cs | 14 ++++++++++++++ .../Instruments/TO_Instrument.cs | 2 ++ 8 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashBalance.cs create mode 100644 src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashWrapper.cs diff --git a/src/Qwack.Core/Instruments/CashWrapper.cs b/src/Qwack.Core/Instruments/CashWrapper.cs index efbe8e5f..6772d516 100644 --- a/src/Qwack.Core/Instruments/CashWrapper.cs +++ b/src/Qwack.Core/Instruments/CashWrapper.cs @@ -5,7 +5,10 @@ using Qwack.Core.Instruments.Asset; using Qwack.Core.Instruments.Funding; using Qwack.Core.Models; +using Qwack.Dates; using Qwack.Transport.BasicTypes; +using Qwack.Transport.TransportObjects.Instruments; +using Qwack.Transport.TransportObjects.Instruments.Asset; namespace Qwack.Core.Instruments { @@ -18,6 +21,10 @@ public CashWrapper(IAssetInstrument underlyingInstrument, List cash CashBalances = cashBalances ?? new List(); MetaData = underlyingInstrument.MetaData; } + public CashWrapper(TO_CashWrapper to, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider) : + this(InstrumentFactory.GetInstrument(to.Underlying, currencyProvider, calendarProvider) as IAssetInstrument, to.CashBalances?.Select(x => new CashBalance(x, currencyProvider)).ToList()) + { + } public IAssetInstrument UnderlyingInstrument { get; } public List CashBalances { get; } @@ -66,5 +73,15 @@ public override bool Equals(object obj) public string[] IrCurves(IAssetFxModel model) => UnderlyingInstrument.IrCurves(model); public Dictionary> PastFixingDates(DateTime valDate) => UnderlyingInstrument.PastFixingDates(valDate); public IAssetInstrument SetStrike(double strike) => UnderlyingInstrument.SetStrike(strike); + + public TO_Instrument ToTransportObject() => new() + { + AssetInstrumentType = AssetInstrumentType.CashWrapper, + CashWrapper = new TO_CashWrapper + { + CashBalances = CashBalances.Select(x => x.ToTransportObject()).ToArray(), + Underlying = UnderlyingInstrument.GetTransportObject() + } + }; } } diff --git a/src/Qwack.Core/Instruments/Funding/CashBalance.cs b/src/Qwack.Core/Instruments/Funding/CashBalance.cs index f2d77d77..3ae42e7f 100644 --- a/src/Qwack.Core/Instruments/Funding/CashBalance.cs +++ b/src/Qwack.Core/Instruments/Funding/CashBalance.cs @@ -3,6 +3,7 @@ using Qwack.Core.Basic; using Qwack.Core.Models; using Qwack.Transport.BasicTypes; +using Qwack.Transport.TransportObjects.Instruments.Asset; namespace Qwack.Core.Instruments.Funding { @@ -18,6 +19,9 @@ public CashBalance(Currency currency, double notional, DateTime? payDate = null) PayDate = payDate ?? DateTime.MinValue; } + public CashBalance(TO_CashBalance to, ICurrencyProvider currencyProvider) + : this(currencyProvider.GetCurrencySafe(to.Currency), to.Notional, to.PayDate) { } + public double Notional { get; set; } public string PortfolioName { get; set; } public Currency Currency { get; set; } @@ -79,5 +83,8 @@ public override bool Equals(object obj) => obj is CashBalance balance && }; public double SuggestPillarValue(IFundingModel model) => 0.05; + + public TO_CashBalance ToTransportObject() + => new TO_CashBalance { Currency = Currency.Ccy, Notional = Notional, PayDate = PayDate }; } } diff --git a/src/Qwack.Core/Instruments/InstrumentEx.cs b/src/Qwack.Core/Instruments/InstrumentEx.cs index c8e92c8d..7e5e4b72 100644 --- a/src/Qwack.Core/Instruments/InstrumentEx.cs +++ b/src/Qwack.Core/Instruments/InstrumentEx.cs @@ -23,6 +23,7 @@ public static class InstrumentEx FxForward fxForward => fxForward.ToTransportObject(), FxPerpetual fxPerpetual => fxPerpetual.ToTransportObject(), Future future => future.ToTransportObject(), + CashWrapper cashWrapper => cashWrapper.ToTransportObject(), _ => throw new Exception("Unable to serialize instrument"), }; } diff --git a/src/Qwack.Core/Instruments/InstrumentFactory.cs b/src/Qwack.Core/Instruments/InstrumentFactory.cs index 01e7d5d5..7be4b1a8 100644 --- a/src/Qwack.Core/Instruments/InstrumentFactory.cs +++ b/src/Qwack.Core/Instruments/InstrumentFactory.cs @@ -41,7 +41,8 @@ public static IInstrument GetInstrument(this TO_Instrument transportObject, ICur return new FuturesOption(transportObject.FuturesOption, currencyProvider); case AssetInstrumentType.Future: return new Future(transportObject.Future, currencyProvider); - + case AssetInstrumentType.CashWrapper: + return new CashWrapper(transportObject.CashWrapper, currencyProvider, calendarProvider); } } else diff --git a/src/Qwack.Transport/BasicTypes/AssetInstrumentType.cs b/src/Qwack.Transport/BasicTypes/AssetInstrumentType.cs index 38113a1c..de542627 100644 --- a/src/Qwack.Transport/BasicTypes/AssetInstrumentType.cs +++ b/src/Qwack.Transport/BasicTypes/AssetInstrumentType.cs @@ -20,7 +20,8 @@ public enum AssetInstrumentType MultiPeriodBackpricingOption, OneTouchOption, Equity, - Bond + Bond, + CashWrapper } } diff --git a/src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashBalance.cs b/src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashBalance.cs new file mode 100644 index 00000000..02f67a99 --- /dev/null +++ b/src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashBalance.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using ProtoBuf; + +namespace Qwack.Transport.TransportObjects.Instruments.Asset +{ + [ProtoContract] + public class TO_CashBalance + { + [ProtoMember(1)] + public double Notional { get; set; } + [ProtoMember(2)] + public string Currency { get; set; } + [ProtoMember(3)] + public DateTime? PayDate { get; set; } + } +} diff --git a/src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashWrapper.cs b/src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashWrapper.cs new file mode 100644 index 00000000..2cffdfe4 --- /dev/null +++ b/src/Qwack.Transport/TransportObjects/Instruments/Asset/TO_CashWrapper.cs @@ -0,0 +1,14 @@ +using ProtoBuf; + +namespace Qwack.Transport.TransportObjects.Instruments.Asset +{ + [ProtoContract] + public class TO_CashWrapper + { + [ProtoMember(1)] + public TO_Instrument Underlying { get; set; } + [ProtoMember(2)] + public TO_CashBalance[] CashBalances { get; set; } + + } +} diff --git a/src/Qwack.Transport/TransportObjects/Instruments/TO_Instrument.cs b/src/Qwack.Transport/TransportObjects/Instruments/TO_Instrument.cs index 8cd9ec54..26e23884 100644 --- a/src/Qwack.Transport/TransportObjects/Instruments/TO_Instrument.cs +++ b/src/Qwack.Transport/TransportObjects/Instruments/TO_Instrument.cs @@ -39,6 +39,8 @@ public class TO_Instrument public TO_FxVanillaOption FxOption { get; set; } [ProtoMember(114)] public TO_FxPerpetual FxPerpetual { get; set; } + [ProtoMember(115)] + public TO_CashWrapper CashWrapper { get; set; } public override bool Equals(object obj) => obj is TO_Instrument instrument && FundingInstrumentType == instrument.FundingInstrumentType &&