Beispiel #1
0
 public ForwardVanillaOption(double moneyness, Date resetDate, StrikedTypePayoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_ForwardVanillaOption(moneyness, Date.getCPtr(resetDate), StrikedTypePayoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #2
0
 private void REPORT_FAILURE(string greekName,
                             StrikedTypePayoff payoff,
                             Exercise exercise,
                             Barrier.Type barrierType,
                             double barrier,
                             double s,
                             double q,
                             double r,
                             Date today,
                             double v,
                             double expected,
                             double calculated,
                             double error,
                             double tolerance)
 {
     QAssert.Fail(payoff.optionType() + " option with "
                  + barrierType + " barrier type:\n"
                  + "    barrier:          " + barrier + "\n"
                  + payoff + " payoff:\n"
                  + exercise + " "
                  + payoff.optionType()
                  + "    spot value: " + s + "\n"
                  + "    strike:           " + payoff.strike() + "\n"
                  + "    dividend yield:   " + q + "\n"
                  + "    risk-free rate:   " + r + "\n"
                  + "    reference date:   " + today + "\n"
                  + "    maturity:         " + exercise.lastDate() + "\n"
                  + "    volatility:       " + v + "\n\n"
                  + "    expected " + greekName + ":   " + expected + "\n"
                  + "    calculated " + greekName + ": " + calculated + "\n"
                  + "    error:            " + error + "\n"
                  + "    tolerance:        " + tolerance);
 }
Beispiel #3
0
 void REPORT_FAILURE_FIXED(string greekName,
                           double minmax,
                           StrikedTypePayoff payoff,
                           Exercise exercise,
                           double s,
                           double q,
                           double r,
                           Date today,
                           double v,
                           double expected,
                           double calculated,
                           double error,
                           double tolerance)
 {
     QAssert.Fail(exercise.GetType() + " "
                  + payoff.optionType() + " lookback option with "
                  + payoff + " payoff:\n"
                  + "    underlying value  " + s + "\n"
                  + "    strike:           " + payoff.strike() + "\n"
                  + "    dividend yield:   " + q + "\n"
                  + "    risk-free rate:   " + r + "\n"
                  + "    reference date:   " + today + "\n"
                  + "    maturity:         " + exercise.lastDate() + "\n"
                  + "    volatility:       " + v + "\n\n"
                  + "    expected " + greekName + ":   " + expected + "\n"
                  + "    calculated " + greekName + ": " + calculated + "\n"
                  + "    error:            " + error + "\n"
                  + "    tolerance:        " + tolerance);
 }
 public BlackCalculator(StrikedTypePayoff payoff, double forward, double stdDev) : this(NQuantLibcPINVOKE.new_BlackCalculator__SWIG_1(StrikedTypePayoff.getCPtr(payoff), forward, stdDev), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public ContinuousAveragingAsianOption(Average.Type averageType, StrikedTypePayoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_ContinuousAveragingAsianOption((int)averageType, StrikedTypePayoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #6
0
 public EuropeanOption(StrikedTypePayoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_EuropeanOption(StrikedTypePayoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #7
0
 public void REPORT_FAILURE_VANNAVOLGA(string greekName, DoubleBarrier.Type barrierType,
                                       double barrier1, double barrier2, double rebate,
                                       StrikedTypePayoff payoff, Exercise exercise, double s, double q,
                                       double r, Date today, double vol25Put, double atmVol, double vol25Call, double v,
                                       double expected, double calculated, double error, double tolerance)
 {
     QAssert.Fail("Double Barrier Option " + barrierType + " " + exercise + " "
                  + payoff.optionType() + " option with "
                  + payoff + " payoff:\n"
                  + "    underlying value: " + s + "\n"
                  + "    strike:           " + payoff.strike() + "\n"
                  + "    barrier 1:        " + barrier1 + "\n"
                  + "    barrier 2:        " + barrier2 + "\n"
                  + "    rebate :          " + rebate + "\n"
                  + "    dividend yield:   " + q + "\n"
                  + "    risk-free rate:   " + r + "\n"
                  + "    reference date:   " + today + "\n"
                  + "    maturity:         " + exercise.lastDate() + "\n"
                  + "    25PutVol:         " + +(vol25Put) + "\n"
                  + "    atmVol:           " + (atmVol) + "\n"
                  + "    25CallVol:        " + (vol25Call) + "\n"
                  + "    volatility:       " + v + "\n\n"
                  + "    expected " + greekName + ":   " + expected + "\n"
                  + "    calculated " + greekName + ": " + calculated + "\n"
                  + "    error:            " + error + "\n"
                  + "    tolerance:        " + tolerance);
 }
 // Constructor
 public OptionPosition(StrikedTypePayoff payoff, Exercise exercise, DateTime TradeDate, double SpotAtStrikeDate, DayCounter dayCounter)
 {
     _option       = new VanillaOption(payoff, exercise);
     _dayCounter   = dayCounter;
     _expiryDate   = exercise.lastDate();
     _spotAtStrike = SpotAtStrikeDate;
     _tradeDate    = TradeDate;
 }
Beispiel #9
0
 public ForwardVanillaOption(double moneyness,
                             Date resetDate,
                             StrikedTypePayoff payoff,
                             Exercise exercise)
     : base(payoff, exercise)
 {
     moneyness_ = moneyness;
     resetDate_ = resetDate;
 }
Beispiel #10
0
 public DoubleBarrierOption(DoubleBarrier.Type barrierType,
                            double barrier_lo,
                            double barrier_hi,
                            double rebate,
                            StrikedTypePayoff payoff,
                            Exercise exercise)
     : base(payoff, exercise)
 {
     barrierType_ = barrierType;
     barrier_lo_  = barrier_lo;
     barrier_hi_  = barrier_hi;
     rebate_      = rebate;
 }
Beispiel #11
0
 private void REPORT_FAILURE(string greekName,
                             StrikedTypePayoff payoff,
                             Exercise exercise,
                             double expected,
                             double calculated,
                             double tolerance,
                             Date today)
 {
     QAssert.Fail(exercise + " "
                  + "Spread option with "
                  + payoff + " payoff:\n"
                  + "    strike:           " + payoff.strike() + "\n"
                  + "    reference date:   " + today + "\n"
                  + "    maturity:         " + exercise.lastDate() + "\n"
                  + "    expected " + greekName + ":   " + expected + "\n"
                  + "    calculated " + greekName + ": " + calculated + "\n"
                  + "    error:            " + Math.Abs(expected - calculated) + "\n"
                  + "    tolerance:        " + tolerance);
 }
Beispiel #12
0
        public override void calculate()
        {
            AmericanExercise ex = arguments_.exercise as AmericanExercise;

            Utils.QL_REQUIRE(ex != null, () => "non-American exercise given");
            Utils.QL_REQUIRE(ex.dates()[0] <= process_.blackVolatility().link.referenceDate(), () =>
                             "American option with window exercise not handled yet");

            StrikedTypePayoff payoff = arguments_.payoff as StrikedTypePayoff;

            Utils.QL_REQUIRE(payoff != null, () => "non-striked payoff given");

            double spot = process_.stateVariable().link.value();

            Utils.QL_REQUIRE(spot > 0.0, () => "negative or null underlying given");

            double variance         = process_.blackVolatility().link.blackVariance(ex.lastDate(), payoff.strike());
            double dividendDiscount = process_.dividendYield().link.discount(ex.lastDate());
            double riskFreeDiscount = process_.riskFreeRate().link.discount(ex.lastDate());

            if (ex.payoffAtExpiry())
            {
                AmericanPayoffAtExpiry pricer = new AmericanPayoffAtExpiry(spot, riskFreeDiscount,
                                                                           dividendDiscount, variance,
                                                                           payoff, knock_in());
                results_.value = pricer.value();
            }
            else
            {
                AmericanPayoffAtHit pricer = new AmericanPayoffAtHit(spot, riskFreeDiscount, dividendDiscount, variance, payoff);
                results_.value = pricer.value();
                results_.delta = pricer.delta();
                results_.gamma = pricer.gamma();

                DayCounter rfdc = process_.riskFreeRate().link.dayCounter();
                double     t    = rfdc.yearFraction(process_.riskFreeRate().link.referenceDate(),
                                                    arguments_.exercise.lastDate());
                results_.rho = pricer.rho(t);
            }
        }
Beispiel #13
0
 public EuropeanOption(StrikedTypePayoff payoff, Exercise exercise) : base(payoff, exercise)
 {
 }
 public ContinuousFixedLookbackOption(double minmax, StrikedTypePayoff payoff, Exercise exercise)
     : base(payoff, exercise)
 {
     minmax_ = minmax;
 }
 public ContinuousPartialFixedLookbackOption(Date lookbackPeriodStart, StrikedTypePayoff payoff, Exercise exercise)
     : base(0, payoff, exercise)
 {
     lookbackPeriodStart_ = lookbackPeriodStart;
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StrikedTypePayoff obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Beispiel #17
0
        VanillaOption makeOption(StrikedTypePayoff payoff, Exercise exercise, Quote u, YieldTermStructure q,
                                 YieldTermStructure r, BlackVolTermStructure vol, EngineType engineType, int binomialSteps, int samples)
        {
            GeneralizedBlackScholesProcess stochProcess = makeProcess(u, q, r, vol);

            IPricingEngine engine;

            switch (engineType)
            {
            case EngineType.Analytic:
                engine = new AnalyticEuropeanEngine(stochProcess);
                break;

            case EngineType.JR:
                engine = new BinomialVanillaEngine <JarrowRudd>(stochProcess, binomialSteps);
                break;

            case EngineType.CRR:
                engine = new BinomialVanillaEngine <CoxRossRubinstein>(stochProcess, binomialSteps);
                break;

            case EngineType.EQP:
                engine = new BinomialVanillaEngine <AdditiveEQPBinomialTree>(stochProcess, binomialSteps);
                break;

            case EngineType.TGEO:
                engine = new BinomialVanillaEngine <Trigeorgis>(stochProcess, binomialSteps);
                break;

            case EngineType.TIAN:
                engine = new BinomialVanillaEngine <Tian>(stochProcess, binomialSteps);
                break;

            case EngineType.LR:
                engine = new BinomialVanillaEngine <LeisenReimer>(stochProcess, binomialSteps);
                break;

            case EngineType.JOSHI:
                engine = new BinomialVanillaEngine <Joshi4>(stochProcess, binomialSteps);
                break;

            case EngineType.FiniteDifferences:
                engine = new FDEuropeanEngine(stochProcess, binomialSteps, samples);
                break;

            case EngineType.Integral:
                engine = new IntegralEngine(stochProcess);
                break;

            //case EngineType.PseudoMonteCarlo:
            //  engine = MakeMCEuropeanEngine<PseudoRandom>(stochProcess)
            //      .withSteps(1)
            //      .withSamples(samples)
            //      .withSeed(42);
            //  break;
            //case EngineType.QuasiMonteCarlo:
            //  engine = MakeMCEuropeanEngine<LowDiscrepancy>(stochProcess)
            //      .withSteps(1)
            //      .withSamples(samples);
            //  break;
            default:
                throw new ArgumentException("unknown engine type");
            }

            VanillaOption option = new EuropeanOption(payoff, exercise);

            option.setPricingEngine(engine);
            return(option);
        }
Beispiel #18
0
 public DiscreteAveragingAsianOption(Average.Type averageType, double runningAccumulator, uint pastFixings, DateVector fixingDates, StrikedTypePayoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_DiscreteAveragingAsianOption((int)averageType, runningAccumulator, pastFixings, DateVector.getCPtr(fixingDates), StrikedTypePayoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public DoubleBarrierOption(DoubleBarrier.Type barrierType, double barrier_lo, double barrier_hi, double rebate, StrikedTypePayoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_DoubleBarrierOption((int)barrierType, barrier_lo, barrier_hi, rebate, StrikedTypePayoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #20
0
 public BarrierOption(Barrier.Type barrierType, double barrier, double rebate, StrikedTypePayoff payoff, Exercise exercise) : base(payoff, exercise)
 {
     barrierType_ = barrierType;
     barrier_     = barrier;
     rebate_      = rebate;
 }
 public DividendVanillaOption(StrikedTypePayoff payoff, Exercise exercise, DateVector dividendDates, DoubleVector dividends) : this(NQuantLibcPINVOKE.new_DividendVanillaOption(StrikedTypePayoff.getCPtr(payoff), Exercise.getCPtr(exercise), DateVector.getCPtr(dividendDates), DoubleVector.getCPtr(dividends)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }