Package com.opengamma.analytics.financial.greeks

Examples of com.opengamma.analytics.financial.greeks.GreekResultCollection


          for (final double vol : VOLS) {
            final int nSteps = 1543;
            for (final double dividend : DIVIDENDS) {
              for (final double payoffStrike : PAYOFF_STRIKES) {
                final OptionFunctionProvider1D function = new GapOptionFunctionProvider(strike, TIME, nSteps, isCall, payoffStrike);
                final GreekResultCollection resDiv = _modelTrinomial.getGreeks(lattice, function, SPOT, vol, interest, dividend);
                final double priceDiv = price(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend, isCall);
                final double refPriceDiv = Math.max(Math.abs(priceDiv), 1.) * 5.e-2;
                assertEquals(resDiv.get(Greek.FAIR_PRICE), priceDiv, refPriceDiv);
                final double deltaDiv = delta(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend, isCall);
                final double refDeltaDiv = Math.max(Math.abs(deltaDiv), 0.1) * 1.e-1;
                assertEquals(resDiv.get(Greek.DELTA), deltaDiv, refDeltaDiv);
                final double gammaDiv = gamma(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend);
                final double refGammaDiv = Math.max(Math.abs(gammaDiv), 0.1) * 1.e-1;
                assertEquals(resDiv.get(Greek.GAMMA), gammaDiv, refGammaDiv);
                final double thetaDiv = theta(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend, isCall);
                final double refThetaDiv = Math.max(Math.abs(thetaDiv), 1.) * 1.e-1;
                assertEquals(resDiv.get(Greek.THETA), thetaDiv, refThetaDiv);
              }
            }
          }
        }
      }
View Full Code Here


            for (final double vol : VOLS) {
              for (final double payoffStrike : PAYOFF_STRIKES) {
                final int nSteps = 831;
                for (final double dividend : DIVIDENDS) {
                  final OptionFunctionProvider1D function = new GapOptionFunctionProvider(strike, TIME, nSteps, isCall, payoffStrike);
                  final GreekResultCollection resDiv = _model.getGreeks(lattice, function, SPOT, vol, interest, dividend);
                  final double priceDiv = price(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend, isCall);
                  final double refPriceDiv = Math.max(Math.abs(priceDiv), 1.) * 1.e-6;
                  assertEquals(resDiv.get(Greek.FAIR_PRICE), priceDiv, refPriceDiv);
                  final double deltaDiv = delta(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend, isCall);
                  final double refDeltaDiv = Math.max(Math.abs(deltaDiv), 1.) * 1.e-3;
                  assertEquals(resDiv.get(Greek.DELTA), deltaDiv, refDeltaDiv);
                  final double gammaDiv = gamma(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend);
                  final double refGammaDiv = Math.max(Math.abs(gammaDiv), 1.) * 1.e-3;
                  assertEquals(resDiv.get(Greek.GAMMA), gammaDiv, refGammaDiv);
                  final double thetaDiv = theta(SPOT, strike, payoffStrike, TIME, vol, interest, interest - dividend, isCall);
                  final double refThetaDiv = Math.max(Math.abs(thetaDiv), 1.) * 1.e-2;
                  assertEquals(resDiv.get(Greek.THETA), thetaDiv, refThetaDiv);
                }
              }
            }
          }
        }
View Full Code Here

    assertPriceEquals(definition, 0.6, 0.0691);
  }

  private void assertPriceEquals(final LogOptionDefinition definition, final double sigma, final double price) {
    final StandardOptionDataBundle bundle = getBundle(sigma);
    final GreekResultCollection actual = MODEL.getGreeks(definition, bundle, REQUIRED_GREEKS);
    assertEquals(actual.get(Greek.FAIR_PRICE), price, EPS);
  }
