-- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./QuantLib/Index/Commodity.chs" #-}
module QuantLib.Index.Commodity
  (
    -- * Types
    CommodityIndex

    -- * Constructors
  , commodityIndex

    -- * Inspectors
  , forwardPrice
  , lastQuoteDate
  , isEmpty
  ) where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp


import QuantLib.Internal
import QuantLib.Internal.Type








{-# LINE 23 "./QuantLib/Index/Commodity.chs" #-}


{-# LINE 24 "./QuantLib/Index/Commodity.chs" #-}


{-# LINE 25 "./QuantLib/Index/Commodity.chs" #-}


{-# LINE 26 "./QuantLib/Index/Commodity.chs" #-}


{-# LINE 27 "./QuantLib/Index/Commodity.chs" #-}


{-# LINE 28 "./QuantLib/Index/Commodity.chs" #-}


-- |A named commodity index, whose fixings forecast from an optional forward 'CommodityCurve'
-- (or fall back to a stored historical fixing when none is given -- add one via
-- 'QuantLib.Index.addFixing'). Upstream's constructor also takes an
-- @ExchangeContracts@\/nearby-offset pair for rolling onto nearby exchange contracts; this binds
-- only the no-rolling case (a null @exchangeContracts@ and offset 0), the same scope this module's
-- 'QuantLib.TermStructure.Commodity.CommodityCurve' already narrowed 'price' to.
-- Commodity type, currency, unit, lot quantity, and forward curve are not exposed as inspectors
-- because they only echo the constructor arguments.
commodityIndex :: (String) -- ^name
 -> (CommodityType) -> (Currency) -> (UnitOfMeasure) -> (Calendar) -> (Double) -- ^lotQuantity
 -> (Maybe CommodityCurve) -- ^forwardCurve
 -> IO ((CommodityIndex))
commodityIndex :: String
-> CommodityType
-> Currency
-> UnitOfMeasure
-> Calendar
-> Double
-> Maybe CommodityCurve
-> IO CommodityIndex
commodityIndex String
a1 CommodityType
a2 Currency
a3 UnitOfMeasure
a4 Calendar
a5 Double
a6 Maybe CommodityCurve
a7 =
  String -> (CString -> IO CommodityIndex) -> IO CommodityIndex
forall a. String -> (CString -> IO a) -> IO a
C2HSImp.withCString String
a1 ((CString -> IO CommodityIndex) -> IO CommodityIndex)
-> (CString -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (a -> b) -> a -> b
$ \CString
a1' -> 
  CommodityType
-> (Ptr CCommodityType -> IO CommodityIndex) -> IO CommodityIndex
forall b. CommodityType -> (Ptr CCommodityType -> IO b) -> IO b
withCommodityType CommodityType
a2 ((Ptr CCommodityType -> IO CommodityIndex) -> IO CommodityIndex)
-> (Ptr CCommodityType -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (a -> b) -> a -> b
$ \Ptr CCommodityType
a2' -> 
  Currency
-> (Ptr CCurrency -> IO CommodityIndex) -> IO CommodityIndex
forall b. Currency -> (Ptr CCurrency -> IO b) -> IO b
withCurrency Currency
a3 ((Ptr CCurrency -> IO CommodityIndex) -> IO CommodityIndex)
-> (Ptr CCurrency -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (a -> b) -> a -> b
$ \Ptr CCurrency
a3' -> 
  UnitOfMeasure
-> (Ptr CUnitOfMeasure -> IO CommodityIndex) -> IO CommodityIndex
forall b. UnitOfMeasure -> (Ptr CUnitOfMeasure -> IO b) -> IO b
withUnitOfMeasure UnitOfMeasure
a4 ((Ptr CUnitOfMeasure -> IO CommodityIndex) -> IO CommodityIndex)
-> (Ptr CUnitOfMeasure -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (a -> b) -> a -> b
$ \Ptr CUnitOfMeasure
a4' -> 
  Calendar
-> (Ptr CCalendar -> IO CommodityIndex) -> IO CommodityIndex
forall b. Calendar -> (Ptr CCalendar -> IO b) -> IO b
withCalendar Calendar
a5 ((Ptr CCalendar -> IO CommodityIndex) -> IO CommodityIndex)
-> (Ptr CCalendar -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (a -> b) -> a -> b
$ \Ptr CCalendar
a5' -> 
  let {a6' :: CDouble
a6' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a6} in 
  Maybe CommodityCurve
-> (Ptr CCommodityCurve' -> IO CommodityIndex) -> IO CommodityIndex
forall b.
Maybe CommodityCurve -> (Ptr CCommodityCurve' -> IO b) -> IO b
withMaybeCommodityCurve Maybe CommodityCurve
a7 ((Ptr CCommodityCurve' -> IO CommodityIndex) -> IO CommodityIndex)
-> (Ptr CCommodityCurve' -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (a -> b) -> a -> b
$ \Ptr CCommodityCurve'
a7' -> 
  (Ptr CString -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr CString -> IO CommodityIndex) -> IO CommodityIndex)
-> (Ptr CString -> IO CommodityIndex) -> IO CommodityIndex
forall a b. (a -> b) -> a -> b
$ \Ptr CString
a8' -> 
  CString
-> Ptr CCommodityType
-> Ptr CCurrency
-> Ptr CUnitOfMeasure
-> Ptr CCalendar
-> CDouble
-> Ptr CCommodityCurve'
-> Ptr CString
-> IO (Ptr CCommodityIndex')
commodityIndex'_ CString
a1' Ptr CCommodityType
a2' Ptr CCurrency
a3' Ptr CUnitOfMeasure
a4' Ptr CCalendar
a5' CDouble
a6' Ptr CCommodityCurve'
a7' Ptr CString
a8' IO (Ptr CCommodityIndex')
-> (Ptr CCommodityIndex' -> IO CommodityIndex) -> IO CommodityIndex
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CCommodityIndex'
res ->
  Ptr CCommodityIndex' -> IO CommodityIndex
peekCommodityIndex Ptr CCommodityIndex'
res IO CommodityIndex
-> (CommodityIndex -> IO CommodityIndex) -> IO CommodityIndex
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' ->
  errorCheck  a8'>>
  return (res')

{-# LINE 46 "./QuantLib/Index/Commodity.chs" #-}


-- |The forecast forward price for a date, from the forward curve.
forwardPrice :: (CommodityIndex) -> (Day) -> IO ((Double))
forwardPrice a1 a2 =
  withCommodityIndex a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  forwardPrice'_ a1' a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a3'>>
  return (res')

{-# LINE 49 "./QuantLib/Index/Commodity.chs" #-}


-- |The most recent date with a stored historical fixing. Throws if none has been added yet --
-- check 'isEmpty' first if that's a possibility.
lastQuoteDate :: (CommodityIndex) -> IO ((Day))
lastQuoteDate a1 =
  withCommodityIndex a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  lastQuoteDate'_ a1' a2' >>= \res ->
  let {res' = toDay res} in
  errorCheck  a2'>>
  return (res')

{-# LINE 53 "./QuantLib/Index/Commodity.chs" #-}


-- |Whether this index has any stored historical fixings.
isEmpty :: (CommodityIndex) -> (Bool)
isEmpty a1 =
  C2HSImp.unsafePerformIO $
  withCommodityIndex a1 $ \a1' -> 
  isEmpty'_ a1' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  return (res')

{-# LINE 56 "./QuantLib/Index/Commodity.chs" #-}


-- vim: set ff=unix ts=8 sts=2 sw=2 et:

foreign import ccall safe "QuantLib/Index/Commodity.chs.h qlCommodityIndex"
  commodityIndex'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (CCommodityType)) -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CUnitOfMeasure)) -> ((C2HSImp.Ptr (CCalendar)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCommodityCurve')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCommodityIndex')))))))))))

foreign import ccall safe "QuantLib/Index/Commodity.chs.h qlCommodityIndexForwardPrice"
  forwardPrice'_ :: ((C2HSImp.Ptr (CCommodityIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))

foreign import ccall safe "QuantLib/Index/Commodity.chs.h qlCommodityIndexLastQuoteDate"
  lastQuoteDate'_ :: ((C2HSImp.Ptr (CCommodityIndex')) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "QuantLib/Index/Commodity.chs.h qlCommodityIndexEmpty"
  isEmpty'_ :: ((C2HSImp.Ptr (CCommodityIndex')) -> (IO C2HSImp.CInt))