FRAStandardCapFloorlet.java

  1. package org.drip.product.fra;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  9.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  10.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  11.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2014 Lakshmi Krishnamurthy
  13.  *
  14.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  15.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  16.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  17.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  18.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  19.  *      and computational support.
  20.  *  
  21.  *      https://lakshmidrip.github.io/DROP/
  22.  *  
  23.  *  DROP is composed of three modules:
  24.  *  
  25.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  26.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  27.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  28.  *
  29.  *  DROP Product Core implements libraries for the following:
  30.  *  - Fixed Income Analytics
  31.  *  - Loan Analytics
  32.  *  - Transaction Cost Analytics
  33.  *
  34.  *  DROP Portfolio Core implements libraries for the following:
  35.  *  - Asset Allocation Analytics
  36.  *  - Asset Liability Management Analytics
  37.  *  - Capital Estimation Analytics
  38.  *  - Exposure Analytics
  39.  *  - Margin Analytics
  40.  *  - XVA Analytics
  41.  *
  42.  *  DROP Computational Core implements libraries for the following:
  43.  *  - Algorithm Support
  44.  *  - Computation Support
  45.  *  - Function Analysis
  46.  *  - Model Validation
  47.  *  - Numerical Analysis
  48.  *  - Numerical Optimizer
  49.  *  - Spline Builder
  50.  *  - Statistical Learning
  51.  *
  52.  *  Documentation for DROP is Spread Over:
  53.  *
  54.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  55.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  56.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  57.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  58.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  59.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  60.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  61.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  62.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  63.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  64.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  65.  *
  66.  *  Licensed under the Apache License, Version 2.0 (the "License");
  67.  *      you may not use this file except in compliance with the License.
  68.  *  
  69.  *  You may obtain a copy of the License at
  70.  *      http://www.apache.org/licenses/LICENSE-2.0
  71.  *  
  72.  *  Unless required by applicable law or agreed to in writing, software
  73.  *      distributed under the License is distributed on an "AS IS" BASIS,
  74.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  75.  *  
  76.  *  See the License for the specific language governing permissions and
  77.  *      limitations under the License.
  78.  */

  79. /**
  80.  * <i>FRAStandardCapFloorlet</i> implements the Standard FRA Caplet and Floorlet.
  81.  *
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  86.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/README.md">Product Components/Baskets for Credit, FRA, FX, Govvie, Rates, and Option AssetClasses</a></li>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/fra/README.md">Standard/Market FRAs - Caps/Floors</a></li>
  88.  *  </ul>
  89.  * <br><br>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public class FRAStandardCapFloorlet extends org.drip.product.option.OptionComponent {
  94.     private boolean _bIsCaplet = false;
  95.     private org.drip.product.fra.FRAStandardComponent _fra = null;
  96.     private org.drip.pricer.option.FokkerPlanckGenerator _fpg = null;

  97.     /**
  98.      * FRAStandardCapFloorlet constructor
  99.      *
  100.      * @param strName Name
  101.      * @param fra The Underlying FRA Standard Component
  102.      * @param strManifestMeasure Measure of the Underlying Component
  103.      * @param bIsCaplet Is the FRA Option a Caplet? TRUE - YES
  104.      * @param dblStrike Strike of the Underlying Component's Measure
  105.      * @param dblNotional Option Notional
  106.      * @param ltds Last Trading Date Setting
  107.      * @param fpg The Fokker Planck Pricer Instance
  108.      * @param csp Cash Settle Parameters
  109.      *
  110.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  111.      */

  112.     public FRAStandardCapFloorlet (
  113.         final java.lang.String strName,
  114.         final org.drip.product.fra.FRAStandardComponent fra,
  115.         final java.lang.String strManifestMeasure,
  116.         final boolean bIsCaplet,
  117.         final double dblStrike,
  118.         final double dblNotional,
  119.         final org.drip.product.params.LastTradingDateSetting ltds,
  120.         final org.drip.pricer.option.FokkerPlanckGenerator fpg,
  121.         final org.drip.param.valuation.CashSettleParams csp)
  122.         throws java.lang.Exception
  123.     {
  124.         super (strName, fra, strManifestMeasure, dblStrike, dblNotional, ltds, csp);

  125.         if (null == (_fpg = fpg))
  126.             throw new java.lang.Exception ("FRAStandardCapFloorlet ctr: Invalid Option Pricer");

  127.         _fra = fra;
  128.         _bIsCaplet = bIsCaplet;
  129.     }

  130.     /**
  131.      * Retrieve the Underlying FRA Instance
  132.      *
  133.      * @return The FRA Instance
  134.      */

  135.     public org.drip.product.fra.FRAStandardComponent fra()
  136.     {
  137.         return _fra;
  138.     }

  139.     /**
  140.      * Indicate whether this a Caplet/Floorlet
  141.      *
  142.      * @return TRUE - This is a Caplet
  143.      */

  144.     public boolean isCaplet()
  145.     {
  146.         return _bIsCaplet;
  147.     }

  148.     /**
  149.      * Retrieve the Underlying Pricer Instance
  150.      *
  151.      * @return The Pricer Instance
  152.      */

  153.     public org.drip.pricer.option.FokkerPlanckGenerator pricer()
  154.     {
  155.         return _fpg;
  156.     }

  157.     /**
  158.      * Generate the Standard FRA Caplet/Floorlet Measures from the Integrated Surface Variance
  159.      *
  160.      * @param valParams The Valuation Parameters
  161.      * @param pricerParams The Pricer Parameters
  162.      * @param csqs The Market Parameters
  163.      * @param vcp The Valuation Customization Parameters
  164.      * @param dblIntegratedSurfaceVariance The Integrated Surface Variance
  165.      *
  166.      * @return The Standard FRA Caplet/Floorlet Measures
  167.      */

  168.     public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> valueFromSurfaceVariance (
  169.         final org.drip.param.valuation.ValuationParams valParams,
  170.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  171.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  172.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  173.         final double dblIntegratedSurfaceVariance)
  174.     {
  175.         if (null == valParams || null == csqs || !org.drip.numerical.common.NumberUtil.IsValid
  176.             (dblIntegratedSurfaceVariance))
  177.             return null;

  178.         org.drip.state.discount.MergedDiscountForwardCurve dcFunding = csqs.fundingState
  179.             (org.drip.state.identifier.FundingLabel.Standard (_fra.payCurrency()));

  180.         if (null == dcFunding) return null;

  181.         int iValueDate = valParams.valueDate();

  182.         org.drip.product.params.LastTradingDateSetting ltds = lastTradingDateSetting();

  183.         try {
  184.             if (null != ltds && iValueDate >= ltds.lastTradingDate (_fra.effectiveDate().julian(),
  185.                 _fra.stream().calendar()))
  186.                 return null;
  187.         } catch (java.lang.Exception e) {
  188.             e.printStackTrace();

  189.             return null;
  190.         }

  191.         long lStart = System.nanoTime();

  192.         int iExerciseDate = exerciseDate().julian();

  193.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFRAOutput = _fra.value
  194.             (valParams, pricerParams, csqs, vcp);

  195.         java.lang.String strManifestMeasure = manifestMeasure();

  196.         if (null == mapFRAOutput || !mapFRAOutput.containsKey (strManifestMeasure)) return null;

  197.         double dblFRADV01 = mapFRAOutput.get ("DV01");

  198.         double dblATMManifestMeasure = mapFRAOutput.get (strManifestMeasure);

  199.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblATMManifestMeasure) ||
  200.             !org.drip.numerical.common.NumberUtil.IsValid (dblFRADV01))
  201.             return null;

  202.         try {
  203.             double dblStrike = strike();

  204.             double dblNotional = notional();

  205.             double dblMoneynessFactor = dblATMManifestMeasure / dblStrike;
  206.             double dblManifestMeasurePriceTransformer = java.lang.Double.NaN;
  207.             double dblManifestMeasureIntrinsic = _bIsCaplet ? dblATMManifestMeasure - dblStrike : dblStrike -
  208.                 dblATMManifestMeasure;

  209.             if (strManifestMeasure.equalsIgnoreCase ("Price") || strManifestMeasure.equalsIgnoreCase ("PV"))
  210.                 dblManifestMeasurePriceTransformer = dcFunding.df (iExerciseDate);
  211.             else if (strManifestMeasure.equalsIgnoreCase ("ForwardRate") ||
  212.                 strManifestMeasure.equalsIgnoreCase ("ParForward") || strManifestMeasure.equalsIgnoreCase
  213.                     ("ParForwardRate") || strManifestMeasure.equalsIgnoreCase ("QuantoAdjustedParForward") ||
  214.                         strManifestMeasure.equalsIgnoreCase ("Rate"))
  215.                 dblManifestMeasurePriceTransformer = 10000. * dblFRADV01;

  216.             if (!org.drip.numerical.common.NumberUtil.IsValid (dblManifestMeasurePriceTransformer)) return null;

  217.             org.drip.pricer.option.Greeks optGreek = _fpg.greeks (iValueDate, iExerciseDate, dblStrike,
  218.                 dcFunding, dblATMManifestMeasure, !_bIsCaplet, true, dblIntegratedSurfaceVariance);

  219.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapResult = new
  220.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  221.             double dblForwardIntrinsic = optGreek.expectedPayoff();

  222.             double dblForwardATMIntrinsic = optGreek.expectedATMPayoff();

  223.             double dblSpotPrice = dblForwardIntrinsic * dblManifestMeasurePriceTransformer;

  224.             mapResult.put ("ATMFRA", dblATMManifestMeasure);

  225.             mapResult.put ("ATMPrice", dblForwardATMIntrinsic * dblManifestMeasurePriceTransformer);

  226.             mapResult.put ("CalcTime", (System.nanoTime() - lStart) * 1.e-09);

  227.             mapResult.put ("Charm", optGreek.charm() * dblManifestMeasurePriceTransformer);

  228.             mapResult.put ("Color", optGreek.color() * dblManifestMeasurePriceTransformer);

  229.             mapResult.put ("Delta", optGreek.delta() * dblManifestMeasurePriceTransformer);

  230.             mapResult.put ("EffectiveVolatility", optGreek.effectiveVolatility());

  231.             mapResult.put ("ExpectedATMPayoff", optGreek.expectedATMPayoff());

  232.             mapResult.put ("ExpectedPayoff", optGreek.expectedPayoff());

  233.             mapResult.put ("ForwardATMIntrinsic", dblForwardATMIntrinsic);

  234.             mapResult.put ("ForwardIntrinsic", dblForwardIntrinsic);

  235.             mapResult.put ("Gamma", optGreek.gamma() * dblManifestMeasurePriceTransformer);

  236.             mapResult.put ("IntegratedSurfaceVariance", dblIntegratedSurfaceVariance);

  237.             mapResult.put ("ManifestMeasureIntrinsic", dblManifestMeasureIntrinsic);

  238.             mapResult.put ("ManifestMeasureIntrinsicValue", dblManifestMeasureIntrinsic *
  239.                 dblManifestMeasurePriceTransformer);

  240.             mapResult.put ("ManifestMeasureTransformer", dblManifestMeasurePriceTransformer);

  241.             mapResult.put ("MoneynessFactor", dblMoneynessFactor);

  242.             mapResult.put ("Price", dblSpotPrice);

  243.             mapResult.put ("Prob1", optGreek.prob1());

  244.             mapResult.put ("Prob2", optGreek.prob2());

  245.             mapResult.put ("PV", dblSpotPrice * dblNotional);

  246.             mapResult.put ("Rho", optGreek.rho() * dblManifestMeasurePriceTransformer);

  247.             mapResult.put ("Speed", optGreek.speed() * dblManifestMeasurePriceTransformer);

  248.             mapResult.put ("SpotPrice", dblSpotPrice);

  249.             mapResult.put ("Theta", optGreek.theta() * dblManifestMeasurePriceTransformer);

  250.             mapResult.put ("Ultima", optGreek.ultima() * dblManifestMeasurePriceTransformer);

  251.             mapResult.put ("Upfront", dblSpotPrice);

  252.             mapResult.put ("Vanna", optGreek.vanna() * dblManifestMeasurePriceTransformer);

  253.             mapResult.put ("Vega", optGreek.vega() * dblManifestMeasurePriceTransformer);

  254.             mapResult.put ("Veta", optGreek.veta() * dblManifestMeasurePriceTransformer);

  255.             mapResult.put ("Vomma", optGreek.vomma() * dblManifestMeasurePriceTransformer);

  256.             return mapResult;
  257.         } catch (java.lang.Exception e) {
  258.             // e.printStackTrace();
  259.         }

  260.         return null;
  261.     }

  262.     /**
  263.      * Compute the Caplet/Floorlet Price from the Inputs
  264.      *
  265.      * @param valParams The Valuation Parameters
  266.      * @param pricerParams Pricer Parameters
  267.      * @param csqs The Market Parameters
  268.      * @param vcp The Valuation Customization Parameters
  269.      * @param dblVolatility The FRA Volatility
  270.      *
  271.      * @return The Caplet/Floorlet Price
  272.      *
  273.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  274.      */

  275.     public double price (
  276.         final org.drip.param.valuation.ValuationParams valParams,
  277.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  278.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  279.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  280.         final double dblVolatility)
  281.         throws java.lang.Exception
  282.     {
  283.         if (null == valParams || null == csqs || !org.drip.numerical.common.NumberUtil.IsValid (dblVolatility))
  284.             throw new java.lang.Exception ("FRAStandardCapFloorlet::price => Invalid Inputs");

  285.         org.drip.state.discount.MergedDiscountForwardCurve dcFunding = csqs.fundingState
  286.             (org.drip.state.identifier.FundingLabel.Standard (_fra.payCurrency()));

  287.         if (null == dcFunding)
  288.             throw new java.lang.Exception ("FRAStandardCapFloorlet::price => Invalid Inputs");

  289.         int iExerciseDate = exerciseDate().julian();

  290.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFRAOutput = _fra.value
  291.             (valParams, pricerParams, csqs, vcp);

  292.         java.lang.String strManifestMeasure = manifestMeasure();

  293.         if (null == mapFRAOutput || !mapFRAOutput.containsKey (strManifestMeasure))
  294.             throw new java.lang.Exception ("FRAStandardCapFloorlet::price => No ATM Metric");

  295.         double dblManifestMeasurePriceTransformer = java.lang.Double.NaN;

  296.         if (strManifestMeasure.equalsIgnoreCase ("Price") || strManifestMeasure.equalsIgnoreCase ("PV"))
  297.             dblManifestMeasurePriceTransformer = dcFunding.df (iExerciseDate);
  298.         else if (strManifestMeasure.equalsIgnoreCase ("ForwardRate") ||
  299.             strManifestMeasure.equalsIgnoreCase ("ParForward") || strManifestMeasure.equalsIgnoreCase
  300.                 ("ParForwardRate") || strManifestMeasure.equalsIgnoreCase ("QuantoAdjustedParForward") ||
  301.                     strManifestMeasure.equalsIgnoreCase ("Rate")) {
  302.             if (!mapFRAOutput.containsKey ("DV01"))
  303.                 throw new java.lang.Exception ("FRAStandardCapFloorlet::price => No FRA DV01");

  304.             dblManifestMeasurePriceTransformer = 10000. * mapFRAOutput.get ("DV01");
  305.         }

  306.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblManifestMeasurePriceTransformer))
  307.             throw new java.lang.Exception
  308.                 ("FRAStandardCapFloorlet::price => No Manifest Measure Price Transformer");

  309.         return dblManifestMeasurePriceTransformer * _fpg.payoff (valParams.valueDate(), iExerciseDate,
  310.             strike(), dcFunding, mapFRAOutput.get (strManifestMeasure), !_bIsCaplet, true, dblVolatility,
  311.                 false);
  312.     }

  313.     /**
  314.      * Imply the Flat Caplet/Floorlet Volatility from the Market Manifest Measure
  315.      *
  316.      * @param valParams The Valuation Parameters
  317.      * @param pricerParams Pricer Parameters
  318.      * @param csqs The Market Parameters
  319.      * @param vcp The Valuation Customization Parameters
  320.      * @param strCalibMeasure The Calibration Measure
  321.      * @param dblCalibValue The Calibration Value
  322.      *
  323.      * @return The Implied Caplet/Floorlet Volatility
  324.      *
  325.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  326.      */

  327.     public double implyVolatility (
  328.         final org.drip.param.valuation.ValuationParams valParams,
  329.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  330.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  331.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  332.         final java.lang.String strCalibMeasure,
  333.         final double dblCalibValue)
  334.         throws java.lang.Exception
  335.     {
  336.         if (null == valParams || null == strCalibMeasure || strCalibMeasure.isEmpty() || null == csqs ||
  337.             !org.drip.numerical.common.NumberUtil.IsValid (dblCalibValue))
  338.             throw new java.lang.Exception ("FRAStandardCapFloorlet::implyVolatility => Invalid Inputs");

  339.         final double dblStrike = strike();

  340.         final int iValueDate = valParams.valueDate();

  341.         final int iExerciseDate = exerciseDate().julian();

  342.         final org.drip.state.discount.MergedDiscountForwardCurve dcFunding = csqs.fundingState
  343.             (org.drip.state.identifier.FundingLabel.Standard (_fra.payCurrency()));

  344.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFRAOutput = _fra.value
  345.             (valParams, pricerParams, csqs, vcp);

  346.         java.lang.String strManifestMeasure = manifestMeasure();

  347.         if (null == mapFRAOutput || !mapFRAOutput.containsKey (strManifestMeasure))
  348.             throw new java.lang.Exception ("FRAStandardCapFloorlet::implyVolatility => No ATM Metric");

  349.         final double dblATMManifestMeasure = mapFRAOutput.get (strManifestMeasure);

  350.         double dblManifestMeasurePriceTransformer = java.lang.Double.NaN;

  351.         if (strManifestMeasure.equalsIgnoreCase ("Price") || strManifestMeasure.equalsIgnoreCase ("PV"))
  352.             dblManifestMeasurePriceTransformer = dcFunding.df (iExerciseDate);
  353.         else if (strManifestMeasure.equalsIgnoreCase ("ForwardRate") ||
  354.             strManifestMeasure.equalsIgnoreCase ("ParForward") || strManifestMeasure.equalsIgnoreCase
  355.                 ("ParForwardRate") || strManifestMeasure.equalsIgnoreCase ("QuantoAdjustedParForward") ||
  356.                     strManifestMeasure.equalsIgnoreCase ("Rate")) {
  357.             if (!mapFRAOutput.containsKey ("DV01"))
  358.                 throw new java.lang.Exception ("FRAStandardCapFloorlet::implyVolatility => No DV01");

  359.             dblManifestMeasurePriceTransformer = 10000. * mapFRAOutput.get ("DV01");
  360.         }

  361.         final double dblManifestMeasurePriceTransformerCalib = dblManifestMeasurePriceTransformer;

  362.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblManifestMeasurePriceTransformer))
  363.             throw new java.lang.Exception ("FRAStandardCapFloorlet::implyVolatility => No Transformer");

  364.         org.drip.function.definition.R1ToR1 funcVolPricer = new org.drip.function.definition.R1ToR1 (null) {
  365.             @Override public double evaluate (
  366.                 final double dblVolatility)
  367.                 throws java.lang.Exception
  368.             {
  369.                 if ("Price".equals (strCalibMeasure))
  370.                     return dblManifestMeasurePriceTransformerCalib * _fpg.payoff (iValueDate, iExerciseDate,
  371.                         dblStrike, dcFunding, dblATMManifestMeasure, !_bIsCaplet, true, dblVolatility,
  372.                             false);

  373.                 if ("ATMPrice".equals (strCalibMeasure))
  374.                     return dblManifestMeasurePriceTransformerCalib * _fpg.payoff (iValueDate, iExerciseDate,
  375.                         dblStrike, dcFunding, dblStrike, !_bIsCaplet, true, dblVolatility, false);

  376.                 java.util.Map<java.lang.String, java.lang.Double> mapOutput = valueFromSurfaceVariance
  377.                     (valParams, pricerParams, csqs, vcp, dblVolatility * dblVolatility * (iExerciseDate -
  378.                         iValueDate) / 365.25);

  379.                 if (null == mapOutput || !mapOutput.containsKey (strCalibMeasure))
  380.                     throw new java.lang.Exception
  381.                         ("FRAStandardCapFloorlet::implyVolatility => Cannot generate Calibration Measure");

  382.                 return mapOutput.get (strCalibMeasure);

  383.             }
  384.         };

  385.         org.drip.function.r1tor1solver.FixedPointFinderOutput fpfo = (new
  386.             org.drip.function.r1tor1solver.FixedPointFinderBrent (dblCalibValue, funcVolPricer,
  387.                 false)).findRoot();

  388.         if (null == fpfo || !fpfo.containsRoot())
  389.             throw new java.lang.Exception
  390.                 ("FRAStandardCapFloorlet::implyVolatility => Cannot calibrate the Vol");

  391.         return fpfo.getRoot();
  392.     }

  393.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> value (
  394.         final org.drip.param.valuation.ValuationParams valParams,
  395.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  396.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  397.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  398.     {
  399.         if (null == valParams || null == csqs) return null;

  400.         try {
  401.             return valueFromSurfaceVariance (valParams, pricerParams, csqs, vcp,
  402.                 org.drip.analytics.support.OptionHelper.IntegratedSurfaceVariance (csqs.forwardVolatility
  403.                     (_fra.forwardLabel().get ("DERIVED")), valParams.valueDate(), exerciseDate().julian()));
  404.         } catch (java.lang.Exception e) {
  405.             e.printStackTrace();
  406.         }

  407.         return null;
  408.     }

  409.     @Override public java.util.Set<java.lang.String> measureNames()
  410.     {
  411.         java.util.Set<java.lang.String> setstrMeasureNames = new java.util.TreeSet<java.lang.String>();

  412.         setstrMeasureNames.add ("ATMFRA");

  413.         setstrMeasureNames.add ("ATMPrice");

  414.         setstrMeasureNames.add ("CalcTime");

  415.         setstrMeasureNames.add ("Charm");

  416.         setstrMeasureNames.add ("Color");

  417.         setstrMeasureNames.add ("Delta");

  418.         setstrMeasureNames.add ("EffectiveVolatility");

  419.         setstrMeasureNames.add ("ExpectedATMPayoff");

  420.         setstrMeasureNames.add ("ExpectedPayoff");

  421.         setstrMeasureNames.add ("ForwardATMIntrinsic");

  422.         setstrMeasureNames.add ("ForwardIntrinsic");

  423.         setstrMeasureNames.add ("Gamma");

  424.         setstrMeasureNames.add ("IntegratedSurfaceVariance");

  425.         setstrMeasureNames.add ("ManifestMeasureIntrinsic");

  426.         setstrMeasureNames.add ("ManifestMeasureIntrinsicValue");

  427.         setstrMeasureNames.add ("MoneynessFactor");

  428.         setstrMeasureNames.add ("Price");

  429.         setstrMeasureNames.add ("Prob1");

  430.         setstrMeasureNames.add ("Prob2");

  431.         setstrMeasureNames.add ("PV");

  432.         setstrMeasureNames.add ("Rho");

  433.         setstrMeasureNames.add ("Speed");

  434.         setstrMeasureNames.add ("SpotPrice");

  435.         setstrMeasureNames.add ("Theta");

  436.         setstrMeasureNames.add ("Ultima");

  437.         setstrMeasureNames.add ("Upfront");

  438.         setstrMeasureNames.add ("Vanna");

  439.         setstrMeasureNames.add ("Vega");

  440.         setstrMeasureNames.add ("Veta");

  441.         setstrMeasureNames.add ("Vomma");

  442.         return setstrMeasureNames;
  443.     }

  444.     @Override public double pv (
  445.         final org.drip.param.valuation.ValuationParams valParams,
  446.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  447.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  448.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  449.         throws java.lang.Exception
  450.     {
  451.         if (null == csqc) throw new java.lang.Exception ("FRAStandardCapFloorlet::pv => Invalid Inputs");

  452.         org.drip.state.volatility.VolatilityCurve vc = csqc.forwardVolatility (_fra.forwardLabel().get
  453.             ("DERIVED"));

  454.         if (null == vc) throw new java.lang.Exception ("FRAStandardCapFloorlet::pv => Invalid Inputs");

  455.         return price (valParams, pricerParams, csqc, vcp, vc.impliedVol (exerciseDate().julian()));
  456.     }

  457.     @Override public org.drip.state.estimator.PredictorResponseWeightConstraint volatilityPRWC (
  458.         final org.drip.param.valuation.ValuationParams valParams,
  459.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  460.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  461.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  462.         final org.drip.product.calib.ProductQuoteSet pqs)
  463.     {
  464.         if (null == pqs || null == valParams || !(pqs instanceof
  465.             org.drip.product.calib.VolatilityProductQuoteSet))
  466.             return null;

  467.         double dblEndDate = maturityDate().julian();

  468.         if (valParams.valueDate() > dblEndDate) return null;

  469.         double dblOptionPV = 0.;
  470.         org.drip.product.calib.VolatilityProductQuoteSet vpqs =
  471.             (org.drip.product.calib.VolatilityProductQuoteSet) pqs;

  472.         if (!vpqs.containsOptionPV()) return null;

  473.         try {
  474.             dblOptionPV = vpqs.optionPV();
  475.         } catch (java.lang.Exception e) {
  476.             e.printStackTrace();

  477.             return null;
  478.         }

  479.         org.drip.state.estimator.PredictorResponseWeightConstraint prwc = _fra.stream().volatilityPRWC
  480.             (valParams, pricerParams, csqs, vcp, pqs);

  481.         if (null == prwc) return null;

  482.         if (!prwc.addPredictorResponseWeight (dblEndDate, 1.)) return null;

  483.         if (!prwc.addDResponseWeightDManifestMeasure ("OptionPV", dblEndDate, 1.)) return null;

  484.         return !prwc.updateValue (dblOptionPV) || !prwc.updateDValueDManifestMeasure ("OptionPV", 1.) ? null
  485.             : prwc;
  486.     }
  487. }