Saturday, September 29, 2007

Test of my global evolutionary optimization program

It seemed that my program works quite well for
global optimization. It even found some new global
minimization point. If possible, I would like to
improve it further and write a paper on this subject.
(For definition of those functions, see
Some new test functions for global
optimization and performance of
repulsive particle swarm method
Sudhanshu Mishra
North-Eastern Hill University, Shillong (India))

For Hougen function, our program find the solution is about
1 1.72812 0.0868823 0.0566724 0.15568 0.868809 as
the standard deviation is 0.298914. (The best result is
Rosenbrock-Quasi-Newton method:
1 1.253031 1.190943 0.062798 0.040063 0.112453. The sum
of squares of deviations is 0.298900994).


--------------------

The Hansen function
f* = -176.541793 Global Solution=9
1 4.97648 -7.70831 -176.542
2 -7.58989 -7.70831 -176.542
3 -1.30671 -1.42513 -176.542
4 -1.30671 4.85806 -176.542
Total finding is 9
The tube holder function a
x* = -10.8723 Global Solution=2
1 1.5706 5.74051e-009 -10.8723
2 -1.5706 -8.72265e-009 -10.8723
Total finding is 2
The tube holder function b
x* = -10.8723 Global Solution=2
1 1.5706 5.75833e-009 -10.8723
2 -1.5706 9.85915e-010 -10.8723
Total finding is 2
The Holder table function
x* = -26.92 Global Solution=4
1 9.64617 9.64617 -26.9203
2 9.64617 -9.64617 -26.9203
3 -9.64617 -9.64617 -26.9203
4 -9.64617 9.64617 -26.9203
Total finding is 4
The Carrom table function
x* = -24.1568155 Global Solution=4
1 -9.64617 -9.64617 -24.1568
2 -9.64617 9.64617 -24.1568
3 9.64617 9.64617 -24.1568
4 9.64617 -9.64617 -24.1568
Total finding is 4
The Cross in tray function
x* = -2.06261218 Global Solution=4
1 1.34941 -1.34941 -2.06261
2 -1.34941 -1.34941 -2.06261
3 1.34941 1.34941 -2.06261
4 -1.34941 1.34941 -2.06261
Total finding is 4
***The Crowned cross function
x* -> 0.0 Global Solution=1
1 9.99995e-016 3.27808e-018 0.0012431
Total finding is 1
***The cross function
x* -> 0.0 Global Solution=4
1 -1.34941 -1.34941 4.84822e-009
2 1.34941 -1.34941 4.84822e-009
3 1.34941 1.34941 4.84822e-009
4 -1.34941 1.34941 4.84822e-009
Total finding is 4
*****Cross-leg table function:
x* -> -1.0 Global Solution=1
1 -6.74913e-018 9.99978e-016 -7.48396e-006
Total finding is 1
Pen holder function:
x* -> -0.96354 Global Solution=1
1 9.64617 9.64617 -0.963535
2 9.64617 -9.64617 -0.963535
3 -9.64617 9.64617 -0.963535
4 -9.64617 -9.64617 -0.963535
Total finding is 4
Bird function:
x* -> -106.764537 Global Solution=1
1 -1.58214 -3.13025 -106.765
2 4.70104 3.15294 -106.765
Total finding is 2
Modified Schaffer function #1:
x* = 0 Global Solution=1
1 3.24218e-007 -3.02404e-007 0
Total finding is 1
Modified Schaffer function #2:
x* = 0 Global Solution=1
1 -3.42333e-007 2.56129e-007 0
2 0.00139488 -0.00139456 0
3 0.00211379 -0.00211354 0
4 0.0024989 -0.00249896 0
Total finding is 133
Modified Schaffer function #3:
x* = 0.00156685(0,1.253115) Global Solution=1
1 41.0424 -41.0615 3.66026e-007
Total finding is 1
Modified Schaffer function #4:
x* = f (0, 1.253132) = 0.292579 Global Solution=1
1 -41.7439 41.7251 0.291927
Total finding is 1
Styblinski-Tang function
x* =f (-2.903534, -2.903534)=-78.332 Global Solution=1
1 -2.90353 -2.90353 -78.3323
Total finding is 1
Bukin function f6
x* =f (-10, 1)=0 Global Solution=1
1 -10.0009 1.00018 1.13323e-005
Total finding is 1
Giunta function:
x* =f (0.45834282, 0.45834282) =0.0602472184 Global Solution=1
(Wrong! f (0.45834282, 0.45834282) =0.0646388)
1 0.46732 0.46732 0.0644704
Total finding is 1
Schaffer function
x* =f (0, 0) =0 Global Solution=1
1 -2.06858e-010 -1.61139e-009 0
Total finding is 1
Press any key to continue

