| |||||||||||||||||
| |||||||||||||||||
| |||||||||||||||||
| Description | |||||||||||||||||
Tested with: GHC 6.6.1 Finance.Treasury is a module to obtain yield curve data from Department of Treasury website. Error reporting is somewhat of a mixed model in this module. More improvement is desired in future releases. Here is a small complete program illustrating the use of this module: module Main where
import Finance.Treasury
import qualified Data.Map as M
import Data.List (sort)
import Text.Printf
main = do
putStrLn "**************************************"
m <- getYieldCurveThisMonth
putStrLn "*** pretty print 10y rates for all dates"
prettyYieldCurve m (Just "10y")
--
d <- getLatestYieldCurve
putStrLn "*** pretty print the latest daily yield curve"
prettyYieldCurve (M.fromList [d]) Nothing
--
putStrLn "*** show some yield curves of past year"
h <- getYieldCurveHist
prettyYieldCurve (minmax h) (Just "10y")
mapM_ prt yrs
putStrLn "**************************************"
return ()
where minmax h = M.fromList [ M.findMin h, M.findMax h ]
yrs = reverse [ 1992..2007 ]
prt :: Int -> IO ()
prt yr = do putStrLn $ "*** show some yield curves of "++(show yr)
yc <- getYieldCurveYyyy yr
prettyYieldCurve (minmax yc) (Just "10y")
return ()
License info: The license is a simple BSD3-style license. | |||||||||||||||||
| Synopsis | |||||||||||||||||
| |||||||||||||||||
| Yield curve storage | |||||||||||||||||
| type YieldCurveMap = Map Day DailyYieldCurve | |||||||||||||||||
| a Map storing all the daily yield curves | |||||||||||||||||
| type DailyYieldCurve = Map String Float | |||||||||||||||||
| a Map storing the assoc array of maturity to interest rate (in percent) | |||||||||||||||||
| type DailyYieldCurveList = [(String, Float)] | |||||||||||||||||
| a List storing the tuple of maturity and interest rate (in percent) | |||||||||||||||||
| Yield curve maturity | |||||||||||||||||
| yieldCurveHash :: Map String String | |||||||||||||||||
| translates maturity from XML names to abbreviations. E.g. BC_1MONTH becomes 1m. List of all maturities: 1m 3m 6m 1y 2y 3y 5y 7y 10y 20y 30y. However, 30y data may be lacking for some years when the bond was not in circulation. | |||||||||||||||||
| Fetching yield curve data | |||||||||||||||||
| getLatestYieldCurve :: IO (Day, DailyYieldCurve) | |||||||||||||||||
| fetch the latest daily yield curve from the monthly data. | |||||||||||||||||
| getYieldCurveThisMonth :: IO YieldCurveMap | |||||||||||||||||
| fetch the latest monthly data. There is no reason to fail, so it is an error if there is no XML returned | |||||||||||||||||
| getYieldCurveHist :: IO YieldCurveMap | |||||||||||||||||
| fetch the latest yearly data (excluding current month). There is no reason to fail, so it is an error if there is no XML returned | |||||||||||||||||
| getYieldCurveYyyy :: Int -> IO YieldCurveMap | |||||||||||||||||
| fetch the historical yearly data (excluding current year). If YYYY is not in range (since 1992), this call may fail. Otherwise, there is no reason to fail. | |||||||||||||||||
| Printing yield curve data | |||||||||||||||||
| prettyYieldCurve :: YieldCurveMap -> Maybe String -> IO () | |||||||||||||||||
| print yield curve data in a csv format for storage or testing. | |||||||||||||||||
| Produced by Haddock version 0.8 |