
 Brazilian Finance Codes : 

     *  
    
      
  


  


Brazilian Finance Codes:

    * 
    




/





-}


import Data.Time
import Data.Time.Clock.POSIX


(|>) x f = f x
(|>>) x f = map f x

pow x y = exp(y * log x)
geomean lst = pow (product lst) $ 1/(fromIntegral (length lst))
mean lst = sum lst / fromIntegral (length lst)
{- Standard Deviation-}
stdev values =  values   |>> (\x -> x -  mean values ) |>> (^2) |> mean |> sqrt
{- Standard Variance -}
stvar values = stdev values |> (^2)


date y m d = 
    UTCTime (fromGregorian y m d) (timeOfDayToTime $ TimeOfDay 0 0 0)

data Period =   Year
            |   Year360
            |   Year252
            |   Month
            |   Each3Months
            |   Each4Months
            |   Semester            
            |   Day252
            |   Day365
            |   Day360
            deriving (Eq, Show)

aa = Year
am = Month
as = Semester
at = Each3Months
aq = Each4Months
ad252 = Day252
ad365 = Day365
ad360 = Day360
du360 = Year360
du252 = Year252

period Year         = 1.0    -- Year
period Month        = 12.0   -- Month
period Semester     = 2.0    -- Semester
  Year 252
period Day360       = 360.0  -- 360 days years convention
  365 adys years convention
  Each Year has 4 periods of 3 months




-- Write a nunmber a percent
pct x = x/100.0
-- Write a percent list
pctxs = map pct 

-- 
lagdiff lst = zipWith (-) (tail lst) lst
growth lst = zipWith (/) (lagdiff lst) lst

growth_p lst = map to_pct (growth lst)

-- Convert decimal to percent
to_pct x = 100.0*x
to_pctxs = map to_pct

  Convert a percent number to decimal
from_pct x =  x / 100.0


--- Compound Future Value and Present Value
-- Future Value
fv i n pv = pv * pow (1+i) n
-- Present Value
pv i n fv = fv / pow (1 + i ) n

interest fv pv = fv - pv

  Future Value Interest
ifv i n pv = (fv i n pv) - pv
-- Present Value Interest
ipv i n fv = fv - (pv i n fv)



  Annual equivalent rate
anrate rate cap =  ( pow (1+ rate) ( period cap) ) -1
anrate_p rate cap = to_pct $ anrate (pct rate) cap

-- Equivalent Interest rate
eqvrate rate1 cap1 cap2 =
    (pow (1+rate1) (period cap1 / period cap2)) - 1

eqvrate_p rate1 cap1 cap2 =
    to_pct $ eqvrate (pct rate1) cap1 cap2

efrate rate cap  =
    (pow (1 + rate / (period cap)) (period cap) ) -  1

--     
efrate_pct rate cap = to_pct $ efrate (pct rate) cap


-- Equivalent Interest raate
totalrate rates = (foldr (*) 1 $ map (1.0+) rates) - 1

totalrate_p rates = to_pct $ totalrate (map pct rates)

-- 
--
--
-- -que-significa-taxa-over-definicao-e-caracteristicas/
-- 
-- 
rate1bu rate = (pow (1 + rate) (1.0/252.0)) - 1
rate1bu_p rate = to_pct $ rate1bu (pct rate)

buTd360 rate = 
    pow ( 1 + rate) (360.0/252.0) -1

d360Tbu rate = 
    pow ( 1 + rate) (252.0/360.0) -1

 Standard Deviation
 Standard Variance 
 Year
 Month
 Semester
 360 days years convention
 Write a nunmber a percent
 Write a percent list
 
 Convert decimal to percent
- Compound Future Value and Present Value
 Future Value
 Present Value
 Present Value Interest
 Equivalent Interest rate
     
 Equivalent Interest raate
 


 -que-significa-taxa-over-definicao-e-caracteristicas/
 
 

 Brazilian Finance Codes : 

     *  
    
      
  


  


Brazilian Finance Codes:

    * 
    




/





-}


import Data.Time
import Data.Time.Clock.POSIX


(|>) x f = f x
(|>>) x f = map f x

pow x y = exp(y * log x)
geomean lst = pow (product lst) $ 1/(fromIntegral (length lst))
mean lst = sum lst / fromIntegral (length lst)
stdev values =  values   |>> (\x -> x -  mean values ) |>> (^2) |> mean |> sqrt
stvar values = stdev values |> (^2)


date y m d = 
    UTCTime (fromGregorian y m d) (timeOfDayToTime $ TimeOfDay 0 0 0)

data Period =   Year
            |   Year360
            |   Year252
            |   Month
            |   Each3Months
            |   Each4Months
            |   Semester            
            |   Day252
            |   Day365
            |   Day360
            deriving (Eq, Show)

aa = Year
am = Month
as = Semester
at = Each3Months
aq = Each4Months
ad252 = Day252
ad365 = Day365
ad360 = Day360
du360 = Year360
du252 = Year252

  Year 252
  365 adys years convention
  Each Year has 4 periods of 3 months




pct x = x/100.0
pctxs = map pct 

lagdiff lst = zipWith (-) (tail lst) lst
growth lst = zipWith (/) (lagdiff lst) lst

growth_p lst = map to_pct (growth lst)

to_pct x = 100.0*x
to_pctxs = map to_pct

  Convert a percent number to decimal
from_pct x =  x / 100.0


fv i n pv = pv * pow (1+i) n
pv i n fv = fv / pow (1 + i ) n

interest fv pv = fv - pv

  Future Value Interest
ifv i n pv = (fv i n pv) - pv
ipv i n fv = fv - (pv i n fv)



  Annual equivalent rate
anrate rate cap =  ( pow (1+ rate) ( period cap) ) -1
anrate_p rate cap = to_pct $ anrate (pct rate) cap

eqvrate rate1 cap1 cap2 =
    (pow (1+rate1) (period cap1 / period cap2)) - 1

eqvrate_p rate1 cap1 cap2 =
    to_pct $ eqvrate (pct rate1) cap1 cap2

efrate rate cap  =
    (pow (1 + rate / (period cap)) (period cap) ) -  1

efrate_pct rate cap = to_pct $ efrate (pct rate) cap


totalrate rates = (foldr (*) 1 $ map (1.0+) rates) - 1

totalrate_p rates = to_pct $ totalrate (map pct rates)

rate1bu rate = (pow (1 + rate) (1.0/252.0)) - 1
rate1bu_p rate = to_pct $ rate1bu (pct rate)

buTd360 rate = 
    pow ( 1 + rate) (360.0/252.0) -1

d360Tbu rate = 
    pow ( 1 + rate) (252.0/360.0) -1