Friday, September 28, 2007

Note 08: An study on an example of QuantLib: EquityOption

1)Notice this example does not contain calibration procedure.
2) Result from executive file after compiling:

Option type = Put
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
MC (Sobol) 3.844613 N/A N/A
MC (Longstaff Schwartz) N/A N/A 4.481675

Run completed in 5 s

3) With the above result, let us begin to analyze how this program works step by step:

Step 1: Include the QuantLib header and Boost timer
#define BOOST_LIB_DIAGNOSTIC # include #undef BOOST_LIB_DIAGNOSTIC
#include

Step 2: Define option parameters: The important thing here
is that we need to the time as Date class. And also We need
to determine the date counter type(DayCounter class).
Option::Type type(Option::Put);

Date todaysDate(15, May, 1998);
Date settlementDate(17, May, 1998);
Settings::instance().evaluationDate() = todaysDate;
Date maturity(17, May, 1999);
DayCounter dayCounter = Actual365Fixed();

Step 3: Determine the exercise Dates for different type of options/
And also we need to set the parameters to the engine of the Quantlib.
The trick here is to use the Handle class to make the observable being shared.

template
class QuantLib::Handle<> And is inherited from observable.

So the definition for dividend is like:
        Handle flatDividendTS(
boost::shared_ptr(
new FlatForward(settlementDate, dividendYield, dayCounter)));
Step 4: define option type , eg:
VanillaOption americanOption(stochasticProcess, payoff,
americanExercise);
Step 5: Use different method to calculate the option. The only trick here is to
use the setPricingEngine to do this job with the selected. eg:

americanOption.setPricingEngine(boost::shared_ptr(
new BaroneAdesiWhaleyApproximationEngine));







Sunday, September 23, 2007

how can we output the SAS estimated parameters?

1)
For each SAS procedure, SAS produces a group of ODS output objects. In order to know what objects are associated with a particular proc, we use ods trace on statement right before the proc and turn the trace off right after it.

ods trace on /listing;
proc reg data=****;
model *****;
run;
quit;
ods trace off;
2) After knowing the label of object, we can

use the label to create a data set just as using
the name. Eg, one label of the Reg Output is
"Parameter Estimates", now we can try:
ods output "Parameter Estimates"=parest;
proc reg data=***;
model ****;
run;
quit;
ods output close;


Trick:

A)
We can NOT use noprint option since ODS requires an output object.but the statement
ods listing close;
eliminates the output to appear in the output window. After the proc reg, we turn
back the listing output back so output will appear in the output window again.

ods listing close;
ods output "Parameter Estimates"=****;
proc reg data=****;
model ****;
run;
quit;
ods output close;
ods listing;

B)Output to an HTML file

Let's say that we want to write the output of our proc reg to an HTML file. This can be done very easily using ODS. First we specify the file name we are going to use. Then we point the ods html output to it. At the end we close the ods html output to finish writing to the HTML file. You can view procreg.html created by the following code.

filename myhtml "c:\examples\procreg.html";
ods html body=myhtml;
proc reg data=hsb25;
model write= female math;
run; quit;
ods html close;