/// <summary> /// 获取行权收益 /// </summary> /// <param name="pricePath">价格路径</param> /// <returns>行权收益</returns> public override Cashflow[] GetPayoff(Dictionary <Date, double> pricePath) { var prices = new SortedDictionary <Date, double>(pricePath); //merges fixings and monte carlo path foreach (var key in Fixings.Keys) { prices[key] = Fixings[key]; } var simulatedValuesToCheck = ObservationDates.Select(x => prices[x]).ToArray(); var actualPaymentDate = SettlmentGap.Get(Calendar, UnderlyingMaturityDate); var voidCf = new[] { new Cashflow(StartDate, UnderlyingMaturityDate, actualPaymentDate, Rebate * Notional, PayoffCcy, CashflowType.Net, false, double.NaN, null), new Cashflow(StartDate, UnderlyingMaturityDate, OptionPremiumPaymentDate ?? actualPaymentDate, OptionPremium, PayoffCcy, CashflowType.Net, true, double.NaN, null) }; switch (BarrierType) { case BarrierType.UpAndOut: return(simulatedValuesToCheck.Any(val => val > Barrier) ? voidCf : GetPayoff(new[] { prices.Last().Value })); case BarrierType.UpAndIn: return(simulatedValuesToCheck.Any(val => val > Barrier) ? GetPayoff(new[] { prices.Last().Value }) : voidCf); case BarrierType.DownAndOut: return(simulatedValuesToCheck.Any(val => val < Barrier) ? voidCf : GetPayoff(new[] { prices.Last().Value })); case BarrierType.DownAndIn: return(simulatedValuesToCheck.Any(val => val < Barrier) ? GetPayoff(new[] { prices.Last().Value }) : voidCf); case BarrierType.DoubleTouchOut: return(simulatedValuesToCheck.Any(val => (val > UpperBarrier || val < Barrier)) ? voidCf : GetPayoff(new[] { prices.Last().Value })); case BarrierType.DoubleTouchIn: return(simulatedValuesToCheck.Any(val => (val > UpperBarrier || val < Barrier)) ? GetPayoff(new[] { prices.Last().Value }) : voidCf); default: return(voidCf); } }
/// <summary> /// 获取行权收益 /// </summary> /// <param name="pricePath">价格路径</param> /// <returns>行权收益</returns> public override Cashflow[] GetPayoff(Dictionary <Date, double> pricePath) { var prices = new Dictionary <Date, double>(pricePath); //merges fixings and monte carlo path foreach (var key in Fixings.Keys) { prices[key] = Fixings[key]; } var avgPrice = ObservationDates.Average(x => prices[x]); return(GetPayoff(new[] { avgPrice, pricePath[ExerciseDates[0]] })); }