Posted by
Grant Birchmeier on
Mar 20, 2009; 2:33pm
URL: http://quantlib.414.s1.nabble.com/Greeks-tp7342p7348.html
Sumit,
I was able to figure out the Greeks yesterday, as well as
Black-Scholes options valuations. I've pasted a function below that
will create a EuropeanOption based on some simple parameters. Then
you can call the NPV(), delta(), gamma(), etc methods on the resulting
object.
Some caveats:
(1) this code is C#, using the SWIG-wrapped release, but I think you
can figure out how to redo it in C++
(2) it's using the plain old BlackScholes stochastic process
(3) it's using the SimpleDayCounter, which is for theoretical
computation (see the docs). If you pass in todaysDate=01Jan2009 and
maturityDate=01Jul2009, then the time-to-maturity will be exactly 0.5.
This might not be the best code example, but I'm new to both QuantLib
and this subject area.
-Grant
private EuropeanOption CreateEuropeanOption(
double underlyingPrice,
double strikePrice,
double riskFreeRate,
Date todaysDate,
Date maturityDate,
double volatility,
Option.Type optionType)
{
Date settlementDate = todaysDate;
Settings.instance().setEvaluationDate(todaysDate);
Calendar calendar = new NullCalendar();
DayCounter dayCounter = new SimpleDayCounter();
QuoteHandle underlyingQuoteH = new QuoteHandle(new
SimpleQuote(underlyingPrice));
EuropeanExercise europeanExercise = new
EuropeanExercise(maturityDate);
YieldTermStructureHandle flatRateTSH
= new YieldTermStructureHandle(
new FlatForward(settlementDate, riskFreeRate, dayCounter));
BlackVolTermStructureHandle flatVolTSH
= new BlackVolTermStructureHandle(
new BlackConstantVol(settlementDate, calendar,
volatility, dayCounter));
BlackScholesProcess stochasticProcess = new
BlackScholesProcess(underlyingQuoteH, flatRateTSH, flatVolTSH);
PlainVanillaPayoff payoff = new
PlainVanillaPayoff(optionType, strikePrice);
EuropeanOption europeanOption = new EuropeanOption(payoff,
europeanExercise);
europeanOption.setPricingEngine(new
AnalyticEuropeanEngine(stochasticProcess));
return europeanOption;
}
On Fri, Mar 20, 2009 at 5:00 AM, Luigi Ballabio
<
[hidden email]> wrote:
> On Thu, 2009-03-19 at 13:21 +1100, Sumit Gupta wrote:
>> I am trying to get my hands on Options. I am trying to use the
>> QuantLib C# code for calculating Options (single and multiple) and
>> also to evaluate Greeks and Marginal Values. In the solution I have
>> seen an example of calculating options but the values there is not
>> matching with www.asx.com.au calculator.
>
> Do you have an example of values not matching (and the inputs you used)?
>
> Luigi
>
>
> --
>
> A debugged program is one for which you have not yet found the
> conditions that make it fail.
> -- Jerry Ogdin
>
>
>
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial.
http://p.sf.net/sfu/www-adobe-com> _______________________________________________
> QuantLib-users mailing list
>
[hidden email]
>
https://lists.sourceforge.net/lists/listinfo/quantlib-users>
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial.
http://p.sf.net/sfu/www-adobe-com_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users