Skip to content

Commit

Permalink
Avoid deprecated classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Nov 14, 2019
1 parent 1980839 commit 5a249c4
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 34 deletions.
12 changes: 6 additions & 6 deletions CSharp/examples/EquityOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ static void Main(string[] args)
// Finite differences
try {
europeanOption.setPricingEngine(
new FDEuropeanEngine(stochasticProcess,
timeSteps, timeSteps - 1));
new FdBlackScholesVanillaEngine(stochasticProcess,
timeSteps, timeSteps - 1));
bermudanOption.setPricingEngine(
new FDBermudanEngine(stochasticProcess,
timeSteps, timeSteps - 1));
new FdBlackScholesVanillaEngine(stochasticProcess,
timeSteps, timeSteps - 1));
americanOption.setPricingEngine(
new FDAmericanEngine(stochasticProcess,
timeSteps, timeSteps - 1));
new FdBlackScholesVanillaEngine(stochasticProcess,
timeSteps, timeSteps - 1));
ReportResults("Finite differences",
europeanOption.NPV(),
bermudanOption.NPV(),
Expand Down
13 changes: 7 additions & 6 deletions Java/examples/EquityOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
import org.quantlib.DayCounter;
import org.quantlib.EuropeanExercise;
import org.quantlib.Exercise;
import org.quantlib.FDAmericanEngine;
import org.quantlib.FDBermudanEngine;
import org.quantlib.FDEuropeanEngine;
import org.quantlib.FdBlackScholesVanillaEngine;
import org.quantlib.HestonModel;
import org.quantlib.HestonProcess;
import org.quantlib.FlatForward;
Expand Down Expand Up @@ -233,13 +231,16 @@ public static void main(String[] args) throws Exception {
// Finite differences
int timeSteps = 801;
method = "Finite differences";
europeanOption.setPricingEngine(new FDEuropeanEngine(stochasticProcess,
europeanOption.setPricingEngine(
new FdBlackScholesVanillaEngine(stochasticProcess,
timeSteps,
timeSteps-1));
bermudanOption.setPricingEngine(new FDBermudanEngine(stochasticProcess,
bermudanOption.setPricingEngine(
new FdBlackScholesVanillaEngine(stochasticProcess,
timeSteps,
timeSteps-1));
americanOption.setPricingEngine(new FDAmericanEngine(stochasticProcess,
americanOption.setPricingEngine(
new FdBlackScholesVanillaEngine(stochasticProcess,
timeSteps,
timeSteps-1));
System.out.printf(fmt, new Object[] { method,
Expand Down
2 changes: 1 addition & 1 deletion Python/examples/american-option.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def report(method, x, dx=None):
timeSteps = 801
gridPoints = 800

option.setPricingEngine(ql.FDAmericanEngine(process, timeSteps, gridPoints))
option.setPricingEngine(ql.FdBlackScholesVanillaEngine(process, timeSteps, gridPoints))
report("finite differences", option.NPV())

# method: binomial
Expand Down
2 changes: 1 addition & 1 deletion Python/examples/european-option.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def report(method, x, dx=None):
timeSteps = 801
gridPoints = 800

option.setPricingEngine(ql.FDEuropeanEngine(process, timeSteps, gridPoints))
option.setPricingEngine(ql.FdBlackScholesVanillaEngine(process, timeSteps, gridPoints))
report("finite diff.", option.NPV())

# method: binomial
Expand Down
2 changes: 1 addition & 1 deletion R/demo/european-option.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ report('integral', option$NPV())
timeSteps <- 801
gridPoints <- 800

invisible(option$setPricingEngine(FDEuropeanEngine(process,timeSteps,gridPoints)))
invisible(option$setPricingEngine(FdBlackScholesVanillaEngine(process,timeSteps,gridPoints)))
report('finite diff.', option$NPV())


Expand Down
2 changes: 1 addition & 1 deletion R/demo/fd-option.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ process <- BlackScholesMertonProcess(QuoteHandle(underlying),
YieldTermStructureHandle(riskFreeRate),
BlackVolTermStructureHandle(volatility))
option <- VanillaOption(payoff, exercise)
invisible(option$setPricingEngine(s_arg2=FDEuropeanEngine(process)))
invisible(option$setPricingEngine(s_arg2=FdBlackScholesVanillaEngine(process)))
priceCurve <- option$priceCurve()

print(summary(as.data.frame(priceCurve)))
Expand Down
2 changes: 1 addition & 1 deletion Ruby/examples/american-option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def report(method, x, dx = nil)
timeSteps = 801
gridPoints = 800

option.pricingEngine = FDAmericanEngine.new(process,timeSteps,gridPoints)
option.pricingEngine = FdBlackScholesVanillaEngine.new(process,timeSteps,gridPoints)
report('finite differences',option.NPV)

# method: binomial
Expand Down
2 changes: 1 addition & 1 deletion Ruby/examples/european-option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def report(method, x, dx = nil)
timeSteps = 801
gridPoints = 800

option.pricingEngine = FDEuropeanEngine.new(process,timeSteps,gridPoints)
option.pricingEngine = FdBlackScholesVanillaEngine.new(process,timeSteps,gridPoints)
report('finite diff.',option.NPV)

# method: binomial
Expand Down
84 changes: 78 additions & 6 deletions SWIG/options.i
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ typedef QuantLib::FDBermudanEngine<CrankNicolson> FDBermudanEngine;

%shared_ptr(FDBermudanEngine)
class FDBermudanEngine : public PricingEngine {
#if defined(SWIGPYTHON)
%pythonprepend FDBermudanEngine %{
from warnings import warn
warn("FDBermudanEngine is deprecated; use FdBlackScholesVanillaEngine")
%}
#endif
public:
FDBermudanEngine(const boost::shared_ptr<GeneralizedBlackScholesProcess>& process,
Size timeSteps = 100, Size gridPoints = 100,
Expand All @@ -476,6 +482,12 @@ typedef QuantLib::FDEuropeanEngine<CrankNicolson> FDEuropeanEngine;

%shared_ptr(FDEuropeanEngine)
class FDEuropeanEngine : public PricingEngine {
#if defined(SWIGPYTHON)
%pythonprepend FDEuropeanEngine %{
from warnings import warn
warn("FDEuropeanEngine is deprecated; use FdBlackScholesVanillaEngine")
%}
#endif
public:
FDEuropeanEngine(const boost::shared_ptr<GeneralizedBlackScholesProcess> process,
Size timeSteps = 100, Size gridPoints = 100,
Expand Down Expand Up @@ -787,6 +799,12 @@ typedef QuantLib::FDShoutEngine<CrankNicolson> FDShoutEngine;

%shared_ptr(FDAmericanEngine)
class FDAmericanEngine : public PricingEngine {
#if defined(SWIGPYTHON)
%pythonprepend FDAmericanEngine %{
from warnings import warn
warn("FDAmericanEngine is deprecated; use FdBlackScholesVanillaEngine")
%}
#endif
public:
FDAmericanEngine(const boost::shared_ptr<GeneralizedBlackScholesProcess>& process,
Size timeSteps = 100, Size gridPoints = 100,
Expand Down Expand Up @@ -934,6 +952,12 @@ using QuantLib::FDDividendAmericanEngine;
%rename(FDDividendEuropeanEngineT) FDDividendEuropeanEngine;
template <class S>
class FDDividendEuropeanEngine : public PricingEngine {
#if defined(SWIGPYTHON)
%pythonprepend FDDividendEuropeanEngine %{
from warnings import warn
warn("FDDividendEuropeanEngine is deprecated; use FdBlackScholesVanillaEngine")
%}
#endif
public:
FDDividendEuropeanEngine(const boost::shared_ptr<GeneralizedBlackScholesProcess>& process,
Size timeSteps = 100,
Expand All @@ -949,6 +973,12 @@ class FDDividendEuropeanEngine : public PricingEngine {
%rename(FDDividendAmericanEngineT) FDDividendAmericanEngine;
template <class S>
class FDDividendAmericanEngine : public PricingEngine {
#if defined(SWIGPYTHON)
%pythonprepend FDDividendAmericanEngine %{
from warnings import warn
warn("FDDividendAmericanEngine is deprecated; use FdBlackScholesVanillaEngine")
%}
#endif
public:
FDDividendAmericanEngine(const boost::shared_ptr<GeneralizedBlackScholesProcess>& process,
Size timeSteps = 100,
Expand Down Expand Up @@ -1124,22 +1154,45 @@ using QuantLib::FdHestonVanillaEngine;
%shared_ptr(FdBlackScholesVanillaEngine)
class FdBlackScholesVanillaEngine : public PricingEngine {
public:
enum CashDividendModel { Spot, Escrowed };

FdBlackScholesVanillaEngine(
const boost::shared_ptr<GeneralizedBlackScholesProcess>& process,
Size tGrid = 100, Size xGrid = 100, Size dampingSteps = 0,
const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Douglas(),
bool localVol = false,
Real illegalLocalVolOverwrite = -Null<Real>());

Real illegalLocalVolOverwrite = -Null<Real>(),
CashDividendModel cashDividendModel = Spot);

FdBlackScholesVanillaEngine(
const boost::shared_ptr<GeneralizedBlackScholesProcess>&,
const boost::shared_ptr<FdmQuantoHelper>& quantoHelper,
Size tGrid = 100,
Size xGrid = 100,
Size dampingSteps = 0,
Size tGrid = 100, Size xGrid = 100, Size dampingSteps = 0,
const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Douglas(),
bool localVol = false,
Real illegalLocalVolOverwrite = -Null<Real>());
Real illegalLocalVolOverwrite = -Null<Real>(),
CashDividendModel cashDividendModel = Spot);

#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") make;
%extend {
static boost::shared_ptr<FdBlackScholesVanillaEngine> make(
const boost::shared_ptr<GeneralizedBlackScholesProcess>& process,
const boost::shared_ptr<FdmQuantoHelper>& quantoHelper
= boost::shared_ptr<FdmQuantoHelper>(),
Size tGrid = 100, Size xGrid = 100, Size dampingSteps = 0,
const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Douglas(),
bool localVol = false,
Real illegalLocalVolOverwrite = -Null<Real>(),
CashDividendModel cashDividendModel = Spot) {
return boost::shared_ptr<FdBlackScholesVanillaEngine>(
new FdBlackScholesVanillaEngine(process, quantoHelper, tGrid, xGrid,
dampingSteps, schemeDesc,
localVol, illegalLocalVolOverwrite,
cashDividendModel));
}
}
#endif
};

%shared_ptr(FdBatesVanillaEngine)
Expand Down Expand Up @@ -1173,6 +1226,25 @@ class FdHestonVanillaEngine : public PricingEngine {
const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Hundsdorfer(),
const boost::shared_ptr<LocalVolTermStructure>& leverageFct
= boost::shared_ptr<LocalVolTermStructure>());

#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") make;
%extend {
static boost::shared_ptr<FdHestonVanillaEngine> make(
const boost::shared_ptr<HestonModel>& model,
const boost::shared_ptr<FdmQuantoHelper>& quantoHelper
= boost::shared_ptr<FdmQuantoHelper>(),
Size tGrid = 100, Size xGrid = 100, Size vGrid = 50,
Size dampingSteps = 0,
const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Hundsdorfer(),
const boost::shared_ptr<LocalVolTermStructure>& leverageFct
= boost::shared_ptr<LocalVolTermStructure>()) {
return boost::shared_ptr<FdHestonVanillaEngine>(
new FdHestonVanillaEngine(model, quantoHelper, tGrid, xGrid, vGrid,
dampingSteps, schemeDesc, leverageFct));
}
}
#endif
};


Expand Down
20 changes: 10 additions & 10 deletions Scala/examples/EquityOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,18 @@ object EquityOptions {

// Finite Difference
var timeSteps : Int = 801;
val fdEuropeanNpv =
new VanillaPricingService(payoff, europeanExercise) !!
new FDEuropeanEngine(SimpleFactory.bsProcess(),
timeSteps, timeSteps-1)
val fdBermudanNpv =
val fdEuropeanNpv =
new VanillaPricingService(payoff, europeanExercise) !!
new FdBlackScholesVanillaEngine(SimpleFactory.bsProcess(),
timeSteps, timeSteps-1)
val fdBermudanNpv =
new VanillaPricingService(payoff, bermudanExercise) !!
new FDBermudanEngine(SimpleFactory.bsProcess(),
timeSteps, timeSteps-1)
val fdAmericanNpv =
new FdBlackScholesVanillaEngine(SimpleFactory.bsProcess(),
timeSteps, timeSteps-1)
val fdAmericanNpv =
new VanillaPricingService(payoff, americanExercise) !!
new FDAmericanEngine(SimpleFactory.bsProcess(),
timeSteps, timeSteps-1)
new FdBlackScholesVanillaEngine(SimpleFactory.bsProcess(),
timeSteps, timeSteps-1)

// Binomial method
val jarrowRuddEuropeanNpv =
Expand Down

0 comments on commit 5a249c4

Please sign in to comment.