Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableFuturesAssetController"/> class.
 /// </summary>
 /// <param name="baseDate">The base date.</param>
 /// <param name="position">The number of contracts.</param>
 /// <param name="nodeStruct"></param>
 /// <param name="marketQuote">In the case of a future, this is a rate.</param>
 /// <param name="extraQuote">In the case of a future, this is the futures convexity volatility.</param>
 protected PriceableFuturesAssetController(DateTime baseDate, int position, FutureNodeStruct nodeStruct,
                                           BasicQuotation marketQuote, Decimal extraQuote)
 {
     Id       = nodeStruct.Future.id;
     Position = position;
     BaseDate = baseDate;
     SetQuote(marketQuote);
     //This handles the case where the underlying index is pat of an IR future node type.
     Volatility             = extraQuote;
     BusinessDayAdjustments = nodeStruct.BusinessDayAdjustments;
     FuturesLag             = nodeStruct.SpotDate;
     Future = nodeStruct.Future;
 }
Exemple #2
0
        public FutureTransactionPricer(ILogger logger, ICoreCache cache, string nameSpace, DateTime tradeDate, ExchangeContractTypeEnum futuresType,
                                       IBusinessCalendar settlementCalendar, FutureTransaction futureFpML, string basePartyReference, Boolean forecastRateInterpolation)
        {
            logger.LogInfo("FuturesType set. Commence to build a future transaction.");
            if (futureFpML == null)
            {
                return;
            }
            Multiplier        = 1.0m;
            BuyerReference    = futureFpML.buyerPartyReference.href;
            PaymentCurrencies = new List <string> {
                futureFpML.unitPrice.currency.Value
            };
            SellerReference = futureFpML.sellerPartyReference.href;
            BasePartyBuyer  = basePartyReference == futureFpML.buyerPartyReference.href;
            if (!BasePartyBuyer)
            {
                Multiplier = -1.0m;
            }
            ForecastRateInterpolation = forecastRateInterpolation;
            SettlementCalendar        = settlementCalendar;
            FuturesType       = futuresType;
            ReferenceContract = futureFpML.future.id;
            var futuresCode = ReferenceContract.Split('-')[2];

            NumberOfContracts = Convert.ToInt16(futureFpML.numberOfUnits);
            PurchasePrice     = MoneyHelper.GetAmount(futureFpML.unitPrice.amount, futureFpML.unitPrice.currency.Value);
            var exchangeMIC = futureFpML.future.exchangeId;

            FuturesCurveName  = CurveNameHelpers.GetExchangeTradedCurveName(futureFpML.unitPrice.currency.Value, exchangeMIC.Value, futuresCode);
            DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(futureFpML.unitPrice.currency, true);
            FuturesTypeInfo   = new FutureNodeStruct();
            var exchangeMICData = InstrumentDataHelper.CreateEquityExchangeKey(nameSpace, exchangeMIC.Value);
            var exchangeData    = cache.LoadItem <ExchangeConfigData>(exchangeMICData);

            if (exchangeData?.Data is ExchangeConfigData)
            {
                Exchange = (ExchangeConfigData)exchangeData.Data;
                FuturesTypeInfo.SpotDate = Exchange.SettlementDate;
            }
            if (futureFpML.future != null)
            {
                if (SettlementCalendar == null)
                {
                    SettlementCalendar = BusinessCenterHelper.ToBusinessCalendar(cache,
                                                                                 FuturesTypeInfo.SpotDate
                                                                                 .businessCenters,
                                                                                 nameSpace);
                }
                var future = XmlSerializerHelper.Clone(futureFpML.future);
                FuturesTypeInfo.Future = future;
                if (FuturesTypeInfo.SpotDate != null)
                {
                    SettlementDate = GetSettlementDate(tradeDate, SettlementCalendar,
                                                       FuturesTypeInfo.SpotDate);
                }
                //Instantiate the priceable future.
                NamedValueSet namedValueSet = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, FuturesTypeInfo.Future.id, tradeDate);
                var           asset         = AssetHelper.Parse(FuturesTypeInfo.Future.id, 0.0m, 0.0m);
                UnderlyingFuture = PriceableAssetFactory.Create(logger, cache, nameSpace, asset.Second, namedValueSet, null, null) as IPriceableFuturesAssetController;
                if (UnderlyingFuture != null)
                {
                    RiskMaturityDate = UnderlyingFuture.GetRiskMaturityDate();
                    MaturityDate     = RiskMaturityDate;
                    LastTradeDate    = UnderlyingFuture.LastTradeDate;
                }
                if (!PaymentCurrencies.Contains(futureFpML.future.currency.Value))
                {
                    PaymentCurrencies.Add(futureFpML.future.currency.Value);
                }
                logger.LogInfo("Futures transaction has been successfully created.");
            }
            else
            {
                logger.LogInfo("Futures type data not available.");
            }
            //Add payments like the settlement price
            if (!PurchasePrice.amountSpecified)
            {
                return;
            }
            var amount            = PurchasePrice.amount * NumberOfContracts / 100;
            var settlementPayment = PaymentHelper.Create("FuturesSettlemetAmount", BuyerReference, SellerReference, amount, SettlementDate);

            AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, new[] { settlementPayment }, SettlementCalendar);
            if (!PaymentCurrencies.Contains(settlementPayment.paymentAmount.currency.Value))
            {
                PaymentCurrencies.Add(settlementPayment.paymentAmount.currency.Value);
            }
        }