When I slightly modify the example EquityOptions.cpp
as shown below, so that it calculates for Put and then Call, then the results of the second (ie. Call) are incorrect/buggy (see attached results). What is causing this unexpected behaviour? QuantLib/Examples/EquityOption/EquityOption.cpp : ... int main(int, char* []) { for (int iType = 0; iType < 2; ++iType) // added { // added try { ... // our options Option::Type type(iType == 0 ? Option::Put : Option::Call); // modified ... std::cout << "StartDate = " << todaysDate << std::endl; // added ... // return 0; // disabled } // added return 0; // added } // Output: Option type = Put StartDate = May 15th, 1998 Maturity = May 17th, 1999 Underlying price = 36 Strike = 40 Risk-free interest rate = 6.000000 % Dividend yield = 0.000000 % Volatility = 20.000000 % Method European Bermudan American Black-Scholes 3.844308 N/A N/A Barone-Adesi/Whaley N/A N/A 4.459628 Bjerksund/Stensland N/A N/A 4.453064 Integral 3.844309 N/A N/A Finite differences 3.844342 4.360807 4.486118 Binomial Jarrow-Rudd 3.844132 4.361174 4.486552 Binomial Cox-Ross-Rubinstein 3.843504 4.360861 4.486415 Additive equiprobabilities 3.836911 4.354455 4.480097 Binomial Trigeorgis 3.843557 4.360909 4.486461 Binomial Tian 3.844171 4.361176 4.486413 Binomial Leisen-Reimer 3.844308 4.360713 4.486076 Binomial Joshi 3.844308 4.360713 4.486076 MC (crude) 3.834522 N/A N/A QMC (Sobol) 3.844613 N/A N/A MC (Longstaff Schwartz) N/A N/A 4.481675 Run completed in 7 s Option type = Call StartDate = May 15th, 1998 Maturity = May 17th, 1999 Underlying price = 36 Strike = 40 Risk-free interest rate = 6 % Dividend yield = 0 % Volatility = 20 % Method European Bermudan American Black-Scholes 2 N/A N/A Barone-Adesi/Whaley N/A N/A 2 Bjerksund/Stensland N/A N/A 2 Integral 2 N/A N/A Finite differences 2 2 2 Binomial Jarrow-Rudd 2 2 2 Binomial Cox-Ross-Rubinstein 2 2 2 Additive equiprobabilities 2 2 2 Binomial Trigeorgis 2 2 2 Binomial Tian 2 2 2 Binomial Leisen-Reimer 2 2 2 Binomial Joshi 2 2 2 MC (crude) 2 N/A N/A QMC (Sobol) 2 N/A N/A MC (Longstaff Schwartz) N/A N/A 2 Run completed in 10 s ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
I can reproduce your results, however I set a break point at Real Instrument::NPV (instrument.hpp) and found the call value is computed around 2.1737 (looks correct). So it's a problem of 'cout', I can's see any wrong usages of 'cout' in the code, but I am no expert on the 'cout' Maybe it's a bug in VS? I use VS Team System 2008. Do you use VS?
When I slightly modify the example EquityOptions.cpp as shown below, so that it calculates for Put and then Call, then the results of the second (ie. Call) are incorrect/buggy (see attached results). What is causing this unexpected behaviour? QuantLib/Examples/EquityOption/EquityOption.cpp : ... int main(int, char* []) { for (int iType = 0; iType < 2; ++iType) // added { // added try { ... // our options Option::Type type(iType == 0 ? Option::Put : Option::Call); // modified ... std::cout << "StartDate = " << todaysDate << std::endl; // added ... // return 0; // disabled } // added return 0; // added } // Output: Option type = Put StartDate = May 15th, 1998 Maturity = May 17th, 1999 Underlying price = 36 Strike = 40 Risk-free interest rate = 6.000000 % Dividend yield = 0.000000 % Volatility = 20.000000 % Method European Bermudan American Black-Scholes 3.844308 N/A N/A Barone-Adesi/Whaley N/A N/A 4.459628 Bjerksund/Stensland N/A N/A 4.453064 Integral 3.844309 N/A N/A Finite differences 3.844342 4.360807 4.486118 Binomial Jarrow-Rudd 3.844132 4.361174 4.486552 Binomial Cox-Ross-Rubinstein 3.843504 4.360861 4.486415 Additive equiprobabilities 3.836911 4.354455 4.480097 Binomial Trigeorgis 3.843557 4.360909 4.486461 Binomial Tian 3.844171 4.361176 4.486413 Binomial Leisen-Reimer 3.844308 4.360713 4.486076 Binomial Joshi 3.844308 4.360713 4.486076 MC (crude) 3.834522 N/A N/A QMC (Sobol) 3.844613 N/A N/A MC (Longstaff Schwartz) N/A N/A 4.481675 Run completed in 7 s Option type = Call StartDate = May 15th, 1998 Maturity = May 17th, 1999 Underlying price = 36 Strike = 40 Risk-free interest rate = 6 % Dividend yield = 0 % Volatility = 20 % Method European Bermudan American Black-Scholes 2 N/A N/A Barone-Adesi/Whaley N/A N/A 2 Bjerksund/Stensland N/A N/A 2 Integral 2 N/A N/A Finite differences 2 2 2 Binomial Jarrow-Rudd 2 2 2 Binomial Cox-Ross-Rubinstein 2 2 2 Additive equiprobabilities 2 2 2 Binomial Trigeorgis 2 2 2 Binomial Tian 2 2 2 Binomial Leisen-Reimer 2 2 2 Binomial Joshi 2 2 2 MC (crude) 2 N/A N/A QMC (Sobol) 2 N/A N/A MC (Longstaff Schwartz) N/A N/A 2 Run completed in 10 s ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Yan Kuang <[hidden email]> writes: > So it's a problem of 'cout', I can's see any wrong usages of 'cout' in the > code, but I am no expert on the 'cout' The problem is in the std::cout << std::fixed << std::setprecision(0) line which sets the precision of printed numbers to zero. You need a corresponding line at the top like std::cout << std::fixed << std::setprecision(7) to set the cout system to print some decimal digits. Best, Bojan -- Bojan Nikolic || http://www.bnikolic.co.uk ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Oh, I can see the line now when write seconds: std::cout << std::fixed << std::setprecision(0) << seconds << " s\n" << std::endl; Thanks!
Yan Kuang <[hidden email]> writes: > So it's a problem of 'cout', I can's see any wrong usages of 'cout' in the > code, but I am no expert on the 'cout' The problem is in the std::cout << std::fixed << std::setprecision(0) line which sets the precision of printed numbers to zero. You need a corresponding line at the top like std::cout << std::fixed << std::setprecision(7) to set the cout system to print some decimal digits. Best, Bojan -- Bojan Nikolic || http://www.bnikolic.co.uk Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Yan Kuang wrote:
> Oh, I can see the line now when write seconds: > > std::cout << std::fixed << std::setprecision(0) > << seconds << " s\n" << std::endl; > > Thanks! Yes, problem solved, thanks also from me to Bojan. Yan, FYI: I'm using Linux and g++, using no graphical IDE yet for QuantLib projects, although have Eclipse installed. > Bojan Nikolic <[hidden email]> > 04/09/2009 05:33 PM > > To > Yan Kuang <[hidden email]> > cc > "Ralf M." <[hidden email]>, [hidden email] > Subject > Re: [Quantlib-users] Possible bug in > Examples/EquityOption/EquityOption.cpp > > > > Yan Kuang <[hidden email]> writes: > >> So it's a problem of 'cout', I can's see any wrong usages of 'cout' in > the >> code, but I am no expert on the 'cout' > > The problem is in the > > std::cout << std::fixed << std::setprecision(0) > > line which sets the precision of printed numbers to zero. You need a > corresponding line at the top like > > std::cout << std::fixed << std::setprecision(7) > > to set the cout system to print some decimal digits. > > Best, > Bojan ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |