public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case 3373707:         // name
                    this.name = (SwaptionVolatilitiesName)newValue;
                    break;

                case 2039569265:         // convention
                    this.convention = (FixedIborSwapConvention)newValue;
                    break;

                case 1905311443:         // dayCount
                    this.dayCount = (DayCount)newValue;
                    break;

                case 2096253127:         // interpolator
                    this.interpolator = (SurfaceInterpolator)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
Exemple #2
0
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case -450004177:         // metadata
                    this.metadata_Renamed = (SurfaceMetadata)newValue;
                    break;

                case 1681280954:         // xValues
                    this.xValues_Renamed = (DoubleArray)newValue;
                    break;

                case -1726182661:         // yValues
                    this.yValues_Renamed = (DoubleArray)newValue;
                    break;

                case -838678980:         // zValues
                    this.zValues_Renamed = (DoubleArray)newValue;
                    break;

                case 2096253127:         // interpolator
                    this.interpolator_Renamed = (SurfaceInterpolator)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
Exemple #3
0
 /// <summary>
 /// Restricted copy constructor. </summary>
 /// <param name="beanToCopy">  the bean to copy from, not null </param>
 internal Builder(InterpolatedNodalSurface beanToCopy)
 {
     this.metadata_Renamed     = beanToCopy.Metadata;
     this.xValues_Renamed      = beanToCopy.XValues;
     this.yValues_Renamed      = beanToCopy.YValues;
     this.zValues_Renamed      = beanToCopy.ZValues;
     this.interpolator_Renamed = beanToCopy.Interpolator;
 }
 private SabrSwaptionDefinition(SwaptionVolatilitiesName name, FixedIborSwapConvention convention, DayCount dayCount, SurfaceInterpolator interpolator)
 {
     JodaBeanUtils.notNull(name, "name");
     JodaBeanUtils.notNull(convention, "convention");
     JodaBeanUtils.notNull(dayCount, "dayCount");
     JodaBeanUtils.notNull(interpolator, "interpolator");
     this.name         = name;
     this.convention   = convention;
     this.dayCount     = dayCount;
     this.interpolator = interpolator;
 }
Exemple #5
0
        // constructor that sorts (artificial boolean flag)
        private InterpolatedNodalSurface(SurfaceMetadata metadata, DoubleArray xValues, DoubleArray yValues, DoubleArray zValues, SurfaceInterpolator interpolator, bool sort)
        {
            validateInputs(metadata, xValues, yValues, zValues, interpolator);
            // sort inputs
            IDictionary <DoublesPair, ObjDoublePair <ParameterMetadata> > sorted = new SortedDictionary <DoublesPair, ObjDoublePair <ParameterMetadata> >();

            for (int i = 0; i < xValues.size(); i++)
            {
                ParameterMetadata pm = metadata.getParameterMetadata(i);
                sorted[DoublesPair.of(xValues.get(i), yValues.get(i))] = ObjDoublePair.of(pm, zValues.get(i));
            }
            double[]            sortedX  = new double[sorted.Count];
            double[]            sortedY  = new double[sorted.Count];
            double[]            sortedZ  = new double[sorted.Count];
            ParameterMetadata[] sortedPm = new ParameterMetadata[sorted.Count];
            int pos = 0;

            foreach (KeyValuePair <DoublesPair, ObjDoublePair <ParameterMetadata> > entry in sorted.SetOfKeyValuePairs())
            {
                sortedX[pos]  = entry.Key.First;
                sortedY[pos]  = entry.Key.Second;
                sortedZ[pos]  = entry.Value.Second;
                sortedPm[pos] = entry.Value.First;
                pos++;
            }
            // assign
            SurfaceMetadata sortedMetadata = metadata.withParameterMetadata(Arrays.asList(sortedPm));

            this.metadata = sortedMetadata;
            this.xValues  = DoubleArray.ofUnsafe(sortedX);
            this.yValues  = DoubleArray.ofUnsafe(sortedY);
            this.zValues  = DoubleArray.ofUnsafe(sortedZ);
            IDictionary <DoublesPair, double> pairs = new Dictionary <DoublesPair, double>();

            for (int i = 0; i < xValues.size(); i++)
            {
                pairs[DoublesPair.of(xValues.get(i), yValues.get(i))] = zValues.get(i);
            }
            this.interpolator      = interpolator;
            this.boundInterpolator = interpolator.bind(this.xValues, this.yValues, this.zValues);
            this.parameterMetadata = IntStream.range(0, ParameterCount).mapToObj(i => sortedMetadata.getParameterMetadata(i)).collect(toImmutableList());
        }
