Login  Register

Intraday patch

Posted by Joseph Wang-4 on Dec 22, 2014; 7:47am
URL: http://quantlib.414.s1.nabble.com/Intraday-patch-tp16122.html

I've just pushed up a patch to quantlib that provides basic support
for intraday calculations.  The patch consists of two new classes

timestamp - which is a simple UTC timestamp class.  It is a subclass
of Date, and can be used whereever date is.

continoustime - is a day counter that supports intraday calculations
with timestamp.  ContinousTime allows the user to specify the base
unit, so it is now possible to specify
interest rates and volatility per day, per week, or per month (which
is defined as 30 days) rather than per year.

The only non backward compartible part is the use of "yearFraction" to
specify something other than a fraction of a year.  There is a
function "timeFraction" which calls yearFraction.

Also this counter does not handle leap seconds, but I plan to add that.

I also intentionally left time zones out of these additions since
that's another level of complexity.

I can write some unit tests and I'll add some more comments.  However,
before I do, I'd like some feedback about the general class structure
and to go through a code review.

Below is python code that uses the new interface

def option(strike, vol, t, putcall):
    now = TimeStamp.now()
    Settings.instance().evaluationDate = now
    settlementDate = todaysDate + Period(3, Weeks)
    riskFreeRate = FlatForward(settlementDate, 0.00, ContinuousTime.perDay())

    # option parameters
    exercise = EuropeanExercise(settlementDate)
    payoff = PlainVanillaPayoff(Option.Call, strike)
    x = np.arange(strike*0.8, strike*1.2, 0.01);

    volatility = BlackConstantVol(todaysDate, TARGET(), vol,
ContinuousTime.perDay())
    dividendYield = FlatForward(settlementDate, 0.00, ContinuousTime.perDay())
    underlying = SimpleQuote(0.0)
    process = BlackScholesMertonProcess(QuoteHandle(underlying),
                                    YieldTermStructureHandle(dividendYield),
                                    YieldTermStructureHandle(riskFreeRate),
                                    BlackVolTermStructureHandle(volatility))
    option = VanillaOption(payoff, exercise)
    # method: analytic
    option.setPricingEngine(AnalyticEuropeanEngine(process))
    def myfunc(x):
        underlying .setValue(x)
        return option.NPV()
    def mydelta(x):
        underlying.setValue(x)
        return option.delta()
    def mytheta(x):
        underlying.setValue(x)
        return option.theta()
    plt.figure(1, figsize=(5,8))
    plt.subplot(211)
    y = map(payoff, x)
    plt.plot(x, y)
    plt.plot(x, map(myfunc,x))
    plt.subplot(212)
    plt.plot(x, map(mydelta,x))

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev