public FDEuropeanEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { prices_ = new SampledCurve(gridPoints); process.registerWith(update); }
/*! \warning currently, this method returns the Black-Scholes implied volatility using analytic formulas for European options and a finite-difference method for American and Bermudan options. It will give unconsistent results if the pricing was performed with any other methods (such as jump-diffusion models.) \warning options with a gamma that changes sign (e.g., binary options) have values that are <b>not</b> monotonic in the volatility. In these cases, the calculation can fail and the result (if any) is almost meaningless. Another possible source of failure is to have a target value that is not attainable with any volatility, e.g., a target value lower than the intrinsic value in the case of American options. */ //public double impliedVolatility(double price, GeneralizedBlackScholesProcess process, // double accuracy = 1.0e-4, int maxEvaluations = 100, double minVol = 1.0e-7, double maxVol = 4.0) { public double impliedVolatility(double targetValue, GeneralizedBlackScholesProcess process, double accuracy, int maxEvaluations, double minVol, double maxVol) { if(isExpired()) throw new ApplicationException("option expired"); SimpleQuote volQuote = new SimpleQuote(); GeneralizedBlackScholesProcess newProcess = ImpliedVolatilityHelper.clone(process, volQuote); // engines are built-in for the time being IPricingEngine engine; switch (exercise_.type()) { case Exercise.Type.European: engine = new AnalyticEuropeanEngine(newProcess); break; case Exercise.Type.American: engine = new FDAmericanEngine(newProcess); break; case Exercise.Type.Bermudan: engine = new FDBermudanEngine(newProcess); break; default: throw new ArgumentException("unknown exercise type"); } return ImpliedVolatilityHelper.calculate(this, engine, volQuote, targetValue, accuracy, maxEvaluations, minVol, maxVol); }
public BSMOperator(Vector grid, GeneralizedBlackScholesProcess process, double residualTime) : base(grid.size()) { //PdeBSM::grid_type logGrid(grid); LogGrid logGrid = new LogGrid(grid); var cc = new PdeConstantCoeff<PdeBSM>(process, residualTime, process.stateVariable().link.value()); cc.generateOperator(residualTime, logGrid, this); }
//! default theta calculation for Black-Scholes options public static double blackScholesTheta(GeneralizedBlackScholesProcess p, double value, double delta, double gamma) { double u = p.stateVariable().currentLink().value(); double r = p.riskFreeRate().currentLink().zeroRate(0.0, Compounding.Continuous).rate(); double q = p.dividendYield().currentLink().zeroRate(0.0, Compounding.Continuous).rate(); double v = p.localVolatility().currentLink().localVol(0.0, u, false); return r *value -(r-q)*u *delta - 0.5 *v *v *u *u *gamma; }
public static TridiagonalOperator getOperator(GeneralizedBlackScholesProcess process, Vector grid, double residualTime, bool timeDependent) { if (timeDependent) //! Black-Scholes-Merton differential operator /*! \ingroup findiff \test coefficients are tested against constant BSM operator */ return new PdeOperator<PdeBSM>(grid, process, residualTime); else return new BSMOperator(grid, process, residualTime); }
public static GeneralizedBlackScholesProcess clone(GeneralizedBlackScholesProcess process, SimpleQuote volQuote) { Handle<Quote> stateVariable = process.stateVariable(); Handle<YieldTermStructure> dividendYield = process.dividendYield(); Handle<YieldTermStructure> riskFreeRate = process.riskFreeRate(); Handle<BlackVolTermStructure> blackVol = process.blackVolatility(); var volatility = new Handle<BlackVolTermStructure>(new BlackConstantVol(blackVol.link.referenceDate(), blackVol.link.calendar(), new Handle<Quote>(volQuote), blackVol.link.dayCounter())); return new GeneralizedBlackScholesProcess(stateVariable, dividendYield, riskFreeRate, volatility); }
public BjerksundStenslandApproximationEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public FDDividendEuropeanEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent = false) : base(process, timeSteps, gridPoints, timeDependent) { }
public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { // master data load this.indexOptionDAO_.SelectOwn(); // market data load // index data clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); string calcDateStr = calcDate.ToString("yyyyMMdd"); QLNet.Settings.setEvaluationDate(calcDate); clstb.REF_DT = calcDateStr; clstb.INDEX_CD = this.indexOptionDAO_.UNDERLYING_INDEX_CD; int checkNum = clstb.SelectOwn(); if (checkNum == 0) { throw new Exception("market data does not exist : " + calcDateStr + " " + clstb.INDEX_CD); } double indexData = clstb.LAST; // curveData -------------------------------------------------- string curve_cd = "IRSKRW"; YieldCurve curveManager = new YieldCurve(); curveManager.loadCurveData(calcDate,curve_cd,clsHDAT_CURVEDATA_TB.RATE_TYP_Type.YTM); QLNet.YieldTermStructure yield_ts = curveManager.yieldCurve(); // calculate string maturityDateStr = this.indexOptionDAO_.MATURITY_DT; System.Globalization.CultureInfo us = new System.Globalization.CultureInfo("en-US"); DateTime maturityDate = DateTime.ParseExact(maturityDateStr, "yyyyMMdd", us); DayCounter dc = new Actual365Fixed(); Calendar cal = new NullCalendar(); double vol = 0.3; double strike = this.indexOptionDAO_.STRIKE; PlainVanillaPayoff strikePayoff = new PlainVanillaPayoff(Option.Type. Call, strike); Exercise exercise = new EuropeanExercise(maturityDate); VanillaOption q_option = new VanillaOption(strikePayoff,exercise); Handle<Quote> x0 = new Handle<Quote>(new SimpleQuote(indexData)); FlatForward flatForward = new FlatForward(calcDate,0.01,dc); Handle<YieldTermStructure> dividendTS = new Handle<YieldTermStructure>(flatForward); Handle<YieldTermStructure> riskFreeTS = new Handle<YieldTermStructure>(yield_ts); BlackConstantVol blackConstVol = new BlackConstantVol(calcDate,cal,vol,dc); Handle<BlackVolTermStructure> blackVolTS = new Handle<BlackVolTermStructure>(blackConstVol); GeneralizedBlackScholesProcess process =new GeneralizedBlackScholesProcess(x0 ,dividendTS,riskFreeTS,blackVolTS); AnalyticEuropeanEngine europeanEngine = new AnalyticEuropeanEngine(process); q_option.setPricingEngine(europeanEngine); double value = q_option.NPV(); double indexMultiplier = this.indexOptionDAO_.INDEX_MULTIPLIER; int quantity = this.indexOptionDAO_.QUANTITY; clsHITM_FP_GREEKRESULT_TB result_tb = new clsHITM_FP_GREEKRESULT_TB(); result_tb.FP_GREEKRESULT_ID = IDGenerator.getNewGreekResultID(this.indexOptionDAO_.INSTRUMENT_ID,calcDateStr); result_tb.CALC_DT = calcDateStr; result_tb.INSTRUMENT_ID = this.indexOptionDAO_.INSTRUMENT_ID; result_tb.INSTRUMENT_TYP = this.indexOptionDAO_.INSTRUMENT_TYP; result_tb.UNDERLYING_ID = "KOSPI200"; result_tb.UNDERLYING_VALUE = indexData; //result_tb.SEQ = 1; result_tb.DELTA = (q_option.delta() * indexData / 100) * indexMultiplier * quantity; // 1% Delta result_tb.GAMMA = 0.5 * (q_option.gamma() * indexData / 100) * indexMultiplier * quantity; // 1% Gamma result_tb.VEGA = q_option.vega() / 100 * indexMultiplier * quantity; // 1% point Vega result_tb.CALC_PRICE = value * indexMultiplier * quantity; result_tb.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; result_tb.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); ; result_tb.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; // price if (result_tb.UpdateDateResult() == 0) { throw new Exception("update result fail. no exist , calcDate : " + calcDate.ToString("yyyyMMdd") + " , inst_id : " + result_tb.INSTRUMENT_ID); } // delta // gamma and others : no exist ? }
// this should be defined as new in each deriving class which use template iheritance // in order to return a proper class to wrap public virtual FDVanillaEngine factory(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) { return(new FDVanillaEngine(process, timeSteps, gridPoints, timeDependent)); }
//public FDDividendEngineBase(GeneralizedBlackScholesProcess process, // Size timeSteps = 100, Size gridPoints = 100, bool timeDependent = false) public FDDividendEngineBase(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { }
public override void calculate() { DayCounter rfdc = process_.riskFreeRate().link.dayCounter(); DayCounter divdc = process_.dividendYield().link.dayCounter(); DayCounter voldc = process_.blackVolatility().link.dayCounter(); Calendar volcal = process_.blackVolatility().link.calendar(); double s0 = process_.stateVariable().link.value(); Utils.QL_REQUIRE(s0 > 0.0, () => "negative or null underlying given"); double v = process_.blackVolatility().link.blackVol(arguments_.exercise.lastDate(), s0); Date maturityDate = arguments_.exercise.lastDate(); double r = process_.riskFreeRate().link.zeroRate(maturityDate, rfdc, Compounding.Continuous, Frequency.NoFrequency).value(); double q = process_.dividendYield().link.zeroRate(maturityDate, divdc, Compounding.Continuous, Frequency.NoFrequency).value(); Date referenceDate = process_.riskFreeRate().link.referenceDate(); // binomial trees with constant coefficient Handle <YieldTermStructure> flatRiskFree = new Handle <YieldTermStructure>(new FlatForward(referenceDate, r, rfdc)); Handle <YieldTermStructure> flatDividends = new Handle <YieldTermStructure>(new FlatForward(referenceDate, q, divdc)); Handle <BlackVolTermStructure> flatVol = new Handle <BlackVolTermStructure>(new BlackConstantVol(referenceDate, volcal, v, voldc)); StrikedTypePayoff payoff = arguments_.payoff as StrikedTypePayoff; Utils.QL_REQUIRE(payoff != null, () => "non-striked payoff given"); double maturity = rfdc.yearFraction(referenceDate, maturityDate); StochasticProcess1D bs = new GeneralizedBlackScholesProcess(process_.stateVariable(), flatDividends, flatRiskFree, flatVol); // correct timesteps to ensure a (local) minimum, using Boyle and Lau // approach. See Journal of Derivatives, 1/1994, // "Bumping up against the barrier with the binomial method" // Note: this approach works only for CoxRossRubinstein lattices, so // is disabled if T is not a CoxRossRubinstein or derived from it. int optimum_steps = timeSteps_; if (maxTimeSteps_ > timeSteps_ && s0 > 0 && arguments_.barrier > 0) // boost::is_base_of<CoxRossRubinstein, T>::value && { double divisor; if (s0 > arguments_.barrier) { divisor = Math.Pow(Math.Log(s0 / arguments_.barrier.Value), 2); } else { divisor = Math.Pow(Math.Log(arguments_.barrier.Value / s0), 2); } if (!Utils.close(divisor, 0)) { for (int i = 1; i < timeSteps_; ++i) { int optimum = (int)((i * i * v * v * maturity) / divisor); if (timeSteps_ < optimum) { optimum_steps = optimum; break; // found first minimum with iterations>=timesteps } } } if (optimum_steps > maxTimeSteps_) { optimum_steps = maxTimeSteps_; // too high, limit } } TimeGrid grid = new TimeGrid(maturity, optimum_steps); ITree tree = getTree_(bs, maturity, optimum_steps, payoff.strike()); BlackScholesLattice <ITree> lattice = new BlackScholesLattice <ITree>(tree, r, maturity, optimum_steps); DiscretizedAsset option = getAsset_(arguments_, process_, grid); option.initialize(lattice, maturity); // Partial derivatives calculated from various points in the // binomial tree // (see J.C.Hull, "Options, Futures and other derivatives", 6th edition, pp 397/398) // Rollback to third-last step, and get underlying prices (s2) & // option values (p2) at this point option.rollback(grid[2]); Vector va2 = new Vector(option.values()); Utils.QL_REQUIRE(va2.size() == 3, () => "Expect 3 nodes in grid at second step"); double p2u = va2[2]; // up double p2m = va2[1]; // mid double p2d = va2[0]; // down (low) double s2u = lattice.underlying(2, 2); // up price double s2m = lattice.underlying(2, 1); // middle price double s2d = lattice.underlying(2, 0); // down (low) price // calculate gamma by taking the first derivate of the two deltas double delta2u = (p2u - p2m) / (s2u - s2m); double delta2d = (p2m - p2d) / (s2m - s2d); double gamma = (delta2u - delta2d) / ((s2u - s2d) / 2); // Rollback to second-last step, and get option values (p1) at // this point option.rollback(grid[1]); Vector va = new Vector(option.values()); Utils.QL_REQUIRE(va.size() == 2, () => "Expect 2 nodes in grid at first step"); double p1u = va[1]; double p1d = va[0]; double s1u = lattice.underlying(1, 1); // up (high) price double s1d = lattice.underlying(1, 0); // down (low) price double delta = (p1u - p1d) / (s1u - s1d); // Finally, rollback to t=0 option.rollback(0.0); double p0 = option.presentValue(); // Store results results_.value = p0; results_.delta = delta; results_.gamma = gamma; // theta can be approximated by calculating the numerical derivative // between mid value at third-last step and at t0. The underlying price // is the same, only time varies. results_.theta = (p2m - p0) / grid[2]; }
public AnalyticContinuousPartialFixedLookbackEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public BaroneAdesiWhaleyApproximationEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public AnalyticContinuousGeometricAveragePriceAsianEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public MakeMCEuropeanEngine(GeneralizedBlackScholesProcess process) : base(process) { }
public override void calculate() { DayCounter rfdc = process_.riskFreeRate().link.dayCounter(); DayCounter divdc = process_.dividendYield().link.dayCounter(); DayCounter voldc = process_.blackVolatility().link.dayCounter(); Calendar volcal = process_.blackVolatility().link.calendar(); double s0 = process_.stateVariable().link.value(); if (!(s0 > 0.0)) { throw new Exception("negative or null underlying given"); } double v = process_.blackVolatility().link.blackVol(arguments_.exercise.lastDate(), s0); Date maturityDate = arguments_.exercise.lastDate(); double r = process_.riskFreeRate().link.zeroRate(maturityDate, rfdc, Compounding.Continuous, Frequency.NoFrequency).rate(); double q = process_.dividendYield().link.zeroRate(maturityDate, divdc, Compounding.Continuous, Frequency.NoFrequency).rate(); Date referenceDate = process_.riskFreeRate().link.referenceDate(); // binomial trees with constant coefficient var flatRiskFree = new Handle <YieldTermStructure>(new FlatForward(referenceDate, r, rfdc)); var flatDividends = new Handle <YieldTermStructure>(new FlatForward(referenceDate, q, divdc)); var flatVol = new Handle <BlackVolTermStructure>(new BlackConstantVol(referenceDate, volcal, v, voldc)); PlainVanillaPayoff payoff = arguments_.payoff as PlainVanillaPayoff; if (payoff == null) { throw new Exception("non-plain payoff given"); } double maturity = rfdc.yearFraction(referenceDate, maturityDate); StochasticProcess1D bs = new GeneralizedBlackScholesProcess(process_.stateVariable(), flatDividends, flatRiskFree, flatVol); TimeGrid grid = new TimeGrid(maturity, timeSteps_); T tree = new T().factory(bs, maturity, timeSteps_, payoff.strike()); BlackScholesLattice <T> lattice = new BlackScholesLattice <T>(tree, r, maturity, timeSteps_); DiscretizedVanillaOption option = new DiscretizedVanillaOption(arguments_, process_, grid); option.initialize(lattice, maturity); // Partial derivatives calculated from various points in the // binomial tree (Odegaard) // Rollback to third-last step, and get underlying price (s2) & // option values (p2) at this point option.rollback(grid[2]); Vector va2 = new Vector(option.values()); if (!(va2.size() == 3)) { throw new Exception("Expect 3 nodes in grid at second step"); } double p2h = va2[2]; // high-price double s2 = lattice.underlying(2, 2); // high price // Rollback to second-last step, and get option value (p1) at // this point option.rollback(grid[1]); Vector va = new Vector(option.values()); if (!(va.size() == 2)) { throw new Exception("Expect 2 nodes in grid at first step"); } double p1 = va[1]; // Finally, rollback to t=0 option.rollback(0.0); double p0 = option.presentValue(); double s1 = lattice.underlying(1, 1); // Calculate partial derivatives double delta0 = (p1 - p0) / (s1 - s0); // dp/ds double delta1 = (p2h - p1) / (s2 - s1); // dp/ds // Store results results_.value = p0; results_.delta = delta0; results_.gamma = 2.0 * (delta1 - delta0) / (s2 - s0); //d(delta)/ds results_.theta = Utils.blackScholesTheta(process_, results_.value.GetValueOrDefault(), results_.delta.GetValueOrDefault(), results_.gamma.GetValueOrDefault()); }
public IFDEngine factory(GeneralizedBlackScholesProcess process, int timeSteps = 100 , int gridPoints = 100) { return new FDDividendAmericanEngine(process, timeSteps, gridPoints); }
//protected FDMultiPeriodEngine(GeneralizedBlackScholesProcess process, // int gridPoints = 100, int timeSteps = 100, bool timeDependent = false) protected FDMultiPeriodEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { timeStepPerPeriod_ = timeSteps; }
//protected FDMultiPeriodEngine(GeneralizedBlackScholesProcess process, // int gridPoints = 100, int timeSteps = 100, bool timeDependent = false) protected FDMultiPeriodEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { timeStepPerPeriod_ = timeSteps; }
public override void calculate() { DayCounter rfdc = process_.riskFreeRate().link.dayCounter(); DayCounter divdc = process_.dividendYield().link.dayCounter(); DayCounter voldc = process_.blackVolatility().link.dayCounter(); Calendar volcal = process_.blackVolatility().link.calendar(); double s0 = process_.stateVariable().link.value(); Utils.QL_REQUIRE(s0 > 0.0, () => "negative or null underlying given"); double v = process_.blackVolatility().link.blackVol(arguments_.exercise.lastDate(), s0); Date maturityDate = arguments_.exercise.lastDate(); double r = process_.riskFreeRate().link.zeroRate(maturityDate, rfdc, Compounding.Continuous, Frequency.NoFrequency).value(); double q = process_.dividendYield().link.zeroRate(maturityDate, divdc, Compounding.Continuous, Frequency.NoFrequency).value(); Date referenceDate = process_.riskFreeRate().link.referenceDate(); // binomial trees with constant coefficient Handle <YieldTermStructure> flatRiskFree = new Handle <YieldTermStructure>(new FlatForward(referenceDate, r, rfdc)); Handle <YieldTermStructure> flatDividends = new Handle <YieldTermStructure>(new FlatForward(referenceDate, q, divdc)); Handle <BlackVolTermStructure> flatVol = new Handle <BlackVolTermStructure>(new BlackConstantVol(referenceDate, volcal, v, voldc)); StrikedTypePayoff payoff = arguments_.payoff as StrikedTypePayoff; Utils.QL_REQUIRE(payoff != null, () => "non-striked payoff given"); double maturity = rfdc.yearFraction(referenceDate, maturityDate); StochasticProcess1D bs = new GeneralizedBlackScholesProcess(process_.stateVariable(), flatDividends, flatRiskFree, flatVol); TimeGrid grid = new TimeGrid(maturity, timeSteps_); ITree tree = getTree_(bs, maturity, timeSteps_, payoff.strike()); BlackScholesLattice <ITree> lattice = new BlackScholesLattice <ITree>(tree, r, maturity, timeSteps_); DiscretizedAsset option = getAsset_(arguments_, process_, grid); option.initialize(lattice, maturity); // Partial derivatives calculated from various points in the // binomial tree // (see J.C.Hull, "Options, Futures and other derivatives", 6th edition, pp 397/398) // Rollback to third-last step, and get underlying prices (s2) & // option values (p2) at this point option.rollback(grid[2]); Vector va2 = new Vector(option.values()); Utils.QL_REQUIRE(va2.size() == 3, () => "Expect 3 nodes in grid at second step"); double p2u = va2[2]; // up double p2m = va2[1]; // mid double p2d = va2[0]; // down (low) double s2u = lattice.underlying(2, 2); // up price double s2m = lattice.underlying(2, 1); // middle price double s2d = lattice.underlying(2, 0); // down (low) price // calculate gamma by taking the first derivate of the two deltas double delta2u = (p2u - p2m) / (s2u - s2m); double delta2d = (p2m - p2d) / (s2m - s2d); double gamma = (delta2u - delta2d) / ((s2u - s2d) / 2); // Rollback to second-last step, and get option values (p1) at // this point option.rollback(grid[1]); Vector va = new Vector(option.values()); Utils.QL_REQUIRE(va.size() == 2, () => "Expect 2 nodes in grid at first step"); double p1u = va[1]; double p1d = va[0]; double s1u = lattice.underlying(1, 1); // up (high) price double s1d = lattice.underlying(1, 0); // down (low) price double delta = (p1u - p1d) / (s1u - s1d); // Finally, rollback to t=0 option.rollback(0.0); double p0 = option.presentValue(); // Store results results_.value = p0; results_.delta = delta; results_.gamma = gamma; // theta can be approximated by calculating the numerical derivative // between mid value at third-last step and at t0. The underlying price // is the same, only time varies. results_.theta = (p2m - p0) / grid[2]; }
public override PdeSecondOrderParabolic factory(GeneralizedBlackScholesProcess process) { return new PdeBSM(process); }
public BjerksundStenslandApproximationEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public abstract FDVanillaEngine factory2(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent);
// constructor public FDBermudanEngine(GeneralizedBlackScholesProcess process, int timeSteps = 100, int gridPoints = 100, bool timeDependent = false) : base(process, timeSteps, gridPoints, timeDependent) { }
//public FDEngineAdapter(GeneralizedBlackScholesProcess process, Size timeSteps=100, Size gridPoints=100, bool timeDependent = false) public FDEngineAdapter(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) { optionBase = (Base)FastActivator <Base> .Create().factory(process, timeSteps, gridPoints, timeDependent); process.registerWith(update); }
public override PdeSecondOrderParabolic factory(GeneralizedBlackScholesProcess process) { throw new NotSupportedException(); //return new PdeShortRate(process); }
//public FDStepConditionEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, // bool timeDependent = false) public FDStepConditionEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { controlBCs_ = new InitializedList<BoundaryCondition<IOperator>>(2); controlPrices_ = new SampledCurve(gridPoints); }
//public FDEuropeanEngine(GeneralizedBlackScholesProcess process, // Size timeSteps=100, Size gridPoints=100, bool timeDependent = false) { public FDEuropeanEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints) : this(process, timeSteps, gridPoints, false) { }
public FDShoutEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { }
public ForwardPerformanceVanillaEngine(GeneralizedBlackScholesProcess process, GetOriginalEngine getEngine) : base(process, getEngine) { }
public void testBSMOperatorConsistency() { //("Testing consistency of BSM operators..."); Vector grid = new Vector(10); double price = 20.0; double factor = 1.1; for (int i = 0; i < grid.size(); i++) { grid[i] = price; price *= factor; } double dx = Math.Log(factor); double r = 0.05; double q = 0.01; double sigma = 0.5; BSMOperator refer = new BSMOperator(grid.size(), dx, r, q, sigma); DayCounter dc = new Actual360(); Date today = Date.Today; Date exercise = today + new Period(2, TimeUnit.Years); double residualTime = dc.yearFraction(today, exercise); SimpleQuote spot = new SimpleQuote(0.0); YieldTermStructure qTS = Utilities.flatRate(today, q, dc); YieldTermStructure rTS = Utilities.flatRate(today, r, dc); BlackVolTermStructure volTS = Utilities.flatVol(today, sigma, dc); GeneralizedBlackScholesProcess stochProcess = new GeneralizedBlackScholesProcess( new Handle<Quote>(spot), new Handle<YieldTermStructure>(qTS), new Handle<YieldTermStructure>(rTS), new Handle<BlackVolTermStructure>(volTS)); BSMOperator op1 = new BSMOperator(grid, stochProcess, residualTime); PdeOperator<PdeBSM> op2 = new PdeOperator<PdeBSM>(grid, stochProcess, residualTime); double tolerance = 1.0e-6; Vector lderror = refer.lowerDiagonal() - op1.lowerDiagonal(); Vector derror = refer.diagonal() - op1.diagonal(); Vector uderror = refer.upperDiagonal() - op1.upperDiagonal(); for (int i = 2; i < grid.size() - 2; i++) { if (Math.Abs(lderror[i]) > tolerance || Math.Abs(derror[i]) > tolerance || Math.Abs(uderror[i]) > tolerance) { Assert.Fail("inconsistency between BSM operators:\n" + i + " row:\n" + "expected: " + refer.lowerDiagonal()[i] + ", " + refer.diagonal()[i] + ", " + refer.upperDiagonal()[i] + "\n" + "calculated: " + op1.lowerDiagonal()[i] + ", " + op1.diagonal()[i] + ", " + op1.upperDiagonal()[i]); } } lderror = refer.lowerDiagonal() - op2.lowerDiagonal(); derror = refer.diagonal() - op2.diagonal(); uderror = refer.upperDiagonal() - op2.upperDiagonal(); for (int i = 2; i < grid.size() - 2; i++) { if (Math.Abs(lderror[i]) > tolerance || Math.Abs(derror[i]) > tolerance || Math.Abs(uderror[i]) > tolerance) { Assert.Fail("inconsistency between BSM operators:\n" + i + " row:\n" + "expected: " + refer.lowerDiagonal()[i] + ", " + refer.diagonal()[i] + ", " + refer.upperDiagonal()[i] + "\n" + "calculated: " + op2.lowerDiagonal()[i] + ", " + op2.diagonal()[i] + ", " + op2.upperDiagonal()[i]); } } }
public IFDEngine factory(GeneralizedBlackScholesProcess process) { return(new FDShoutEngine(process, 100, 100, false)); }
public JuQuadraticApproximationEngine(GeneralizedBlackScholesProcess process) { process_ = process; //registerWith(process_); process_.registerWith(update); }
//public FDShoutCondition(GeneralizedBlackScholesProcess process, // Size timeSteps = 100, Size gridPoints = 100, bool timeDependent = false) public FDShoutCondition(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { engine_.setStepCondition(initializeStepConditionImpl); }
public AnalyticContinuousGeometricAveragePriceAsianEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public FDConditionEngineTemplate(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { }
public IntegralEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public FDConditionTemplate(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) : base(process, timeSteps, gridPoints, timeDependent) { // init engine engine_ = (baseEngine) new baseEngine().factory(process, timeSteps, gridPoints, timeDependent); }
public PdeBSM(GeneralizedBlackScholesProcess process) { process_ = process; }
// required for template inheritance public override FDVanillaEngine factory(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) { return(new FDAmericanCondition <baseEngine>(process, timeSteps, gridPoints, timeDependent)); }
public override FDVanillaEngine factory2(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) { throw new NotImplementedException(); }
// constructor public FDBermudanEngine(GeneralizedBlackScholesProcess process, int timeSteps = 100, int gridPoints = 100, bool timeDependent = false) : base(process, timeSteps, gridPoints, timeDependent) { }
public override FDVanillaEngine factory(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) { return factory2(process, timeSteps, gridPoints, timeDependent); }
public AnalyticDividendEuropeanEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
//public FDEuropeanEngine(GeneralizedBlackScholesProcess process, // Size timeSteps=100, Size gridPoints=100, bool timeDependent = false) { public FDEuropeanEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints) : this(process, timeSteps, gridPoints, false) { }
public ForwardVanillaEngine(GeneralizedBlackScholesProcess process, GetOriginalEngine getEngine) { process_ = process; process_.registerWith(update); getOriginalEngine_ = getEngine; }
public AnalyticBarrierEngine(GeneralizedBlackScholesProcess process) { process_ = process; //registerWith(process_); process_.registerWith(update); }
public IntegralEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public BaroneAdesiWhaleyApproximationEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }
public MakeMCAmericanEngine(GeneralizedBlackScholesProcess process) : base(process) { }
public AnalyticBarrierEngine(GeneralizedBlackScholesProcess process) { process_ = process; //registerWith(process_); process_.registerWith(update); }
public JuQuadraticApproximationEngine(GeneralizedBlackScholesProcess process) { process_ = process; process_.registerWith(update); }