Dear All,
I am also interested in simple codes for QuantLib (I have just a smattering of C++ and option pricing). If I understand correctly, the C++ code in the email prices plain vanilla European call options. It uses the standard Black and Scholes theory for a dividend-paying stock. No stochastic volatility, flat term structure and so on. I am testing the results against another library (http://finance.bi.no/~bernt/gcc_prog/). I am not totally sure whether the dividends in the example are paid continuosly or not, but if I set the yield to zero, then I am in the case of a non-dividend paying stock. But the output of the code in the email (I simply reset the value of the yield and print out the relevant quantities) is a bit puzzling to me: the option's maturity is 1 the underlying's value is 7 the dividend yield is 0 the risk-free rate is 0.05 the volatility is 0.1 the strike is 8 Black-Scholes value: 0 whereas the other library provides a small value (about 0.08) but definitely non-zero. Am I misunderstanding? Furthermore, in the case of stock which pays dividends continuously, again I get a non-zero price using the mentioned library. Many thanks Lorenzo > Good afternoon, > I just want to price a simple option with quantlib > I know the maturity, the strike, s0, Sigma and r and I want to use Black and > scholes. > It must be very easy to do that with Quantlib but the example > europeanOption.cpp causes a lot of problems to me. > Could someone give me a simple example ?? > Thank you very much > > NB: in EuropeanOption, what means > return std::exp(-r_*maturity_) > *PlainVanillaPayoff(type_, strike_)(s0_*std::exp(x)) > *std::exp(-(x - nuT)*(x -nuT)/(2*sigma_*sigma_*maturity_)) > /std::sqrt(2.0*M_PI*sigma_*sigma_*maturity_); > in the operator(). > Why a PI ? why multiply the payoff with a exp ? > > _________________________________________________________________ > Gilles, > > In case it helps, here is the EuropeanOption.cpp example stripped to > its most basics: > > #include <ql/quantlib.hpp> > #include <iostream> > using namespace QuantLib; > > int main() > { > Option::Type type(Option::Call); > Real underlying = 7.00, strike = 8.00; > Spread dividendYield = 0.05; > Rate riskFreeRate = 0.05; > Volatility volatility = 0.10; > Date todaysDate(15, May, 1998); > Date settlementDate(17, May, 1998), exerciseDate(17, May, 1999); > Settings::instance().evaluationDate() = todaysDate; > DayCounter dayCounter = Actual365Fixed(); > Time maturity = dayCounter.yearFraction(settlementDate,exerciseDate); > > boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exerciseDate)); > Handle<Quote> underlyingH(boost::shared_ptr<Quote>(new > SimpleQuote(underlying))); > > Handle<YieldTermStructure> > flatTermStructure(boost::shared_ptr<YieldTermStructure>( > new FlatForward(settlementDate, riskFreeRate, dayCounter))); > Handle<YieldTermStructure> > flatDividendTS(boost::shared_ptr<YieldTermStructure>( > new FlatForward(settlementDate, dividendYield, dayCounter))); > Handle<BlackVolTermStructure> > flatVolTS(boost::shared_ptr<BlackVolTermStructure>( > new BlackConstantVol(settlementDate, volatility, dayCounter))); > > boost::shared_ptr<StrikedTypePayoff> payoff( > new PlainVanillaPayoff(type, strike)); > > boost::shared_ptr<BlackScholesProcess> stochasticProcess( > new BlackScholesProcess(underlyingH, flatDividendTS, > flatTermStructure, flatVolTS)); > > EuropeanOption option(stochasticProcess, payoff, exercise); > > option.setPricingEngine(boost::shared_ptr<PricingEngine>( > new AnalyticEuropeanEngine())); > > std::cout << "Black-Scholes value: " << option.NPV() << std::endl; > > return 0; > } > > > > Thank you very much > > > > NB: in EuropeanOption, what means > > return std::exp(-r_*maturity_) > > *PlainVanillaPayoff(type_, strike_)(s0_*std::exp(x)) > > *std::exp(-(x - nuT)*(x -nuT)/(2*sigma_*sigma_*maturity_)) > > /std::sqrt(2.0*M_PI*sigma_*sigma_*maturity_); > > in the operator(). > > Why a PI ? why multiply the payoff with a exp ? > > > > > > _______________________________________________ > Quantlib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On 1/24/06, L.Isella <[hidden email]> wrote:
> If I understand correctly, the C++ code in the email prices plain vanilla European call options. > It uses the standard Black and Scholes theory for a dividend-paying stock. > No stochastic volatility, flat term structure and so on. > I am testing the results against another library (http://finance.bi.no/~bernt/gcc_prog/). > I am not totally sure whether the dividends in the example are paid continuosly or not, but if I set the yield to zero, then I am in the case of a non-dividend paying stock. > But the output of the code in the email (I simply reset the value of the yield and print out the relevant quantities) is a bit puzzling to me: > > Black-Scholes value: 0 > > whereas the other library provides a small value (about 0.08) but definitely non-zero. > Am I misunderstanding? No, but you might be doing something wrong. If I compile and run the code in the email after setting the dividendYield variable to 0.0, I get for the option a Black-Scholes price of 0.082. You might want to check your program or post it here to see what's the problem. Later, Luigi |
In reply to this post by L.Isella
On Tue, 2006-01-24 at 15:10 +0100, Luigi Ballabio wrote:
On 1/24/06, L.Isella <[hidden email]> wrote: > > If I understand correctly, the C++ code in the email prices plain vanilla European call options. > > It uses the standard Black and Scholes theory for a dividend-paying stock. > > No stochastic volatility, flat term structure and so on. > > I am testing the results against another library (http://finance.bi.no/~bernt/gcc_prog/). > > I am not totally sure whether the dividends in the example are paid continuosly or not, but if I set the yield to zero, then I am in the case of a non-dividend paying stock. > > But the output of the code in the email (I simply reset the value of the yield and print out the relevant quantities) is a bit puzzling to me: > > > > Black-Scholes value: 0 > > > > whereas the other library provides a small value (about 0.08) but definitely non-zero. > > Am I misunderstanding? > > No, but you might be doing something wrong. If I compile and run the > code in the email after setting the dividendYield variable to 0.0, I > get for the option a Black-Scholes price of 0.082. You might want to > check your program or post it here to see what's the problem. > > Later, > Luigi > The code I am using is the following (taken from one of the previous emails): #include <ql/quantlib.hpp> #include <iostream> using namespace QuantLib; int main() { Option::Type type(Option::Call); Real underlying = 7.00, strike = 8.00; Spread dividendYield = 0.0; //only part of the code I modified Rate riskFreeRate = 0.05; Volatility volatility = 0.10; Date todaysDate(15, May, 1998); Date settlementDate(17, May, 1998), exerciseDate(17, May, 1999); Settings::instance().evaluationDate() = todaysDate; DayCounter dayCounter = Actual365Fixed(); Time maturity = dayCounter.yearFraction(settlementDate,exerciseDate); boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exerciseDate)); Handle<Quote> underlyingH(boost::shared_ptr<Quote>(new SimpleQuote(underlying))); Handle<YieldTermStructure> flatTermStructure(boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, riskFreeRate, dayCounter))); Handle<YieldTermStructure> flatDividendTS(boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, dividendYield, dayCounter))); Handle<BlackVolTermStructure> flatVolTS(boost::shared_ptr<BlackVolTermStructure>( new BlackConstantVol(settlementDate, volatility, dayCounter))); boost::shared_ptr<StrikedTypePayoff> payoff( new PlainVanillaPayoff(type, strike)); boost::shared_ptr<BlackScholesProcess> stochasticProcess( new BlackScholesProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS)); EuropeanOption option(stochasticProcess, payoff, exercise); option.setPricingEngine(boost::shared_ptr<PricingEngine>( new AnalyticEuropeanEngine())); std::cout << "Black-Scholes value: " << option.NPV() << std::endl; return 0; } I then save it in a file (simple-option.cc) and compile & run it: lorenzo@mypc:~/Temp$ g++ -o simple simple-option.cc -lQuantLib lorenzo@mypc:~/Temp$ ./simple Black-Scholes value: 0 However, If I use the same parameters inside the AmericanOption example, then I get the "right" value. It is again something trivial, 100% sure, but I copied the code from the mail! Lorenzo |
On 1/24/06, L.Isella <[hidden email]> wrote:
> The code I am using is the following (taken from one of the previous emails): > > ... > > I then save it in a file (simple-option.cc) and compile & run it: > > lorenzo@mypc:~/Temp$ g++ -o simple simple-option.cc -lQuantLib > lorenzo@mypc:~/Temp$ ./simple > Black-Scholes value: 0 Hmm. Copying the code from your email and performing the same steps gives me: lballabio:~$ ./simple Black-Scholes value: 0.0823425 However, I'm using the current CVS version. What QuantLib version are you using? I'll try to compile it and reproduce the problem, but it will take some time. Later, Luigi |
In reply to this post by L.Isella
Hmm. Copying the code from your email and performing the same steps gives me:
lballabio:~$ ./simple Black-Scholes value: 0.0823425 However, I'm using the current CVS version. What QuantLib version are you using? I'll try to compile it and reproduce the problem, but it will take some time. Later, Luigi Thanks for your efforts. It is weird indeed... I am on Ubuntu Linux and, as I told Dirk, I am using the QuantLib version libquantlib0-dev version 0.3.9-6ubuntu3. Sometimes I have had troubles with other tested libraries for some "details" (e.g. some function/variable whose name is uppercase in the library and called lowercase in the code), but this does not seem the case. However, I would be curious to find out if anyone else on Ubuntu/Debian experiences the same trouble with that code. Cheers Lorenzo |
Lorenzo,
Can you add the following line, near the top of the code, say right before the first "boost::shared_ptr" definition: std::cout << QL_VERSION << std::endl The output should correspond to the same version you mentioned, but it's a simple check to make sure everything is consistent. I am also running quantlib on linux, and have no problems. You could try compiling the library yourself. It's quite straightforward. Fred On Tuesday 24 January 2006 10:46, L.Isella wrote: > Hmm. Copying the code from your email and performing the same steps gives > me: lballabio:~$ ./simple > Black-Scholes value: 0.0823425 > > However, I'm using the current CVS version. What QuantLib version are > you using? I'll try to compile it and reproduce the problem, but it > will take some time. > > Later, > Luigi > > Thanks for your efforts. > It is weird indeed... > I am on Ubuntu Linux and, as I told Dirk, I am using > the QuantLib version > > libquantlib0-dev version 0.3.9-6ubuntu3. > > Sometimes I have had troubles with other tested libraries for some > "details" (e.g. some function/variable whose name is uppercase in the > library and called lowercase in the code), but this does not seem the case. > However, I would be curious to find out if anyone else on Ubuntu/Debian > experiences the same trouble with that code. Cheers > > Lorenzo > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > <a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 > _______________________________________________ > Quantlib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users |
(Ooops, I forget the the semicolon at the end of that line)
Anyway, with version 0.3.11 I also get 0.0823. On Tuesday 24 January 2006 15:18, Fred Nastos wrote: > Lorenzo, > > Can you add the following line, near the top of the code, say right before > the first "boost::shared_ptr" definition: > > std::cout << QL_VERSION << std::endl > > The output should correspond to the same version you mentioned, but it's > a simple check to make sure everything is consistent. > > I am also running quantlib on linux, and have no problems. You > could try compiling the library yourself. It's quite straightforward. > > Fred > > On Tuesday 24 January 2006 10:46, L.Isella wrote: > > Hmm. Copying the code from your email and performing the same steps gives > > me: lballabio:~$ ./simple > > Black-Scholes value: 0.0823425 > > > > However, I'm using the current CVS version. What QuantLib version are > > you using? I'll try to compile it and reproduce the problem, but it > > will take some time. > > > > Later, > > Luigi > > > > Thanks for your efforts. > > It is weird indeed... > > I am on Ubuntu Linux and, as I told Dirk, I am using > > the QuantLib version > > > > libquantlib0-dev version 0.3.9-6ubuntu3. > > > > Sometimes I have had troubles with other tested libraries for some > > "details" (e.g. some function/variable whose name is uppercase in the > > library and called lowercase in the code), but this does not seem the > > case. However, I would be curious to find out if anyone else on > > Ubuntu/Debian experiences the same trouble with that code. Cheers > > > > Lorenzo > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > > files for problems? Stop! Download the new AJAX search engine that > > makes searching your log files as easy as surfing the web. DOWNLOAD > > SPLUNK! > > <a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 > > _______________________________________________ > > Quantlib-users mailing list > > [hidden email] > > https://lists.sourceforge.net/lists/listinfo/quantlib-users > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > Quantlib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users -- _______________________________________________________ Fred Nastos Ph.D. Candidate Department of Physics Tel: 416-978-4364 University of Toronto Fax: 416-978-2537 60 St. George Street Toronto, ON M5S 1A7 Web: www.physics.utoronto.ca/~nastos _______________________________________________________ |
It looks like it is an issue with Ubuntu. or the older QL 0.3.9 library.
I also get Lorenzo's invalid answer of 0 when I use the supplied QL 0.3.9 packages on Ubuntu. Interestingly enough, I do get the correct answer using RQuantLib rather than the little C++ source code: edd@joe:~$ echo 'library(RQuantLib); EuropeanOption("call", 7, 8, 0, 0.05, 1, 0.1)' | R --slave Concise summary of valuation for EuropeanOption value delta gamma vega theta rho 0.08234248 0.21613477 0.41869080 2.05158494 -0.17410929 1.43060089 divRho -1.51294336 This uses the standard Ubuntu packages, rebuilt for the C++ transition: edd@joe:~$ dpkg -l r-base-core libquantlib-0.3.9c2 r-cran-rquantlib Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-==============-==============-============================================ ii libquantlib-0. 0.3.9-6ubuntu3 Quantitative Finance Library -- development ii r-base-core 2.1.1-1 GNU R core of statistical computing language ii r-cran-rquantl 0.1.12-3build1 GNU R package interfacing the QuantLib finan I don't have access to an older Debian system with 0.3.9 to compare; with 0.3.11 the correct answer comes up with the same C++ code posted a few days ago. Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison |
In reply to this post by Fred Nastos
It is something in the date calcs that must have gotten fixed since 0.3.9.
If we forward the dates from 1998/1999 to 2006/2007, it all works: edd@joe:~$ grep 200 euopt.cpp Date todaysDate(15, May, 2006); Date settlementDate(17, May, 2006), exerciseDate(17, May, 2007); edd@joe:~$ g++ -o euopt euopt.cpp -lQuantLib edd@joe:~$ ./euopt Black-Scholes value: 0.0823425 even on the Ubuntu system with the older 0.3.9 library. Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison |
In reply to this post by Dirk Eddelbuettel
I am checking the Excel AddIns and have a few questions: a. When settlementdate is bigger than valuateDate, DF numbers are undefined. b. Can we set different valuatedate and settlementdate for each instrument for the curve c. what is use of the cell G3 in swap convention section? d. what is trigger used for? Thanks. -Jim
Yahoo! Mail Use Photomail to share photos without annoying attachments. |
One more: the BPS in the SimpleSwap has numbers of over 8,000,000 which seems too big. what is the definition for it? zheng wang <[hidden email]> wrote:
Do you Yahoo!? With a free 1 GB, there's more in store with Yahoo! Mail. |
In reply to this post by zheng wang-4
Hi Jim
> a. When settlementdate is bigger than valuateDate, DF numbers are > undefined. Yes if all you do is increment the settlement date it breaks the curve, you need to make the corresponding changes to the fixing days and the dates in the curve. > b. Can we set different valuatedate and settlementdate for each instrument > for the curve No. The evaluation date is contained the Settings object, in the default QuantLib build there is one global instance of Settings. QuantLib supports the concept of a session, allowing multiple instances of the Settings object, but this is not implemented in the current release of QuantLibAddin (0.3.11). Please see the links below for prior discussion on this subject. http://sourceforge.net/mailarchive/forum.php?thread_id=8151830&forum_id=4299 http://sourceforge.net/mailarchive/forum.php?thread_id=7875915&forum_id=4299 http://sourceforge.net/mailarchive/forum.php?thread_id=7144644&forum_id=4299 The upcoming QuantLibAddin 0.3.12 release implements a session as a workbook allowing all objects requiring a given instance of the evaluation date to be grouped in a single workbook. But this wouldn't really let you use a different evaluation date for each instrument in the curve. > c. what is use of the cell G3 in swap convention section? #/fixing days for the swap rate helpers. > d. what is trigger used for? To force a dependency which isn't known to Excel's calculation tree. For example qlSetQuote and qlGetDf both operate on the same underlying object but Excel has no way to know that so the trigger forces qlGetDf to be recalculated if qlSetQuote changes. Regards, Eric |
In reply to this post by zheng wang-4
On 1/25/06, zheng wang <[hidden email]> wrote:
> One more: the BPS in the SimpleSwap has numbers of over 8,000,000 > which seems too big. what is the definition for it? It is the variation of the NPV of a leg when the paid rate changes of a basis point. Whether it's too big or not depends on the notional of the swap. What parameters were you using? Luigi |
On 2/2/06, zheng wang <[hidden email]> wrote:
> Luigi Ballabio <[hidden email]> wrote: > On 1/25/06, zheng wang wrote: > > One more: the BPS in the SimpleSwap has numbers of over 8,000,000 > > which seems too big. what is the definition for it? > > It is the variation of the NPV of a leg when the paid rate changes of > a basis point. Whether it's too big or not depends on the notional of > the swap. What parameters were you using? > > The sample excel YC_SwapDemo.xls, which has notional of 1,000,000 > but the BPS is 8 times bigger. Hmm. It doesn't look right. Then again, I'm not familiar with the Excel add-in. Eric, can you step in? Thanks, Luigi |
Free forum by Nabble | Edit this page |