corn.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include <iostream>
00004 #include <iomanip>
00005 #include <string>
00006 #include <stdlib.h>
00007 
00008 #include "binomial_greeks_option.h"
00009 #include "NewDateTime.h"
00010 #include "simpleoption.h"
00011 
00012 using namespace std;
00013 
00014 struct cbot_pair {
00015   string strike_price;
00016   string settlement_price;
00017 
00018   mutable double _Price;
00019   mutable double _K;
00020 
00021   /*
00022   cbot_pair( const char *Strike_price, const char * Settlement_price) :
00023     strike_price( Strike_price), 
00024     settlement_price( Settlement_price)
00025   {
00026   }
00027   */
00028 
00029   static double quote2double( const string& quote) {
00030     string handle, frac;
00031     size_t dash = quote.find_first_of( "'");
00032     double retval;
00033 
00034     if (dash == string::npos) {
00035       handle = quote;
00036     } else {
00037       handle = quote.substr( 0, dash);
00038       frac   = quote.substr( dash+1, quote.size()-dash+1);
00039     }
00040 
00041     //cerr << "handle = " << handle << endl;
00042     //cerr << "frac   = " << frac   << endl;
00043 
00044     retval = atof( handle.c_str()) + atof( frac.c_str()) * .125;
00045 
00046     return retval;
00047   }
00048 
00049   double Price() const {
00050     _Price = quote2double( settlement_price);
00051     return _Price;
00052   }
00053 
00054   double K() const {
00055     _K = quote2double( strike_price);
00056     return _K;
00057   }
00058 };
00059 
00060 cbot_pair call_pairs[] = {
00061   /*  { "300'0", "124'0"},
00062       { "310'0", "114'1"},*/
00063 
00064   { "320'0", "104'2"},
00065   { "330'0", "94'7"},
00066   { "340'0", "85'6"},
00067   { "350'0", "76'6"},
00068   { "360'0", "68'6"},
00069   { "370'0", "61'5"},
00070   { "380'0", "54'6"},
00071   { "390'0", "49'0"},
00072   { "400'0", "43'5"},
00073   { "410'0", "39'2"},
00074   { "420'0", "35'4"},
00075   { "430'0", "32'0"},
00076   { "440'0", "29'0"},
00077   { "450'0", "26'2"},
00078   { "460'0", "23'4"},
00079   { "470'0", "21'0"},
00080   { "480'0", "18'4"},
00081   { "490'0", "16'0"},
00082   { "500'0", "14'1"},
00083   { "520'0", "10'6"},
00084   { "540'0", "8'3"},
00085   { "560'0", "6'6"},
00086   { "580'0", "5'6"},
00087   { "600'0", "5'2"}
00088 };
00089 
00090 cbot_pair put_pairs[] = { 
00091   { "300'0", "0'4"},
00092   { "310'0", "0'7"},
00093   { "320'0", "1'2"},
00094   { "330'0", "1'6"},
00095   { "340'0", "2'7"},
00096   { "350'0", "4'0"},
00097   { "360'0", "5'4"},
00098   { "370'0", "8'2"},
00099   { "380'0", "11'3"},
00100   { "390'0", "15'3"},
00101   { "400'0", "20'0"},
00102   { "410'0", "25'5"},
00103   { "420'0", "31'4"},
00104   { "430'0", "37'7"},
00105   { "440'0", "44'6"},
00106   { "450'0", "51'6"}
00107 };
00108 
00109 int main() {
00110   const int number_calls = sizeof( call_pairs) / sizeof(cbot_pair);
00111   const int number_puts =  sizeof( put_pairs) / sizeof(cbot_pair);
00112 
00113   double S = 424, K, Tau, Alpha=0, R=.0534, Sigma=.2, Call_Price, Put_Price,
00114     Implied_sigma;
00115   int NumberIterations = 250, i, Days_Till_Expiration;
00116 
00117   Days_Till_Expiration = day_diff( cbot_ag_option_expiration( 200707), 20070128);
00118   Tau = Days_Till_Expiration / 365.0;
00119 
00120   cout << "Days Till Expiration=" << Days_Till_Expiration << endl;
00121   cout << "Tau = " << Tau << endl;
00122 
00123   cout << setiosflags (ios::showpoint | ios::fixed) << setprecision(4);;
00124 
00125   cout << "Corn Calls" << endl;
00126   for (i=0; i<number_calls; i++) {
00127     K = call_pairs[i].K();
00128     Call_Price = call_pairs[i].Price();
00129 
00130     binomial_greeks_option bgo( S, K, Tau, Alpha, R, Sigma, NumberIterations);
00131 
00132     Implied_sigma = bgo.call_implied_sigma( Call_Price);
00133 
00134     cout << K << " " << Call_Price << " " << Implied_sigma << " " << bgo.get_dC_dS() << endl;
00135   }
00136 
00137   cout << "Corn Puts" << endl;
00138   for (i=0; i<number_puts; i++) {
00139     K = put_pairs[i].K();
00140     Put_Price = put_pairs[i].Price();
00141 
00142     binomial_greeks_option bgo( S, K, Tau, Alpha, R, Sigma, NumberIterations);
00143 
00144     Implied_sigma = bgo.put_implied_sigma( Put_Price);
00145 
00146     cout << K << " " << Put_Price << " " << Implied_sigma << " " << bgo.get_dP_dS() << endl;
00147   }
00148 
00149   return 0;
00150 }
00151 
00156 
00157 

Generated on Fri Jan 7 12:36:18 2011 for public_options by  doxygen 1.5.1