Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need a bit of setup. For convenience, and unless you get name clashes, you better import everything:</p> <pre><code>from QuantLib import * </code></pre> <p>then, create the option, which needs an exercise and a payoff:</p> <pre><code>exercise = EuropeanExercise(Date(3,August,2011)) payoff = PlainVanillaPayoff(Option.Call, 100.0) option = EuropeanOption(payoff,exercise) </code></pre> <p>(note that you'll need an exercise date, not a time to maturity.)</p> <p>Now, whether you want to price it or get its implied volatility, you'll have to setup a Black-Scholes process. There's a bit of machinery involved, since you can't just pass a value, say, of the risk-free rate: you'll need a full curve, so you'll create a flat one and wrap it in a handle. Ditto for dividend yield and vol; the underlying value goes in a quote. (I'm not explaining what all the objects are; comment if you need it.)</p> <pre><code>S = QuoteHandle(SimpleQuote(100.0)) r = YieldTermStructureHandle(FlatForward(0, TARGET(), 0.03, Actual360())) q = YieldTermStructureHandle(FlatForward(0, TARGET(), 0.01, Actual360())) sigma = BlackVolTermStructureHandle(BlackConstantVol(0, TARGET(), 0.20, Actual360())) process = BlackScholesMertonProcess(S,q,r,sigma) </code></pre> <p>(the volatility won't actually be used for implied-vol calculation, but you need one anyway.)</p> <p>Now, for implied volatility you'll call:</p> <pre><code>option.impliedVolatility(11.10, process) </code></pre> <p>and for pricing:</p> <pre><code>engine = AnalyticEuropeanEngine(process) option.setPricingEngine(engine) option.NPV() </code></pre> <p>You might use other features (wrap rates in a quote so you can change them later, etc.) but this should get you started.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload