public static IFloatingRateSource CreateRateForecastCurveFromDiscount( [ExcelArgument(Description = "The floating rate that this curve will be used to forecast.")] FloatRateIndex floatingRateIndex, [ExcelArgument(Description = "The name of the discount curve that will be used to obtain the forward rates.")] IDiscountingSource discountCurve, [QuantSAExcelArgument( Description = "Optional: The name of the fixing curve for providing floating rates at dates before the anchor date of the discount curve. If it is left out then the first floating rate implied by the discount curve will be used for all historical fixes.", Default = null)] IFloatingRateSource fixingCurve) { if (fixingCurve == null) { // Calculate the first fixing off the curve to use at all past dates. var df1 = 1.0; var laterDate = discountCurve.GetAnchorDate().AddTenor(floatingRateIndex.Tenor); var df2 = discountCurve.GetDF(laterDate); var dt = (laterDate - discountCurve.GetAnchorDate()) / 365.0; var rate = (df1 / df2 - 1) / dt; fixingCurve = new FloatingRateFixingCurve1Rate(discountCurve.GetAnchorDate(), rate, floatingRateIndex); } return(new ForecastCurveFromDiscount(discountCurve, floatingRateIndex, fixingCurve)); }
/// <summary> /// </summary> /// <param name="date"></param> /// <returns></returns> public double GetForwardRate(Date date) { //TODO: Index should store the business day and daycount conventions of the index. if (date >= _discountCurve.GetAnchorDate()) { var df1 = _discountCurve.GetDF(date); var laterDate = date.AddTenor(_index.Tenor); var df2 = _discountCurve.GetDF(laterDate); var dt = (laterDate - date) / 365.0; var fwdRate = (df1 / df2 - 1) / dt; return(fwdRate); } return(_fixingCurve.GetForwardRate(date)); }
public static HullWhite1F CreateHWModelDemo([ExcelArgument(Description = "The constant rate of mean reversion.")] double meanReversion, [ExcelArgument(Description = "The constant short rate volatility. Note that this is a Gaussian vol and will in general be lower than the vol that would be used in Black.")] double flatVol, [ExcelArgument(Description = "The curve to which zero coupon bond prices will be calibrated.")] IDiscountingSource baseCurve, [ExcelArgument(Description = "The indices that should be forecast with this same cuve. No spreads are added.")] FloatingIndex forecastIndices) { Date anchorDate = baseCurve.GetAnchorDate(); double flatCurveRate = -Math.Log(baseCurve.GetDF(anchorDate.AddTenor(Tenor.Years(1)))); HullWhite1F model = new HullWhite1F(baseCurve.GetCurrency(), meanReversion, flatVol, flatCurveRate, flatCurveRate, anchorDate); model.AddForecast(forecastIndices); return(model); }
/// <summary> /// Initializes a new instance of the <see cref="EquitySimulator"/> class. /// </summary> /// <param name="shares">An array of shares that will be simulated.</param> /// <param name="prices">The prices of the supplied shares.</param> /// <param name="vols">The annualized volatilites of the supplied shares.</param> /// <param name="divYields">The continous dividend yields.</param> /// <param name="correlations">The correlation matrix for all the shares.</param> /// <param name="discountCurve">The discount curve that will be also be used to determine the drift on the shares.</param> /// <param name="rateForecastCurves">Deterministic rate forecast curves, used for example when a /// structure includes a loan whose interest needs to be calculated during the simulation.</param> public EquitySimulator(Share[] shares, double[] prices, double[] vols, double[] divYields, double[,] correlations, IDiscountingSource discountCurve, IFloatingRateSource[] rateForecastCurves) { this.shares = shares; this.prices = prices; this.vols = vols; this.divYields = divYields; this.discountCurve = discountCurve; anchorDate = discountCurve.GetAnchorDate(); normal = new MultivariateNormalDistribution(Vector.Zeros(prices.Length), correlations); this.rateForecastCurves = new Dictionary <MarketObservable, IFloatingRateSource>(); foreach (var floatingRateSource in rateForecastCurves) { this.rateForecastCurves.Add(floatingRateSource.GetFloatingIndex(), floatingRateSource); } }
/// <summary> /// </summary> /// <param name="date"></param> /// <returns></returns> public double GetForwardRate(Date date) { //TODO: Index should store the business day and daycount conventions of the index. if (date > discountCurve.GetAnchorDate()) { double df1 = discountCurve.GetDF(date); Date laterDate = date.AddTenor(index.tenor); double df2 = discountCurve.GetDF(laterDate); double dt = (laterDate - date) / 365.0; double fwdRate = (df1 / df2 - 1) / dt; return(fwdRate); } else { return(fixingCurve.GetForwardRate(date)); } }
/// <summary> /// Initializes a new instance of the <see cref="DeterministicCreditWithFXJump"/> class. /// </summary> /// <param name="survivalProbSource">A curve that provides survival probabilities. Usually a hazard curve.</param> /// <param name="otherCurrency">The other currency required in the simulation. The valuation currency will /// be inferred from the <paramref name="valueCurrencyDiscount"/>. This value needs to be explicitly set /// since <paramref name="fxSource"/> may provide multiple pairs.</param> /// <param name="fxSource">The source FX spot and forwards.</param> /// <param name="valueCurrencyDiscount">The value currency discount curve.</param> /// <param name="fxVol">The fx volatility.</param> /// <param name="relJumpSizeInDefault">The relative jump size in default. For example if the value currency is ZAR and the /// other currency is USD then the fx is modelled as ZAR per USD and in default the fx rate will change to: /// rate before default * (1 + relJumpSizeInDefault).</param> /// <param name="expectedRecoveryRate">The constant recovery rate that will be assumed to apply in default.</param> public DeterministicCreditWithFXJump(ISurvivalProbabilitySource survivalProbSource, Currency otherCurrency, IFXSource fxSource, IDiscountingSource valueCurrencyDiscount, double fxVol, double relJumpSizeInDefault, double expectedRecoveryRate) { this.survivalProbSource = survivalProbSource; valueCurrency = valueCurrencyDiscount.GetCurrency(); this.fxSource = fxSource; this.valueCurrencyDiscount = valueCurrencyDiscount; this.fxVol = fxVol; this.relJumpSizeInDefault = relJumpSizeInDefault; ReferenceEntity refEntity = survivalProbSource.GetReferenceEntity(); defaultTime = new DefaultTime(refEntity); defaultRecovery = new DefaultRecovery(refEntity); currencyPair = new CurrencyPair(otherCurrency, valueCurrency); anchorDate = valueCurrencyDiscount.GetAnchorDate(); spot = fxSource.GetRate(anchorDate); simRecoveryRate = expectedRecoveryRate; }
/// <summary> /// Construct an FX source where the forwards are obtained from the discount factors on two basis curves. /// </summary> /// <param name="baseCurrency"></param> /// <param name="counterCurrency"></param> /// <param name="fxRateAtAnchorDate"></param> /// <param name="baseCurrencyFXBasisCurve"></param> /// <param name="counterCurrencyFXBasisCurve"></param> public FXForecastCurve(Currency baseCurrency, Currency counterCurrency, double fxRateAtAnchorDate, IDiscountingSource baseCurrencyFXBasisCurve, IDiscountingSource counterCurrencyFXBasisCurve) { if (baseCurrencyFXBasisCurve.GetAnchorDate() != counterCurrencyFXBasisCurve.GetAnchorDate()) { throw new ArgumentException("The two basis curves must have the same anchor dates."); } if (baseCurrency != baseCurrencyFXBasisCurve.GetCurrency()) { throw new ArgumentException("The currency of the baseCurrencyFXBasisCurve must the base currency."); } if (counterCurrency != counterCurrencyFXBasisCurve.GetCurrency()) { throw new ArgumentException("The currency of the counterCurrencyFXBasisCurve must the counter currency."); } this.baseCurrency = baseCurrency; this.counterCurrency = counterCurrency; this.fxRateAtAnchorDate = fxRateAtAnchorDate; this.baseCurrencyFXBasisCurve = baseCurrencyFXBasisCurve; this.counterCurrencyFXBasisCurve = counterCurrencyFXBasisCurve; currencyPair = new CurrencyPair(baseCurrency, counterCurrency); }
/// <summary> /// Construct an FX source where the forwards are obtained from the discount factors on two basis curves. /// </summary> /// <param name="currencyPair"></param> /// <param name="fxRateAtAnchorDate"></param> /// <param name="baseCurrencyFXBasisCurve"></param> /// <param name="counterCurrencyFXBasisCurve"></param> public FXForecastCurve(CurrencyPair currencyPair, double fxRateAtAnchorDate, IDiscountingSource baseCurrencyFXBasisCurve, IDiscountingSource counterCurrencyFXBasisCurve) { _currencyPair = currencyPair ?? throw new ArgumentNullException(nameof(currencyPair)); if (baseCurrencyFXBasisCurve.GetAnchorDate() != counterCurrencyFXBasisCurve.GetAnchorDate()) { throw new ArgumentException("The two basis curves must have the same anchor dates."); } if (currencyPair.BaseCurrency != baseCurrencyFXBasisCurve.GetCurrency()) { throw new ArgumentException("The currency of the baseCurrencyFXBasisCurve must the base currency."); } if (currencyPair.CounterCurrency != counterCurrencyFXBasisCurve.GetCurrency()) { throw new ArgumentException( "The currency of the counterCurrencyFXBasisCurve must the counter currency."); } _fxRateAtAnchorDate = fxRateAtAnchorDate; _baseCurrencyFXBasisCurve = baseCurrencyFXBasisCurve; _counterCurrencyFXBasisCurve = counterCurrencyFXBasisCurve; }
public Date GetAnchorDate() { return(underlyingCurve.GetAnchorDate()); }