View Full Code Here

                final double appThetaCash = theta(modSpot, strike, payoffStrike, TIME, vol, interest, interest, isCall);

                final OptionFunctionProvider1D function = new GapOptionFunctionProvider(strike, TIME, nSteps, isCall, payoffStrike);
                final DividendFunctionProvider cashDividend = new CashDividendFunctionProvider(dividendTimes, cashDividends);
                final DividendFunctionProvider propDividend = new ProportionalDividendFunctionProvider(dividendTimes, propDividends);
                final GreekResultCollection resProp = _model.getGreeks(lattice, function, SPOT, vol, interest, propDividend);
                final GreekResultCollection resCash = _model.getGreeks(lattice, function, SPOT, vol, interest, cashDividend);

                assertEquals(resProp.get(Greek.FAIR_PRICE), exactPriceProp, Math.max(1., Math.abs(exactPriceProp)) * 1.e-2);
                assertEquals(resProp.get(Greek.DELTA), exactDeltaProp, Math.max(1., Math.abs(exactDeltaProp)) * 1.e-1);
                assertEquals(resProp.get(Greek.GAMMA), exactGammaProp, Math.max(1., Math.abs(exactGammaProp)) * 1.e-1);
                assertEquals(resProp.get(Greek.THETA), exactThetaProp, Math.max(1., Math.abs(exactThetaProp)) * 1.e-1);

                assertEquals(resCash.get(Greek.FAIR_PRICE), appPriceCash, Math.max(1., Math.abs(appPriceCash)) * 1.e-1);
                assertEquals(resCash.get(Greek.DELTA), appDeltaCash, Math.max(1., Math.abs(appDeltaCash)) * 1.e-1);
                assertEquals(resCash.get(Greek.GAMMA), appGammaCash, Math.max(1., Math.abs(appGammaCash)) * 1.e-1);
                assertEquals(resCash.get(Greek.THETA), appThetaCash, Math.max(1., Math.abs(appThetaCash)));//theta is poorly approximated

                final LatticeSpecification latticeTri = new TianLatticeSpecification();
                final int nStepsTri = 731;
                final OptionFunctionProvider1D functionTri = new GapOptionFunctionProvider(strike, TIME, nStepsTri, isCall, payoffStrike);
                final GreekResultCollection resPropTrinomial = _modelTrinomial.getGreeks(latticeTri, functionTri, SPOT, vol, interest, propDividend);
                final GreekResultCollection resCashTrinomial = _modelTrinomial.getGreeks(latticeTri, functionTri, SPOT, vol, interest, cashDividend);

                assertEquals(resPropTrinomial.get(Greek.FAIR_PRICE), exactPriceProp, Math.max(1., Math.abs(exactPriceProp)) * 1.e-1);
                assertEquals(resPropTrinomial.get(Greek.DELTA), exactDeltaProp, Math.max(1., Math.abs(exactDeltaProp)) * 1.e-1);
                assertEquals(resPropTrinomial.get(Greek.GAMMA), exactGammaProp, Math.max(1., Math.abs(exactGammaProp)) * 1.e-1);
                assertEquals(resPropTrinomial.get(Greek.THETA), exactThetaProp, Math.max(1., Math.abs(exactThetaProp)) * 1.e-1);

                assertEquals(resCashTrinomial.get(Greek.FAIR_PRICE), appPriceCash, Math.max(1., Math.abs(appPriceCash)) * 1.e-1);
                assertEquals(resCashTrinomial.get(Greek.DELTA), appDeltaCash, Math.max(1., Math.abs(appDeltaCash)) * 1.e-1);
                assertEquals(resCashTrinomial.get(Greek.GAMMA), appGammaCash, Math.max(1., Math.abs(appGammaCash)) * 1.e-1);
                assertEquals(resCashTrinomial.get(Greek.THETA), appThetaCash, Math.max(1., Math.abs(appThetaCash)));//theta is poorly approximated
              }
            }
          }
        }
      }
