packages feed

HQu-0.0.0.0: src/Q/Options/ImpliedVol/SVI.hs

{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Q.Options.ImpliedVol.SVI where
import           Q.Types      (Forward (..), Strike (..), Vol (..),
                               YearFrac (..))
import           Q.Options.ImpliedVol.TimeSlice
import           GHC.Generics (Generic)
import Q.Greeks (Bump, Bumpable(..))

newtype Alpha  = Alpha  Double deriving (Generic, Eq, Show, Ord, Num, Fractional, Floating)
newtype Beta   = Beta   Double deriving (Generic, Eq, Show, Ord, Num, Fractional, Floating)
newtype Rho    = Rho    Double deriving (Generic, Eq, Show, Ord, Num, Fractional, Floating)
newtype M      = M      Double deriving (Generic, Eq, Show, Ord, Num, Fractional, Floating)
newtype Sigma  = Sigma  Double deriving (Generic, Eq, Show, Ord, Num, Fractional, Floating)

-- | Stochastic volatility inspired parameterization of the vol surface.
data SVI = RSVI    -- ^ The original raw SVI representation from Gatheral
           Alpha   -- ^ Corresponds to a vertical translation of the smile.
           Beta    -- ^ Slope of call and put wings.
           Rho     -- ^ A counter clock wise rotation of the smile.
           M       -- ^ translate the smile to the right
           Sigma   -- ^ ATM curviture of the smile.

instance TimeSlice SVI LogRelStrike  where
  totalVar (RSVI (Alpha 𝜢) (Beta 𝜷) (Rho 𝛒) (M 𝐦) (Sigma 𝛔)) (LogRel 𝐀) =
    TotalVar $ 𝜢 + 𝜷 * (𝛒 * (𝐀 - 𝐦) + sqrt ((𝐀 - 𝐦) ** 2 + 𝛔 * 𝛔))


isValidSVI (RSVI (Alpha 𝜢) (Beta 𝜷) (Rho 𝛒) (M 𝐦) (Sigma 𝛔)) =
    𝜷 >= 0
  && abs 𝛒 < 1
  && 𝛔 > 0
  && 𝜢 + 𝜷 * 𝛔 * sqrt (1 -𝛒*𝛒) >= 0