Exemple #6
0
        //-------------------------------------------------------------------------
        // restricted constructor
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ImmutableConstructor private InterpolatedNodalSurface(SurfaceMetadata metadata, com.opengamma.strata.collect.array.DoubleArray xValues, com.opengamma.strata.collect.array.DoubleArray yValues, com.opengamma.strata.collect.array.DoubleArray zValues, com.opengamma.strata.market.surface.interpolator.SurfaceInterpolator interpolator)
        private InterpolatedNodalSurface(SurfaceMetadata metadata, DoubleArray xValues, DoubleArray yValues, DoubleArray zValues, SurfaceInterpolator interpolator)
        {
            validateInputs(metadata, xValues, yValues, zValues, interpolator);
            for (int i = 1; i < xValues.size(); i++)
            {
                if (xValues.get(i) < xValues.get(i - 1))
                {
                    throw new System.ArgumentException("Array of x-values must be sorted");
                }
                if (xValues.get(i) == xValues.get(i - 1) && yValues.get(i) <= yValues.get(i - 1))
                {
                    throw new System.ArgumentException("Array of y-values must be sorted and unique within x-values");
                }
            }
            this.metadata          = metadata;
            this.xValues           = xValues;
            this.yValues           = yValues;
            this.zValues           = zValues;
            this.interpolator      = interpolator;
            this.boundInterpolator = interpolator.bind(xValues, yValues, zValues);
            this.parameterMetadata = IntStream.range(0, ParameterCount).mapToObj(i => metadata.getParameterMetadata(i)).collect(toImmutableList());
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance from the name, convention, day count and tenors.
 /// </summary>
 /// <param name="name">  the name of the volatilities </param>
 /// <param name="convention">  the swap convention that the volatilities are to be used for </param>
 /// <param name="dayCount">  the day count to use </param>
 /// <param name="interpolator">  the interpolator for the alpha, rho and nu surfaces </param>
 /// <returns> the volatilities </returns>
 public static SabrSwaptionDefinition of(SwaptionVolatilitiesName name, FixedIborSwapConvention convention, DayCount dayCount, SurfaceInterpolator interpolator)
 {
     return(new SabrSwaptionDefinition(name, convention, dayCount, interpolator));
 }
Exemple #8
0
 /// <summary>
 /// Creates an instance by specifying the number of steps, maximum time, and 2D interpolator.
 /// </summary>
 /// <param name="nSteps">  number of steps </param>
 /// <param name="maxTime">  the maximum time </param>
 /// <param name="interpolator">  the interpolator </param>
 public ImpliedTrinomialTreeLocalVolatilityCalculator(int nSteps, double maxTime, SurfaceInterpolator interpolator)
 {
     this.nSteps       = nSteps;
     this.maxTime      = maxTime;
     this.interpolator = interpolator;
 }
Exemple #9
0
        static FxOptionVolatilitiesMarketDataFunctionTest()
        {
            ImmutableList.Builder <FxOptionVolatilitiesNode>        volNodeBuilder             = ImmutableList.builder();
            ImmutableMap.Builder <QuoteId, double>                  marketQuoteBuilder         = ImmutableMap.builder();
            ImmutableMap.Builder <QuoteId, MarketDataBox <double> > scenarioMarketQuoteBuilder = ImmutableMap.builder();
            ImmutableList.Builder <FixedOvernightSwapCurveNode>     usdNodeBuilder             = ImmutableList.builder();
            ImmutableList.Builder <FxSwapCurveNode>                 gbpNodeBuilder             = ImmutableList.builder();
            for (int i = 0; i < VOL_TENORS.Count; ++i)
            {
                for (int j = 0; j < STRIKES.Count; ++j)
                {
                    QuoteId quoteId = QuoteId.of(StandardId.of("OG", VOL_TENORS[i].ToString() + "_" + STRIKES[j].Label + "_" + VALUE_TYPES[j].ToString()));
                    volNodeBuilder.add(FxOptionVolatilitiesNode.of(GBP_USD, SPOT_OFFSET, BDA, VALUE_TYPES[j], quoteId, VOL_TENORS[i], STRIKES[j]));
                    marketQuoteBuilder.put(quoteId, VOL_QUOTES[i][j]);
                    scenarioMarketQuoteBuilder.put(quoteId, MarketDataBox.ofScenarioValues(VOL_QUOTES[i][j], VOL_QUOTES_1[i][j]));
                }
            }
            for (int i = 0; i < USD_QUOTES.Count; ++i)
            {
                QuoteId quoteId = QuoteId.of(StandardId.of("OG", USD.ToString() + "-OIS-" + USD_TENORS[i].ToString()));
                usdNodeBuilder.add(FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(USD_TENORS[i], FixedOvernightSwapConventions.USD_FIXED_TERM_FED_FUND_OIS), quoteId));
                marketQuoteBuilder.put(quoteId, USD_QUOTES[i]);
                scenarioMarketQuoteBuilder.put(quoteId, MarketDataBox.ofScenarioValues(USD_QUOTES[i], USD_QUOTES_1[i]));
            }
            for (int i = 0; i < GBP_QUOTES.Count; ++i)
            {
                QuoteId quoteId = QuoteId.of(StandardId.of("OG", GBP_USD.ToString() + "-FX-" + GBP_PERIODS[i].ToString()));
                gbpNodeBuilder.add(FxSwapCurveNode.of(FxSwapTemplate.of(GBP_PERIODS[i], FxSwapConventions.GBP_USD), quoteId));
                marketQuoteBuilder.put(quoteId, GBP_QUOTES[i]);
                scenarioMarketQuoteBuilder.put(quoteId, MarketDataBox.ofScenarioValues(GBP_QUOTES[i], GBP_QUOTES_1[i]));
            }
            VOL_NODES              = volNodeBuilder.build();
            USD_NODES              = usdNodeBuilder.build();
            GBP_NODES              = gbpNodeBuilder.build();
            MARKET_QUOTES          = marketQuoteBuilder.build();
            SCENARIO_MARKET_QUOTES = scenarioMarketQuoteBuilder.build();
            IList <double> expiry  = VOL_TENORS.Select(t => ACT_365F.relativeYearFraction(VALUATION_DATE, BDA.adjust(SPOT_OFFSET.adjust(VALUATION_DATE, REF_DATA).plus(t), REF_DATA))).ToList();
            int            nSmiles = expiry.Count;

            double[] atm = new double[nSmiles];
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] rr = new double[nSmiles][2];
            double[][] rr = RectangularArrays.ReturnRectangularDoubleArray(nSmiles, 2);
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] str = new double[nSmiles][2];
            double[][] str = RectangularArrays.ReturnRectangularDoubleArray(nSmiles, 2);
            for (int i = 0; i < nSmiles; ++i)
            {
                atm[i]    = VOL_QUOTES[i][0];
                rr[i][0]  = VOL_QUOTES[i][1];
                rr[i][1]  = VOL_QUOTES[i][3];
                str[i][0] = VOL_QUOTES[i][2];
                str[i][1] = VOL_QUOTES[i][4];
            }
            InterpolatedStrikeSmileDeltaTermStructure term = InterpolatedStrikeSmileDeltaTermStructure.of(DoubleArray.copyOf(expiry), DoubleArray.of(0.1, 0.25), DoubleArray.copyOf(atm), DoubleMatrix.copyOf(rr), DoubleMatrix.copyOf(str), ACT_365F, LINEAR, FLAT, FLAT, PCHIP, FLAT, FLAT);

            EXP_VOLS = BlackFxOptionSmileVolatilities.of(VOL_NAME, GBP_USD, VALUATION_DATE.atTime(VALUATION_TIME).atZone(ZONE), term);
            for (int i = 0; i < nSmiles; ++i)
            {
                atm[i]    = VOL_QUOTES_1[i][0];
                rr[i][0]  = VOL_QUOTES_1[i][1];
                rr[i][1]  = VOL_QUOTES_1[i][3];
                str[i][0] = VOL_QUOTES_1[i][2];
                str[i][1] = VOL_QUOTES_1[i][4];
            }
            InterpolatedStrikeSmileDeltaTermStructure term1 = InterpolatedStrikeSmileDeltaTermStructure.of(DoubleArray.copyOf(expiry), DoubleArray.of(0.1, 0.25), DoubleArray.copyOf(atm), DoubleMatrix.copyOf(rr), DoubleMatrix.copyOf(str), ACT_365F, LINEAR, FLAT, FLAT, PCHIP, FLAT, FLAT);

            EXP_VOLS_1 = BlackFxOptionSmileVolatilities.of(VOL_NAME, GBP_USD, VALUATION_DATE_1.atTime(VALUATION_TIME_1).atZone(ZONE), term1);
            ImmutableList.Builder <FxOptionVolatilitiesNode> nodeBuilder  = ImmutableList.builder();
            ImmutableMap.Builder <QuoteId, double>           quoteBuilder = ImmutableMap.builder();
            for (int i = 0; i < SURFACE_TENORS.Count; ++i)
            {
                for (int j = 0; j < SURFACE_STRIKES.Count; ++j)
                {
                    QuoteId quoteId = QuoteId.of(StandardId.of("OG", GBP_USD.ToString() + "_" + SURFACE_TENORS[i].ToString() + "_" + SURFACE_STRIKES[j]));
                    quoteBuilder.put(quoteId, SURFACE_VOL_QUOTES[i][j]);
                    nodeBuilder.add(FxOptionVolatilitiesNode.of(GBP_USD, SPOT_OFFSET, BDA, ValueType.BLACK_VOLATILITY, quoteId, SURFACE_TENORS[i], SimpleStrike.of(SURFACE_STRIKES[j])));
                }
            }
            SURFACE_NODES  = nodeBuilder.build();
            SURFACE_QUOTES = quoteBuilder.build();
            IList <double> expiry = new List <double>();
            IList <double> strike = new List <double>();
            IList <double> vols   = new List <double>();

            for (int i = 0; i < SURFACE_TENORS.Count; ++i)
            {
                for (int j = 0; j < SURFACE_STRIKES.Count; ++j)
                {
                    double yearFraction = ACT_365F.relativeYearFraction(VALUATION_DATE, BDA.adjust(SPOT_OFFSET.adjust(VALUATION_DATE, REF_DATA).plus(SURFACE_TENORS[i]), REF_DATA));
                    expiry.Add(yearFraction);
                    strike.Add(SURFACE_STRIKES[j]);
                    vols.Add(SURFACE_VOL_QUOTES[i][j]);
                }
            }
            SurfaceInterpolator      interp  = GridSurfaceInterpolator.of(LINEAR, PCHIP);
            InterpolatedNodalSurface surface = InterpolatedNodalSurface.ofUnsorted(Surfaces.blackVolatilityByExpiryStrike(VOL_NAME.Name, ACT_365F), DoubleArray.copyOf(expiry), DoubleArray.copyOf(strike), DoubleArray.copyOf(vols), interp);

            SURFACE_EXP_VOLS = BlackFxOptionSurfaceVolatilities.of(VOL_NAME, GBP_USD, VALUATION_DATE.atTime(VALUATION_TIME).atZone(ZONE), surface);
        }
