Thursday, July 2, 2015
Monte-Carlo Option Pricing Via Encapsulation
In the spirit of Object Orientated Programming, we revisit our previous post using 'C++ Design Patterns and Derivative Pricing' by M Joshi to extend vanilla options pricing to not only calls but puts as well. We wish to encapsulate the code using seperate compilation and header files. This will allow the code to be used in such a way that the programmers need not know whats going behind the scenes of the class but is still able to use it.
we begin by defining a class PayOff in the header PayOff1.h that has an enumeration declaration for the option types: call or put as well as the constructor for the Payoff which takes in the strike of the option and the type of the option pay-off.
Lastly in the public section we have the main method for this class 'double PayOff::operator()(double spot) const' which is given a value of spot and returns the value of the pay-off. The operator() has been overloaded which is used as a 'functor'. We store the variables 'strike' and 'TheOptionsType' in the private section.
We then define the implementation file 'PayOff1.cpp' which includes the above header file to initialize the constructor as well as the method operator(). By seperating the definitions and implementations for the private data we increase the privacy of the code. PayOff1.cpp can be found below: . Simply, the 'PayOff::operator ()(double spot) const' looks at the option type - call or put - and defines the payoff accordingly. Since puts are bets on prices falling, the amount paid would assume that Strike price > Spot price or else the payoff would be 0.
We then define a header file called 'SimpleMC.h' storing the function declaration for our simulation calculator whose implementation is stored in 'SimpleMC.cpp'. This function is exactly the same as the function in the "call1" function from the previous post http://youth-economics.blogspot.com/2015/06/monte-carlo-methods-for-valuing-call.html except now we have a PayOff memory address to store thePayOff in the function declaration, also since we are now calculating calls and puts, the lines 22 and 23 of the previous calculator are replaced with The main programme is also the same as the previous post except when calling the final price of the put or call. The implementation can be found below.
Here we use the method operator() to calculate the the payoff for a call and put and these values are then plugged into the monte-carlo engine to calculate call and put prices. Calculating option prices with a Spot = 80, Strike = 100, time = 1 year, volatility = 50% and the risk free rate of 4%, we use 100 000 paths to calcuate
Call: 10.3117
Put: 26.6019
which are very close to the theoretical prices given by http://www.option-price.com/index.php
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment