예제 #1
0
        public void C7_11_3_FxOption()
        {
            var fxOption = new FxOption(OptionType.Put, 365, 100, 0, 0, 0.2);

            fxOption.Correlation         = 0.8;
            fxOption.ExchangeRate1       = 1.1;
            fxOption.ExchangeRate2       = 1 / 1.1;
            fxOption.Currency1Volatility = 0.2;
            fxOption.Currency2Volatility = 0.1;
            fxOption.RiskFreeRate1       = 0;
            fxOption.RiskFreeRate2       = 0;

            Console.WriteLine(fxOption.Price(100));
        }
예제 #2
0
        public void DemonstrateCreationOfFxOption()
        {
            // CREATE an Fx-Option (that can then be upserted into LUSID)
            var fxOption = new FxOption(
                strike: 100m,
                domCcy: "USD",
                fgnCcy: "JPY",
                startDate: new DateTimeOffset(2020, 2, 7, 0, 0, 0, TimeSpan.Zero),
                optionMaturityDate: new DateTimeOffset(2020, 12, 18, 0, 0, 0, TimeSpan.Zero),
                optionSettlementDate: new DateTimeOffset(2020, 12, 21, 0, 0, 0, TimeSpan.Zero),
                isCallNotPut: true,
                isDeliveryNotCash: true,
                instrumentType: LusidInstrument.InstrumentTypeEnum.FxOption
                );

            // ASSERT that it was created
            Assert.That(fxOption, Is.Not.Null);

            // CAN NOW UPSERT TO LUSID
            string uniqueId = "id-fxfwd-1";

            UpsertOtcToLusid(fxOption, "some-name-for-this-fxOption", uniqueId);

            // CAN NOW QUERY FROM LUSID
            var retrieved = QueryOtcFromLusid(uniqueId);

            Assert.That(retrieved.InstrumentType == LusidInstrument.InstrumentTypeEnum.FxOption);
            var roundTripFxOption = retrieved as FxOption;

            Assert.That(roundTripFxOption, Is.Not.Null);
            Assert.That(roundTripFxOption.DomCcy, Is.EqualTo(fxOption.DomCcy));
            Assert.That(roundTripFxOption.FgnCcy, Is.EqualTo(fxOption.FgnCcy));
            Assert.That(roundTripFxOption.Strike, Is.EqualTo(fxOption.Strike));
            Assert.That(roundTripFxOption.StartDate, Is.EqualTo(fxOption.StartDate));
            Assert.That(roundTripFxOption.OptionMaturityDate, Is.EqualTo(fxOption.OptionMaturityDate));
            Assert.That(roundTripFxOption.OptionSettlementDate, Is.EqualTo(fxOption.OptionSettlementDate));
            Assert.That(roundTripFxOption.IsCallNotPut, Is.EqualTo(fxOption.IsCallNotPut));
            Assert.That(roundTripFxOption.IsDeliveryNotCash, Is.EqualTo(fxOption.IsDeliveryNotCash));
        }
예제 #3
0
        public static Trade CreateVanillaFxOption(string tradeId, DateTime tradeDate, string buyerPartyReference, string sellerPartyReference, //FxOptionType optionType,
                                                  PutCallEnum?soldAs, string period, DateTime expiryDate, DateTime time, string expiryBusinessCenter,
                                                  CutName cutName, decimal putCurrencyAmount, string putCurrency, decimal callCurrencyAmount,
                                                  string callCurrency, StrikeQuoteBasisEnum strikeQuoteBasis, DateTime valueDate, Decimal strikePrice, decimal?spotRate,
                                                  bool isCashSettled, Currency settlementCurrency, DateTime?fixingDate, QuotedCurrencyPair quotedCurrencyPair, List <FxOptionPremium> premia)
        {
            var trade = new Trade {
                id = tradeId, tradeHeader = new TradeHeader()
            };
            var party1 = PartyTradeIdentifierHelper.Parse(tradeId, "party1");
            var party2 = PartyTradeIdentifierHelper.Parse(tradeId, "party2");

            trade.tradeHeader.partyTradeIdentifier = new[] { party1, party2 };
            trade.tradeHeader.tradeDate            = new IdentifiedDate {
                Value = tradeDate
            };
            FxOption fxOption = CreateVanillaOption(buyerPartyReference, sellerPartyReference, soldAs,
                                                    period, expiryDate, time, expiryBusinessCenter, cutName, putCurrencyAmount, putCurrency, callCurrencyAmount, callCurrency,
                                                    strikeQuoteBasis, valueDate, strikePrice, spotRate, isCashSettled, settlementCurrency, fixingDate, quotedCurrencyPair, premia);

            FpMLFieldResolver.TradeSetFxOptionLeg(trade, fxOption);
            return(trade);
        }
예제 #4
0
 public static void TradeSetFxOptionLeg(Trade trade, FxOption fxLeg)
 {
     trade.Item            = fxLeg;
     trade.ItemElementName = ItemChoiceType15.fxOption;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="baseParty"></param>
        /// <param name="fxOptionLeg"></param>
        /// <returns></returns>
        public static IList <PriceablePayment> CreatePriceableFxOptionLegPayment(string baseParty, FxOption fxOptionLeg)
        {
            //string id1 = fxLeg.exchangedCurrency1.id ?? "Payment_" + fxLeg.exchangedCurrency1.paymentAmount.currency.Value;
            //string id2 = fxLeg.exchangedCurrency2.id ?? "Payment_" + fxLeg.exchangedCurrency2.paymentAmount.currency.Value;

            var priceablePayments = new List <PriceablePayment>();

            //bool payerIsBase = false;
            ////payment1
            //var paymentAmount1 = fxLeg.exchangedCurrency1.paymentAmount.amount;
            //if (baseParty == fxLeg.exchangedCurrency1.payerPartyReference.href)
            //{
            //    paymentAmount1 *= -1; // *fxLeg.exchangedCurrency1.paymentAmount.amount;
            //    payerIsBase = true;
            //}
            //var paymentDate = fxLeg.Items[0];
            //var currency1 = fxLeg.exchangedCurrency1.paymentAmount.currency.Value;
            //priceablePayments.Add(new PriceablePayment(id1, fxLeg.exchangedCurrency1.payerPartyReference.href,
            //    fxLeg.exchangedCurrency2.payerPartyReference.href, payerIsBase,
            //    paymentAmount1, currency1, paymentDate, null));
            ////payment2
            //var paymentAmount2 = fxLeg.exchangedCurrency2.paymentAmount.amount;
            //if (baseParty == fxLeg.exchangedCurrency2.payerPartyReference.href)
            //{
            //    paymentAmount2 *= -1; // *fxLeg.exchangedCurrency2.paymentAmount.amount;
            //    payerIsBase = true;
            //}
            //var currency2 = fxLeg.exchangedCurrency2.paymentAmount.currency.Value;
            //priceablePayments.Add(new PriceablePayment(id2, fxLeg.exchangedCurrency1.payerPartyReference.href,
            //    fxLeg.exchangedCurrency2.payerPartyReference.href, payerIsBase, paymentAmount2, currency2, paymentDate, null));
            return(priceablePayments);
        }
예제 #6
0
        /// <summary>
        /// Creates a vanilla fx option.
        /// </summary>
        /// <param name="buyerPartyReference"></param>
        /// <param name="sellerPartyReference"></param>
        /// <param name="soldAs"></param>
        /// <param name="period"> </param>
        /// <param name="expiryDate"></param>
        /// <param name="expiryBusinessCenter"> </param>
        /// <param name="cutName"> </param>
        /// <param name="isCashSettled"></param>
        /// <param name="settlementCurrency"></param>
        /// <param name="fixingDate"></param>
        /// <param name="quotedCurrencyPair"></param>
        /// <param name="putCurrencyAmount"></param>
        /// <param name="putCurrency"></param>
        /// <param name="callCurrencyAmount"></param>
        /// <param name="spotRate"></param>
        /// <param name="callCurrency"></param>
        /// <param name="strikeQuoteBasis"></param>
        /// <param name="valueDate"></param>
        /// <param name="strikePrice"></param>
        /// <param name="premia"></param>
        /// <param name="time"> </param>
        /// <returns></returns>
        public static FxOption CreateVanillaOption(string buyerPartyReference, string sellerPartyReference, PutCallEnum?soldAs, string period,
                                                   DateTime expiryDate, DateTime time, string expiryBusinessCenter, CutName cutName, decimal putCurrencyAmount, string putCurrency,
                                                   decimal callCurrencyAmount, string callCurrency, StrikeQuoteBasisEnum strikeQuoteBasis, DateTime valueDate, Decimal strikePrice, decimal?spotRate,
                                                   bool isCashSettled, Currency settlementCurrency, DateTime?fixingDate, QuotedCurrencyPair quotedCurrencyPair, List <FxOptionPremium> premia)
        {
            CutName cut = null;

            if (cutName != null)
            {
                cut = new CutName {
                    Value = cutName.Value
                };
            }
            var expiryDateTime = new FxEuropeanExercise
            {
                expiryDate = expiryDate,
                expiryTime =
                    new BusinessCenterTime
                {
                    hourMinuteTime = time,
                    businessCenter = new BusinessCenter {
                        Value = expiryBusinessCenter
                    }
                },
                cutName            = cut,
                valueDate          = valueDate,
                valueDateSpecified = true
            };

            FxOptionPremium[] premiumValues = null;
            if (premia != null)
            {
                premiumValues = premia.ToArray();
            }
            var fxOption = new FxOption
            {
                Items = new object[] { new ProductType {
                                           Value = ProductTypeSimpleEnum.FxOption.ToString()
                                       } },
                ItemsElementName   = new[] { ItemsChoiceType2.productType },
                putCurrencyAmount  = MoneyHelper.GetNonNegativeAmount(putCurrencyAmount, putCurrency),
                callCurrencyAmount = MoneyHelper.GetNonNegativeAmount(callCurrencyAmount, callCurrency),
                strike             =
                    new FxStrikePrice {
                    rate = strikePrice, rateSpecified = true, strikeQuoteBasis = strikeQuoteBasis, strikeQuoteBasisSpecified = true
                },
                buyerPartyReference  = PartyReferenceFactory.Create(buyerPartyReference),
                sellerPartyReference =
                    PartyReferenceFactory.Create(sellerPartyReference),
                premium = premiumValues,
                Item    = expiryDateTime,
            };

            if (spotRate != null)
            {
                fxOption.spotRate          = (decimal)spotRate;
                fxOption.spotRateSpecified = true;
            }
            if (period != null)
            {
                var tenorPeriod = PeriodHelper.Parse(period);
                fxOption.tenorPeriod = tenorPeriod;
            }
            if (soldAs != null)
            {
                fxOption.soldAs          = (PutCallEnum)soldAs;
                fxOption.soldAsSpecified = true;
            }
            if (isCashSettled)
            {
                fxOption.cashSettlement = new FxCashSettlement {
                    settlementCurrency = settlementCurrency
                };
                var fxFixing = new FxFixing();
                if (fixingDate != null)
                {
                    fxFixing.fixingDate          = (DateTime)fixingDate;
                    fxFixing.fixingDateSpecified = true;
                }
                fxFixing.quotedCurrencyPair    = quotedCurrencyPair;
                fxOption.cashSettlement.fixing = new [] { fxFixing };
            }
            return(fxOption);
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VanillaEuropeanFxOptionPricer"/> class.  All the cashflows must be signed.
        /// </summary>
        /// <param name="paymentCalendar">The payment calendar</param>
        /// <param name="fxOptionLeg">The fxLeg.</param>
        /// <param name="baseParty">The the base party.</param>
        /// <param name="logger">The logger</param>
        /// <param name="cache">The cache</param>
        /// <param name="nameSpace">The namespace</param>
        /// <param name="fixingCalendar">The fixing calendar</param>
        public VanillaEuropeanFxOptionPricer(ILogger logger, ICoreCache cache,
                                             String nameSpace, IBusinessCalendar fixingCalendar,
                                             IBusinessCalendar paymentCalendar, FxOption fxOptionLeg, string baseParty)
        {
            OrderedPartyNames = new List <string>();
            Multiplier        = 1.0m;
            Id                   = fxOptionLeg.id;
            AnalyticsModel       = new FxOptionLegAnalytic();
            ProductType          = ProductTypeSimpleEnum.FxOption;
            HybridValuation      = true;
            BuyerPartyReference  = fxOptionLeg.buyerPartyReference.href;
            SellerPartyReference = fxOptionLeg.sellerPartyReference.href;
            BasePartyBuyer       = baseParty == BuyerPartyReference;
            FxOptionType         = FxOptionType.Put;
            ProductType          = ProductTypeSimpleEnum.FxOption;
            if (fxOptionLeg.spotRateSpecified)
            {
                SpotRate = fxOptionLeg.spotRate;
            }
            FpMLProductType = ProductTypeHelper.GetProductType(fxOptionLeg.Items, fxOptionLeg.ItemsElementName);
            //Temporary values used to build the fx and option trades.
            PutCurrencyAmount  = fxOptionLeg.putCurrencyAmount.amount;
            PutCurrency        = fxOptionLeg.callCurrencyAmount.currency.Value;
            CallCurrencyAmount = fxOptionLeg.callCurrencyAmount.amount;
            CallCurrency       = fxOptionLeg.putCurrencyAmount.currency.Value;
            FxStrike           = fxOptionLeg.strike.rate;
            StrikeQuoteBasis   = fxOptionLeg.strike.strikeQuoteBasis;
            if (IsCall())
            {
                FxOptionType = FxOptionType.Call;
            }
            SoldAs = fxOptionLeg.soldAs;
            if (fxOptionLeg.tenorPeriod != null)
            {
                QuotedTenor = fxOptionLeg.tenorPeriod.ToString();
            }
            var vanillaOption = fxOptionLeg.Item as FxEuropeanExercise;

            if (vanillaOption != null)
            {
                ExpiryDate = vanillaOption.expiryDate;
                ExpiryTimeBusinessCenter = vanillaOption.expiryTime.businessCenter.Value;
                ExpiryTime = vanillaOption.expiryTime.hourMinuteTime; //TODO Not Implemented yet!
                CutName    = vanillaOption.cutName;
                ValueDate  = vanillaOption.valueDate;
            }
            var type = HasBeenExercised ? ProductTypeSimpleEnum.FxSpot : ProductTypeSimpleEnum.FxForward;
            //Create the fxleg.
            //TODO Currently this does not handle non-deliverable forwards or a third settlement currency.
            var fxLeg = FxOption.CreateFxSingleLeg(HasBeenExercised, BuyerPartyReference, SellerPartyReference, PutCurrencyAmount, PutCurrency, CallCurrencyAmount,
                                                   CallCurrency, StrikeQuoteBasis, ValueDate, FxStrike);

            FxLeg = new FxSingleLegPricer(fxLeg, baseParty, type);
            VolatilitySurfaceName = fxOptionLeg.GetRequiredVolatilitySurfaces()[0];
            //FxOptionType;
            //Get the currency.
            PaymentCurrencies = new List <string>();
            PaymentCurrencies.AddRange(FxLeg.PaymentCurrencies);
            //Add the premia
            Premia = new List <PriceableFxOptionPremium>();
            if (fxOptionLeg.premium != null)
            {
                foreach (var premium in fxOptionLeg.premium)
                {
                    var priceablePayment = PriceableInstrumentsFactory.CreatePriceableFxOptionPremium(cache, nameSpace, null, baseParty, premium, fixingCalendar, paymentCalendar);
                    Premia.Add(priceablePayment);
                    PaymentCurrencies.AddRange(priceablePayment.PaymentCurrencies);
                }
            }
            PaymentCurrencies = PaymentCurrencies.Distinct().ToList();
            if (fxOptionLeg.cashSettlement != null)
            {
                IsCashSettled          = true;
                CashSettlementCurrency = fxOptionLeg.cashSettlement.settlementCurrency;
                //Only a single fixing date is currency implemented.
                if (fxOptionLeg.cashSettlement.fixing != null && fxOptionLeg.cashSettlement.fixing[0].fixingDateSpecified)
                {
                    FixingDate = fxOptionLeg.cashSettlement.fixing[0].fixingDate;
                    FixingQuotedCurrencyPair = fxOptionLeg.cashSettlement.fixing[0].quotedCurrencyPair;
                }
            }
            if (vanillaOption != null)
            {
                RiskMaturityDate = vanillaOption.valueDate;
            }
            logger.LogInfo("FxOption trade created :");
        }