Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

mainbinomialtree.cpp

Go to the documentation of this file.
00001 #include "..\PartA\BlackScholes\BlackScholes.h"
00002 #include "../Interface/main.h"
00003 #include "..\PartJ\binomialTree.h"
00004 #include "..\common\utils.h"
00005 using namespace std;
00006 
00007 bool mainbinomialtree(void) {
00008         bool result = true;
00009         const valarray<Real> *stockValues;
00010         
00011         Real So = 50, K = 50, r = 0.05, sigma = .30, T = 1;
00012         Natural n = 10;
00013         binomialTree *bt = new binomialTree(So, r, sigma, T, n);
00014         binomialTree *bt2 = new binomialTree(So, r, sigma, T, n + 1);
00015         bt->runEngineCall(PayOff(K));
00016         bt2->runEngineCall(PayOff(K));
00017 
00018         cout << "bintree: " << bt << endl;
00019         
00020         stockValues = bt->getStockProcess(n);
00021         Real highest = So * exp(n * sigma * sqrt(T/n));
00022         Real lowest = So * exp(-1 * (Real)n * sigma * sqrt(T/n));
00023         if ((stockValues == NULL) || 
00024                 !realsEqual((*stockValues)[0], lowest) || 
00025                 !realsEqual((*stockValues)[n], highest)) {
00026                 cout << "low value: " << (*stockValues)[0]
00027                         << " expecting: " << lowest
00028                         << " high value: " << (*stockValues)[n] 
00029                         << " expecting: " << highest << endl;
00030                 result = false;
00031         }
00032 
00033         BlackScholes *BS = new BlackScholes(So, sigma, true, r, K, T, Call);
00034 
00035         LongNatural nPaths = 100000, nDates = 1;
00036         volsurface* myvol = new volsurface(sigma);
00037         yieldCurve* mycurve = new yieldCurve(r);
00038         Real mcPrice = mainmc(T, K, So, myvol, mycurve, nPaths, nDates, 1);
00039 
00040         cout << "binomial tree price: " << bt->getPrice() << endl;
00041         cout << "avg of " << n << " and " << (n + 1) << " tree prices: " <<
00042                 (.5 * (bt->getPrice() + bt2->getPrice())) << endl;
00043         cout << "black-scholes price: " << BS->getPrice() << endl;
00044         cout << "monte carlo price: " << mcPrice << endl;
00045 
00046         delete BS;
00047         // delete myvol;
00048         // delete mycurve;
00049         delete bt;
00050         return result;
00051 }

Note: Generated nightly - reload for latest version
Generated on Thu Dec 22 23:12:36 2005 for terreneuve by doxygen 1.3.6