Exemple #10
0
 /// <summary>
 /// Sets the underlying interpolator. </summary>
 /// <param name="interpolator">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder interpolator(SurfaceInterpolator interpolator)
 {
     JodaBeanUtils.notNull(interpolator, "interpolator");
     this.interpolator_Renamed = interpolator;
     return(this);
 }
Exemple #11
0
 // basic validation
 private void validateInputs(SurfaceMetadata metadata, DoubleArray xValues, DoubleArray yValues, DoubleArray zValues, SurfaceInterpolator interpolator)
 {
     ArgChecker.notNull(metadata, "metadata");
     ArgChecker.notNull(xValues, "times");
     ArgChecker.notNull(yValues, "values");
     ArgChecker.notNull(interpolator, "interpolator");
     if (xValues.size() < 2)
     {
         throw new System.ArgumentException("Length of x-values must be at least 2");
     }
     if (xValues.size() != yValues.size())
     {
         throw new System.ArgumentException("Length of x-values and y-values must match");
     }
     if (xValues.size() != zValues.size())
     {
         throw new System.ArgumentException("Length of x-values and z-values must match");
     }
     metadata.ParameterMetadata.ifPresent(@params =>
     {
         if (xValues.size() != @params.size())
         {
             throw new System.ArgumentException("Length of x-values and parameter metadata must match when metadata present");
         }
     });
 }
Exemple #12
0
 /// <summary>
 /// Creates an interpolated surface with metadata, where the values are not sorted.
 /// <para>
 /// The value arrays will be sorted, by x-values then y-values.
 /// Both the z-values and parameter metadata will be sorted along with the x and y values.
 ///
 /// </para>
 /// </summary>
 /// <param name="metadata">  the surface metadata </param>
 /// <param name="xValues">  the x-values </param>
 /// <param name="yValues">  the y-values </param>
 /// <param name="zValues">  the z-values </param>
 /// <param name="interpolator">  the interpolator </param>
 /// <returns> the surface </returns>
 public static InterpolatedNodalSurface ofUnsorted(SurfaceMetadata metadata, DoubleArray xValues, DoubleArray yValues, DoubleArray zValues, SurfaceInterpolator interpolator)
 {
     return(new InterpolatedNodalSurface(metadata, xValues, yValues, zValues, interpolator, true));
 }