View Full Code Here

          final double volRef = Math.sqrt(constC * constC + 0.5 * constD * constD + 2. * constC * constD / time * (1. - Math.cos(time)) - constD * constD * 0.25 / time * Math.sin(2. * time));
          for (final double payoffStrike : PAYOFF_STRIKES) {

            final OptionFunctionProvider1D function = new GapOptionFunctionProvider(strike, time, steps, isCall, payoffStrike);
            final double resPrice = _model.getPrice(function, SPOT, vol, rate, dividend);
            final GreekResultCollection resGreeks = _model.getGreeks(function, SPOT, vol, rate, dividend);

            final double resPriceConst = _model.getPrice(lattice1, function, SPOT, volRef, rateRef, dividend[0]);
            final GreekResultCollection resGreeksConst = _model.getGreeks(lattice1, function, SPOT, volRef, rateRef, dividend[0]);
            assertEquals(resPrice, resPriceConst, Math.max(Math.abs(resPriceConst), 1.) * 1.e-1);
            assertEquals(resGreeks.get(Greek.FAIR_PRICE), resGreeksConst.get(Greek.FAIR_PRICE), Math.max(Math.abs(resGreeksConst.get(Greek.FAIR_PRICE)), 1.) * 0.1);
            assertEquals(resGreeks.get(Greek.DELTA), resGreeksConst.get(Greek.DELTA), Math.max(Math.abs(resGreeksConst.get(Greek.DELTA)), 1.) * 0.1);
            assertEquals(resGreeks.get(Greek.GAMMA), resGreeksConst.get(Greek.GAMMA), Math.max(Math.abs(resGreeksConst.get(Greek.GAMMA)), 1.) * 0.1);
            assertEquals(resGreeks.get(Greek.THETA), resGreeksConst.get(Greek.THETA), Math.max(Math.abs(resGreeksConst.get(Greek.THETA)), 1.));

            final OptionFunctionProvider1D functionTri = new GapOptionFunctionProvider(strike, time, stepsTri, isCall, payoffStrike);
            final double resPriceTrinomial = _modelTrinomial.getPrice(functionTri, SPOT, volTri, rateTri, dividendTri);
            assertEquals(resPriceTrinomial, resPriceConst, Math.max(Math.abs(resPriceConst), 1.));
            final GreekResultCollection resGreeksTrinomial = _modelTrinomial.getGreeks(functionTri, SPOT, volTri, rateTri, dividendTri);
            assertEquals(resGreeksTrinomial.get(Greek.FAIR_PRICE), resGreeksConst.get(Greek.FAIR_PRICE), Math.max(Math.abs(resGreeksConst.get(Greek.FAIR_PRICE)), 1.));
            assertEquals(resGreeksTrinomial.get(Greek.DELTA), resGreeksConst.get(Greek.DELTA), Math.max(Math.abs(resGreeksConst.get(Greek.DELTA)), 1.));
            assertEquals(resGreeksTrinomial.get(Greek.GAMMA), resGreeksConst.get(Greek.GAMMA), Math.max(Math.abs(resGreeksConst.get(Greek.GAMMA)), 1.));
            assertEquals(resGreeksTrinomial.get(Greek.THETA), resGreeksConst.get(Greek.THETA), Math.max(Math.abs(resGreeksConst.get(Greek.THETA)), 1.));
          }
        }
      }
    }
  }
