public void SimpleOption() { foreach (var val in paramRange) { ISimpleOptionAssetParameters analyticModelParameters = new SimpleRateOptionAssetParameters { isVolatiltiyQuote = true, NotionalAmount = 10000000.0m, Rate = .05m, isDiscounted = false, isPut = true, Volatility = val, Strike = .05m, PremiumPaymentDiscountFactor = 1.0m, TimeToExpiry = 0.25m, YearFraction = .25m }; var model = new SimpleRateOptionAssetAnalytic { AnalyticParameters = analyticModelParameters }; var result = model.NPV; var delta0 = model.Delta0; Debug.Print("ExpectedValue1 : {0} Delta0 : {1} CurveYearFraction : {2} ", result, delta0, analyticModelParameters.TimeToExpiry); analyticModelParameters.Premium = result; var vol = model.VolatilityAtExpiry; Debug.Print("InputVol : {0} OutputVol : {1} ", analyticModelParameters.Volatility, vol); } }
public void SimpleOptionImpliedVol() { foreach (var val in paramRange) { ISimpleOptionAssetParameters analyticModelParameters = new SimpleRateOptionAssetParameters { NotionalAmount = 10000000.0m, Rate = .05m, isDiscounted = false, isPut = true, Strike = .05m, Premium = 0.001m, PremiumPaymentDiscountFactor = 1.0m, TimeToExpiry = 0.25m, YearFraction = .25m }; var model = new SimpleRateOptionAssetAnalytic { AnalyticParameters = analyticModelParameters }; var result = model.VolatilityAtExpiry; Debug.Print("VolatilityAtExpiry : {0}", result); analyticModelParameters.Volatility = result; var vol = model.NPV; Debug.Print("InputVol : {0} OutputVol : {1} ", analyticModelParameters.Volatility, vol); } }
/// <summary> /// Calculates the specified model data. /// </summary> /// <param name="modelData">The model data.</param> /// <returns></returns> public override BasicAssetValuation Calculate(IAssetControllerData modelData) { ModelData = modelData; if (AnalyticsModel == null) { //AnalyticsModel = // DependencyCreator.Resolve<IModelAnalytic<ISimpleOptionAssetParameters, RateOptionMetrics>>( // ModelIdentifier); AnalyticsModel = new SimpleRateOptionAssetAnalytic(); } var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics); // Determine if DFAM has been requested - if so that all we evaluate - every other metric is ignored // var bEvalVolatilityAtRiskMaturity = false; if (metrics.Contains(RateOptionMetrics.VolatilityAtExpiry)) { bEvalVolatilityAtRiskMaturity = true; // Remove all metrics except DFAM // metrics.RemoveAll(metricItem => metricItem != RateOptionMetrics.VolatilityAtExpiry); } ISimpleOptionAssetParameters analyticModelParameters = new SimpleRateOptionAssetParameters { YearFraction = YearFraction }; AnalyticResults = new SimpleRateOptionAssetResults(); var metricsToEvaluate = metrics.ToArray(); if (IsVolatilityQuote) { analyticModelParameters.IsVolatilityQuote = true; analyticModelParameters.Volatility = Volatility; } if (bEvalVolatilityAtRiskMaturity && IsVolatilityQuote) { analyticModelParameters.IsVolatilityQuote = true; AnalyticResults = AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(analyticModelParameters, metricsToEvaluate); return(GetValue(AnalyticResults)); } var marketEnvironment = modelData.MarketEnvironment; IRateCurve curve = null; //1. instantiate curve if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment)) { curve = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure(); CurveName = curve.GetPricingStructureId().UniqueIdentifier; } if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment)) { curve = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve(); CurveName = curve.GetPricingStructureId().UniqueIdentifier; } if (marketEnvironment.GetType() == typeof(SwapLegEnvironment)) { curve = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve(); CurveName = curve.GetPricingStructureId().UniqueIdentifier; } if (marketEnvironment.GetType() == typeof(MarketEnvironment)) { curve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(CurveName); } analyticModelParameters.IsPut = !IsCap; //A cap is a call option on the rate. This rate should reflect the underlying Xibor analyticModelParameters.Rate = GetRate(curve, modelData.ValuationDate, AdjustedEffectiveDate, MaturityDate, YearFraction); analyticModelParameters.Premium = Premium; //2. get start df = curve.getvalue(this._adjustedStartDate); // analyticModelParameters.StartDiscountFactor = GetDiscountFactor(curve, AdjustedEffectiveDate, modelData.ValuationDate); analyticModelParameters.PremiumPaymentDiscountFactor = GetDiscountFactor(curve, PaymentDate, modelData.ValuationDate); analyticModelParameters.NotionalAmount = Notional; analyticModelParameters.IsDiscounted = IsDiscounted; //3. Get the end discount factor // analyticModelParameters.EndDiscountFactor = GetDiscountFactor(curve, MaturityDate, modelData.ValuationDate); analyticModelParameters.Strike = Strike; analyticModelParameters.TimeToExpiry = TimeToExpiry; if (bEvalVolatilityAtRiskMaturity && !IsVolatilityQuote) { AnalyticResults = AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>( analyticModelParameters, metricsToEvaluate); return(GetValue(AnalyticResults)); } if (!IsVolatilityQuote) { IVolatilitySurface volCurve; if (marketEnvironment.GetType() == typeof(SwapLegEnvironment)) { var me = (ISwapLegEnvironment)marketEnvironment; volCurve = me.GetVolatilitySurface(); VolCurveName = volCurve.GetPricingStructureId().UniqueIdentifier; } else { volCurve = (IVolatilitySurface)modelData.MarketEnvironment.GetPricingStructure(VolCurveName); } analyticModelParameters.Volatility = Convert.ToDecimal(volCurve.GetValue((double)TimeToExpiry, (double)Strike)); } //4. Set the analytic input parameters and Calculate the respective metrics // AnalyticResults = AnalyticsModel.Calculate <ISimpleRateOptionAssetResults, SimpleRateOptionAssetResults>(analyticModelParameters, metricsToEvaluate); return(GetValue(AnalyticResults)); }