Skip to content

Commit

Permalink
TO fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Sep 22, 2022
1 parent 1cc6c34 commit 147f515
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Qwack.Core/Instruments/CashWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -18,6 +21,10 @@ public CashWrapper(IAssetInstrument underlyingInstrument, List<CashBalance> cash
CashBalances = cashBalances ?? new List<CashBalance>();
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<CashBalance> CashBalances { get; }
Expand Down Expand Up @@ -66,5 +73,15 @@ public override bool Equals(object obj)
public string[] IrCurves(IAssetFxModel model) => UnderlyingInstrument.IrCurves(model);
public Dictionary<string, List<DateTime>> 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()
}
};
}
}
7 changes: 7 additions & 0 deletions src/Qwack.Core/Instruments/Funding/CashBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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; }
Expand Down Expand Up @@ -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 };
}
}
1 change: 1 addition & 0 deletions src/Qwack.Core/Instruments/InstrumentEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/Qwack.Core/Instruments/InstrumentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Qwack.Transport/BasicTypes/AssetInstrumentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum AssetInstrumentType
MultiPeriodBackpricingOption,
OneTouchOption,
Equity,
Bond
Bond,
CashWrapper

}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 147f515

Please sign in to comment.