View Full Code Here

      for (final double interest : INTERESTS) {
        for (final double vol : VOLS) {
          final int nSteps = 801;
          for (final double dividend : DIVIDENDS) {
            final OptionFunctionProvider1D function = new SupershareOptionFunctionProvider(TIME, lowerBound, upperBound, nSteps);
            final GreekResultCollection resDiv = _modelTrinomial.getGreeks(lattice, function, SPOT, vol, interest, dividend);
            final double priceDiv = price(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refPriceDiv = Math.max(Math.abs(priceDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.FAIR_PRICE), priceDiv, refPriceDiv);
            final double deltaDiv = delta(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refDeltaDiv = Math.max(Math.abs(deltaDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.DELTA), deltaDiv, refDeltaDiv);
            final double gammaDiv = gamma(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refGammaDiv = Math.max(Math.abs(gammaDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.GAMMA), gammaDiv, refGammaDiv);
            final double thetaDiv = theta(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refThetaDiv = Math.max(Math.abs(thetaDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.THETA), thetaDiv, refThetaDiv);
          }
        }
      }
    }
  }
View Full Code Here

        for (final double interest : INTERESTS) {
          for (final double vol : VOLS) {
            final int nSteps = 51;
            for (final double dividend : DIVIDENDS) {
              final OptionFunctionProvider1D function = new SupershareOptionFunctionProvider(TIME, lowerBound, upperBound, nSteps);
              final GreekResultCollection resDiv = _model.getGreeks(lattice, function, SPOT, vol, interest, dividend);
              final double priceDiv = price(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
              final double refPriceDiv = Math.max(Math.abs(priceDiv), 1.) * 1.e-1;
              assertEquals(resDiv.get(Greek.FAIR_PRICE), priceDiv, refPriceDiv);
              final double deltaDiv = delta(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
              final double refDeltaDiv = Math.max(Math.abs(deltaDiv), 1.) * 1.e-1;
              assertEquals(resDiv.get(Greek.DELTA), deltaDiv, refDeltaDiv);
              final double gammaDiv = gamma(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
              final double refGammaDiv = Math.max(Math.abs(gammaDiv), 1.) * 1.e-1;
              assertEquals(resDiv.get(Greek.GAMMA), gammaDiv, refGammaDiv);
              final double thetaDiv = theta(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
              final double refThetaDiv = Math.max(Math.abs(thetaDiv), 1.) * 1.e-1;
              assertEquals(resDiv.get(Greek.THETA), thetaDiv, refThetaDiv);
            }
          }
        }
      }
    }
View Full Code Here

      for (final double interest : INTERESTS) {
        for (final double vol : VOLS) {
          final int nSteps = 1047;
          for (final double dividend : DIVIDENDS) {
            final OptionFunctionProvider1D function = new SupershareOptionFunctionProvider(TIME, lowerBound, upperBound, nSteps);
            final GreekResultCollection resDiv = _model.getGreeks(lattice, function, SPOT, vol, interest, dividend);
            final double priceDiv = price(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refPriceDiv = Math.max(Math.abs(priceDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.FAIR_PRICE), priceDiv, refPriceDiv);
            final double deltaDiv = delta(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refDeltaDiv = Math.max(Math.abs(deltaDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.DELTA), deltaDiv, refDeltaDiv);
            final double gammaDiv = gamma(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refGammaDiv = Math.max(Math.abs(gammaDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.GAMMA), gammaDiv, refGammaDiv);
            final double thetaDiv = theta(SPOT, lowerBound, upperBound, TIME, vol, interest, interest - dividend);
            final double refThetaDiv = Math.max(Math.abs(thetaDiv), 1.) * 1.e-2;
            assertEquals(resDiv.get(Greek.THETA), thetaDiv, refThetaDiv);
          }
        }
      }
    }
  }
View Full Code Here

            final double appThetaCash = theta(modSpot, lowerBound, upperBound, TIME, vol, interest, interest);

            final OptionFunctionProvider1D function = new SupershareOptionFunctionProvider(TIME, lowerBound, upperBound, nSteps);
            final DividendFunctionProvider cashDividend = new CashDividendFunctionProvider(dividendTimes, cashDividends);
            final DividendFunctionProvider propDividend = new ProportionalDividendFunctionProvider(dividendTimes, propDividends);
            final GreekResultCollection resProp = _model.getGreeks(lattice, function, SPOT, vol, interest, propDividend);
            final GreekResultCollection resCash = _model.getGreeks(lattice, function, SPOT, vol, interest, cashDividend);

            assertEquals(resProp.get(Greek.FAIR_PRICE), exactPriceProp, Math.max(1., Math.abs(exactPriceProp)) * 1.e-1);
            assertEquals(resProp.get(Greek.DELTA), exactDeltaProp, Math.max(1., Math.abs(exactDeltaProp)) * 1.e-1);
            assertEquals(resProp.get(Greek.GAMMA), exactGammaProp, Math.max(1., Math.abs(exactGammaProp)) * 1.e-1);
            assertEquals(resProp.get(Greek.THETA), exactThetaProp, Math.max(1., Math.abs(exactThetaProp)) * 1.e-1);

            assertEquals(resCash.get(Greek.FAIR_PRICE), appPriceCash, Math.max(1., Math.abs(appPriceCash)) * 1.e-1);
            assertEquals(resCash.get(Greek.DELTA), appDeltaCash, Math.max(1., Math.abs(appDeltaCash)) * 1.e-1);
            assertEquals(resCash.get(Greek.GAMMA), appGammaCash, Math.max(1., Math.abs(appGammaCash)) * 1.e-1);
            assertEquals(resCash.get(Greek.THETA), appThetaCash, Math.max(1., Math.abs(appThetaCash)) * 1.e-1);

            if (lattice instanceof CoxRossRubinsteinLatticeSpecification || lattice instanceof JarrowRuddLatticeSpecification || lattice instanceof TrigeorgisLatticeSpecification ||
                lattice instanceof TianLatticeSpecification) {
              final int nStepsTri = 21;
              final OptionFunctionProvider1D functionTri = new SupershareOptionFunctionProvider(TIME, lowerBound, upperBound, nStepsTri);
              final GreekResultCollection resPropTrinomial = _modelTrinomial.getGreeks(lattice, functionTri, SPOT, vol, interest, propDividend);
              final GreekResultCollection resCashTrinomial = _modelTrinomial.getGreeks(lattice, functionTri, SPOT, vol, interest, cashDividend);

              assertEquals(resPropTrinomial.get(Greek.FAIR_PRICE), exactPriceProp, Math.max(1., Math.abs(exactPriceProp)) * 1.e-1);
              assertEquals(resPropTrinomial.get(Greek.DELTA), exactDeltaProp, Math.max(1., Math.abs(exactDeltaProp)) * 1.e-1);
              assertEquals(resPropTrinomial.get(Greek.GAMMA), exactGammaProp, Math.max(1., Math.abs(exactGammaProp)) * 1.e-1);
              assertEquals(resPropTrinomial.get(Greek.THETA), exactThetaProp, Math.max(1., Math.abs(exactThetaProp)) * 1.e-1);

              assertEquals(resCashTrinomial.get(Greek.FAIR_PRICE), appPriceCash, Math.max(1., Math.abs(appPriceCash)) * 1.e-1);
              assertEquals(resCashTrinomial.get(Greek.DELTA), appDeltaCash, Math.max(1., Math.abs(appDeltaCash)) * 1.e-1);
              assertEquals(resCashTrinomial.get(Greek.GAMMA), appGammaCash, Math.max(1., Math.abs(appGammaCash)) * 1.e-1);
              assertEquals(resCashTrinomial.get(Greek.THETA), appThetaCash, Math.max(1., Math.abs(appThetaCash)) * 1.e-1);
            }
          }
        }
      }
    }
View Full Code Here

        final double rateRef = constA + 0.5 * constB * time;
        final double volRef = Math.sqrt(constC * constC + 0.5 * constD * constD + 2. * constC * constD / time * (1. - Math.cos(time)) - constD * constD * 0.25 / time * Math.sin(2. * time));

        final OptionFunctionProvider1D function = new SupershareOptionFunctionProvider(time, lowerBound, upperBound, steps);
        final double resPrice = _model.getPrice(function, SPOT, vol, rate, dividend);
        final GreekResultCollection resGreeks = _model.getGreeks(function, SPOT, vol, rate, dividend);

        final double resPriceConst = _model.getPrice(lattice1, function, SPOT, volRef, rateRef, dividend[0]);
        final GreekResultCollection resGreeksConst = _model.getGreeks(lattice1, function, SPOT, volRef, rateRef, dividend[0]);
        assertEquals(resPrice, resPriceConst, Math.max(Math.abs(resPriceConst), 1.) * 1.e-2);
        assertEquals(resGreeks.get(Greek.FAIR_PRICE), resGreeksConst.get(Greek.FAIR_PRICE), Math.max(Math.abs(resGreeksConst.get(Greek.FAIR_PRICE)), 1.) * 1.e-2);
        assertEquals(resGreeks.get(Greek.DELTA), resGreeksConst.get(Greek.DELTA), Math.max(Math.abs(resGreeksConst.get(Greek.DELTA)), 1.) * 1.e-2);
        assertEquals(resGreeks.get(Greek.GAMMA), resGreeksConst.get(Greek.GAMMA), Math.max(Math.abs(resGreeksConst.get(Greek.GAMMA)), 1.) * 1.e-2);
        assertEquals(resGreeks.get(Greek.THETA), resGreeksConst.get(Greek.THETA), Math.max(Math.abs(resGreeksConst.get(Greek.THETA)), 1.));

        final OptionFunctionProvider1D functionTri = new SupershareOptionFunctionProvider(time, lowerBound, upperBound, stepsTri);
        final double resPriceTrinomial = _modelTrinomial.getPrice(functionTri, SPOT, volTri, rateTri, dividendTri);
        assertEquals(resPriceTrinomial, resPriceConst, Math.max(Math.abs(resPriceConst), 1.) * 1.e-1);
        final GreekResultCollection resGreeksTrinomial = _modelTrinomial.getGreeks(functionTri, SPOT, volTri, rateTri, dividendTri);
        assertEquals(resGreeksTrinomial.get(Greek.FAIR_PRICE), resGreeksConst.get(Greek.FAIR_PRICE), Math.max(Math.abs(resGreeksConst.get(Greek.FAIR_PRICE)), 1.) * 1.e-1);
        assertEquals(resGreeksTrinomial.get(Greek.DELTA), resGreeksConst.get(Greek.DELTA), Math.max(Math.abs(resGreeksConst.get(Greek.DELTA)), 1.) * 1.e-1);
        assertEquals(resGreeksTrinomial.get(Greek.GAMMA), resGreeksConst.get(Greek.GAMMA), Math.max(Math.abs(resGreeksConst.get(Greek.GAMMA)), 1.) * 1.e-1);
        assertEquals(resGreeksTrinomial.get(Greek.THETA), resGreeksConst.get(Greek.THETA), Math.max(Math.abs(resGreeksConst.get(Greek.THETA)), 0.1));
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.greeks.GreekResultCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.