/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleOptionAsset"/> class. /// </summary> /// <param name="cache">The cache.</param> /// <param name="logger">The logger.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="baseDate">The base date.</param> /// <param name="expiryTenor">The expiry tenor.</param> /// <param name="underlyingAssetIdentifier">The underlying asset.</param> /// <param name="strike">The strike.</param> /// <param name="volatility">The volatility.</param> /// <param name="forecastCurve">The forecast rate curve.</param> /// <param name="discountCurve">The discount rate curve. Not used yet, as only the implied rate is caclulated.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public PriceableSimpleOptionAsset(ILogger logger, ICoreCache cache, string nameSpace, String underlyingAssetIdentifier, DateTime baseDate, Period expiryTenor, Decimal?strike, Decimal volatility, IRateCurve discountCurve, ICurve forecastCurve, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) { UnderlyingAssetRef = underlyingAssetIdentifier; var expiryOffset = new Offset { period = expiryTenor.period, periodMultiplier = expiryTenor.periodMultiplier, periodSpecified = true, dayType = DayTypeEnum.Calendar, dayTypeSpecified = true }; var expiryDate = expiryOffset.Add(baseDate); var assetProperties = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, underlyingAssetIdentifier, expiryDate); var instrument = InstrumentDataHelper.GetInstrumentConfigurationData(cache, nameSpace, underlyingAssetIdentifier); var quotation = BasicQuotationHelper.CreateRate(0.05m); var quote = BasicAssetValuationHelper.Create(quotation); UnderlyingPriceableAsset = PriceableAssetFactory.Create(logger, cache, nameSpace, instrument, quote, assetProperties, fixingCalendar, rollCalendar); BaseDate = baseDate; ForwardIndex = UnderlyingPriceableAsset.CalculateImpliedQuote(forecastCurve); if (strike != null) { Strike = (Decimal)strike; } else { Strike = ForwardIndex; } DayCounter = new Actual365(); ExpiryDate = expiryDate; Volatility = volatility; TimeToExpiry = DayCounter.DayCount(BaseDate, ExpiryDate); }
public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, String[] expiryTenors, Double[] strikes, Double[,] volSurface) : base(logger, cache, nameSpace, properties, expiryTenors, strikes, volSurface) { var assetClass = properties.GetString(CurveProp.AssetClass, true); var type = EnumHelper.Parse <AssetClass>(assetClass); var assetId = properties.GetValue <string>(CurveProp.AssetId, true); var baseDate = properties.GetValue <DateTime>(CurveProp.BaseDate, true); PricingStructureData = new PricingStructureData(CurveType.Parent, type); UnderlyingPriceableAssets = new List <IPriceableAssetController>(); foreach (var tenor in expiryTenors) { var expiryTenor = PeriodHelper.Parse(tenor); var offset = new Offset { period = expiryTenor.period, periodMultiplier = expiryTenor.periodMultiplier, periodSpecified = true, dayType = DayTypeEnum.Calendar, dayTypeSpecified = true }; var expiryDate = offset.Add(baseDate); var assetProperties = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, assetId, expiryDate); var asset = PriceableAssetFactory.Create(logger, cache, nameSpace, null, assetProperties, null, null); UnderlyingPriceableAssets.Add(asset); } }
public static Reindexer Make(FigureRecipe parent, FigureRecipe[] children) { int childCount = children.Length; //build hidden face set int parentFaceCount = parent.Geometry.Faces.Length; bool[] hiddenFaceSet = new bool[parentFaceCount]; for (int childIdx = 0; childIdx < children.Length; ++childIdx) { Graft graft = children[childIdx].Geometry.Graft; if (graft != null) { foreach (int hiddenFace in graft.HiddenFaces) { hiddenFaceSet[hiddenFace] = true; } } } //build parent face map int[] parentFaceMap = new int[parent.Geometry.Faces.Length]; int nonHiddenParentFaceCount = 0; for (int faceIdx = 0; faceIdx < parentFaceCount; ++faceIdx) { if (hiddenFaceSet[faceIdx]) { parentFaceMap[faceIdx] = -1; } else { parentFaceMap[faceIdx] = nonHiddenParentFaceCount; nonHiddenParentFaceCount += 1; } } //build child offsets and totals Offset[] offsets = new Offset[childCount]; Offset currentOffset = new Offset( parent.Geometry.GetVertexCount(), nonHiddenParentFaceCount, parent.Geometry.GetSurfaceCount() ); for (int i = 0; i < childCount; ++i) { offsets[i] = currentOffset; FigureRecipe currentFigure = children[i]; currentOffset = currentOffset.Add( currentFigure.Geometry.GetVertexCount(), currentFigure.Geometry.Faces.Length, currentFigure.Geometry.GetSurfaceCount()); } Offset totals = currentOffset; return(new Reindexer(parentFaceMap, offsets, totals)); }
public void Add() { var leftHandOffset = Offset.FromHours(5); var rightHandOffset = Offset.FromHours(6); var result = Snippet.For(Offset.Add(leftHandOffset, rightHandOffset)); Assert.AreEqual(Offset.FromHours(11), result); }
/// <summary> /// Converts to a date time. /// </summary> /// <param name="cache"></param> /// <param name="unadjustedDate"></param> /// <param name="businessDayAdjustments"></param> /// <param name="offset"></param> /// <param name="nameSpace"></param> /// <returns></returns> public static DateTime ToAdjustedDate(ICoreCache cache, DateTime unadjustedDate, BusinessDayAdjustments businessDayAdjustments, Offset offset, string nameSpace) { if (DayTypeEnum.Business != offset.dayType && DayTypeEnum.Calendar != offset.dayType) { throw new NotSupportedException( $"Only {DayTypeEnum.Business}, {DayTypeEnum.Calendar} day types supported of Offset type."); } IBusinessCalendar businessCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, businessDayAdjustments.businessCenters, nameSpace); int periodMultiplier = Int32.Parse(offset.periodMultiplier); // offset using calendar days // switch (offset.dayType) { case DayTypeEnum.Business: { switch (offset.period) { case PeriodEnum.D: { // Advance using given number of business days // int periodMultiplierSign = Math.Sign(periodMultiplier); DateTime offsetedDate = unadjustedDate; while (periodMultiplier-- > 0) { offsetedDate = offsetedDate.AddDays(periodMultiplierSign); offsetedDate = businessCalendar.Roll(offsetedDate, businessDayAdjustments.businessDayConvention); } return(offsetedDate); } default: throw new NotSupportedException( $"{offset.period} not supported in conjunction with '{offset.dayType} day type'"); } //~switch(offset.period) } case DayTypeEnum.Calendar: { // Convert offset to period. DateTime adjustedDate = offset.Add(unadjustedDate); return(adjustedDate); } default: { throw new NotSupportedException( $"Only {DayTypeEnum.Business}, {DayTypeEnum.Calendar} day types supported of Offset type."); } } }
public IReadOnlyList <PointI> GetPointOfGaps() { var result = new List <PointI>(); for (var i = 0; i < Size; i++) { for (var j = 0; j < Size; j++) { var point = Offset.Add(PointI.CreateXZ(i, j)); if (!chunks.ContainsKey(point)) { result.Add(point); } } } return(result); }
public Keyframes() { // The minimal working file requires a visibility and offset keyframes. Visibility.Add(new Keyframe <bool>(0, true, Interpolation.None)); Offset.Add(new Keyframe <int>(0, 0, Interpolation.None)); }
public void MethodAdd_NonZero() { Assert.AreEqual(TestObjects.CreatePositiveOffset(6, 0, 0, 0), Offset.Add(ThreeHours, ThreeHours), "3,000,000 + 1"); Assert.AreEqual(Offset.Zero, Offset.Add(ThreeHours, NegativeThreeHours), "1 + (-1)"); Assert.AreEqual(TestObjects.CreateNegativeOffset(9, 0, 0, 0), Offset.Add(NegativeTwelveHours, ThreeHours), "-TwelveHours + threeHours"); }
public void MethodAdd_Zero_IsNeutralElement() { Assert.AreEqual(0, Offset.Add(Offset.Zero, Offset.Zero).Milliseconds, "0 + 0"); Assert.AreEqual(TestObjects.CreatePositiveOffset(3, 0, 0, 0), Offset.Add(ThreeHours, Offset.Zero), "1 + 0"); Assert.AreEqual(TestObjects.CreatePositiveOffset(3, 0, 0, 0), Offset.Add(Offset.Zero, ThreeHours), "0 + 1"); }