-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53e2535
commit ea4cae1
Showing
2 changed files
with
46 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,16 @@ | ||
#ifndef _LIB_QUANTLIB_H_ | ||
#define _LIB_QUANTLIB_H_ | ||
|
||
#include <iostream> | ||
#include <ql/quantlib.hpp> | ||
|
||
using namespace QuantLib; | ||
|
||
Real | ||
PriceOption(Real underlyingPrice, Real strike, Real riskFreeRate, Volatility) { | ||
// Market data | ||
Real underlyingPrice = 100.0; | ||
Real strike = 100.0; | ||
Rate riskFreeRate = 0.05; | ||
Volatility volatility = 0.20; | ||
Date maturity(20, September, 2024); | ||
|
||
// Option type | ||
Option::Type type(Option::Call); | ||
|
||
// Constructing the European option | ||
EuropeanExercise europeanExercise(maturity); | ||
Handle<Quote> underlyingH(boost::shared_ptr<Quote>(new SimpleQuote(underlyingPrice))); | ||
Handle<YieldTermStructure> flatTermStructure( | ||
boost::shared_ptr<YieldTermStructure>(new FlatForward(0, TARGET(), riskFreeRate, Actual365Fixed()))); | ||
Handle<BlackVolTermStructure> flatVolTS( | ||
boost::shared_ptr<BlackVolTermStructure>(new BlackConstantVol(0, TARGET(), volatility, Actual365Fixed()))); | ||
boost::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(type, strike)); | ||
boost::shared_ptr<BlackScholesMertonProcess> bsmProcess( | ||
new BlackScholesMertonProcess(underlyingH, flatTermStructure, flatTermStructure, flatVolTS)); | ||
|
||
// Create a European option | ||
VanillaOption europeanOption(payoff, europeanExercise); | ||
|
||
// Pricing using Monte Carlo with low number of paths (suboptimal) | ||
Size numPaths = 100; // Very low number of paths | ||
boost::shared_ptr<PricingEngine> mcengine; | ||
mcengine = MakeMCEuropeanEngine<PseudoRandom>(bsmProcess).withSteps(10).withAbsoluteTolerance(0.02).withSeed(42); | ||
|
||
europeanOption.setPricingEngine(mcengine); | ||
Real npv = europeanOption.NPV(); | ||
namespace LibQuantLib { | ||
|
||
std::cout << "European Option NPV (Monte Carlo method): " << npv << std::endl; | ||
Real PriceOption(Real underlyingPrice, Real strike, Real riskFreeRate, Volatility volatility, Date maturity); | ||
Real FixedRateBond(Real faceValue, Real couponRate, Date issueDate, Date maturityDate, Frequency frequency, | ||
DayCounter dayCounter); | ||
} // namespace LibQuantLib | ||
|
||
return 0; | ||
} | ||
#endif // !_LIB_QUANTLIB_H_ |