hledger-lib-1.19.1: A reusable library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Data.Valuation

Description

Convert amounts to some related value in various ways. This involves looking up historical market prices (exchange rates) between commodities.

Synopsis

- data ValuationType
  - = AtCost (Maybe CommoditySymbol)
  - | AtThen (Maybe CommoditySymbol)
  - | AtEnd (Maybe CommoditySymbol)
  - | AtNow (Maybe CommoditySymbol)
  - | AtDate Day (Maybe CommoditySymbol)
  - | AtDefault (Maybe CommoditySymbol)
- type PriceOracle = (Day, CommoditySymbol, Maybe CommoditySymbol) -> Maybe (CommoditySymbol, Quantity)
- journalPriceOracle :: Bool -> Journal -> PriceOracle
- unsupportedValueThenError :: String
- mixedAmountApplyValuation :: PriceOracle -> Map CommoditySymbol AmountStyle -> Day -> Maybe Day -> Day -> Bool -> ValuationType -> MixedAmount -> MixedAmount
- mixedAmountValueAtDate :: PriceOracle -> Map CommoditySymbol AmountStyle -> Maybe CommoditySymbol -> Day -> MixedAmount -> MixedAmount
- marketPriceReverse :: MarketPrice -> MarketPrice
- priceDirectiveToMarketPrice :: PriceDirective -> MarketPrice
- tests_Valuation :: TestTree

# Documentation

data ValuationType Source #

What kind of value conversion should be done on amounts ? CLI: --value=cost|then|end|now|DATE[,COMM]

Constructors

AtCost (Maybe CommoditySymbol) | convert to cost commodity using transaction prices, then optionally to given commodity using market prices at posting date
AtThen (Maybe CommoditySymbol) | convert to default or given valuation commodity, using market prices at each posting's date
AtEnd (Maybe CommoditySymbol) | convert to default or given valuation commodity, using market prices at period end(s)
AtNow (Maybe CommoditySymbol) | convert to default or given valuation commodity, using current market prices
AtDate Day (Maybe CommoditySymbol) | convert to default or given valuation commodity, using market prices on some date
AtDefault (Maybe CommoditySymbol) | works like AtNow in single period reports, like AtEnd in multiperiod reports

#### Instances

Instances details

Eq ValuationType Source # |
Instance details Defined in Hledger.Data.Valuation Methods (==) :: ValuationType -> ValuationType -> Bool Source # (/=) :: ValuationType -> ValuationType -> Bool Source #
Show ValuationType Source # |
Instance details Defined in Hledger.Data.Valuation Methods showsPrec :: Int -> ValuationType -> ShowS Source # show :: ValuationType -> String Source # showList :: [ValuationType] -> ShowS Source #

type PriceOracle = (Day, CommoditySymbol, Maybe CommoditySymbol) -> Maybe (CommoditySymbol, Quantity) Source #

A price oracle is a magic memoising function that efficiently looks up market prices (exchange rates) from one commodity to another (or if unspecified, to a default valuation commodity) on a given date.

journalPriceOracle :: Bool -> Journal -> PriceOracle Source #

Generate a price oracle (memoising price lookup function) from a journal's directive-declared and transaction-inferred market prices. For best performance, generate this only once per journal, reusing it across reports if there are more than one, as compoundBalanceCommand does. The boolean argument is whether to infer market prices from transactions or not.

unsupportedValueThenError :: String Source #

Standard error message for a report not supporting --value=then.

mixedAmountApplyValuation :: PriceOracle -> Map CommoditySymbol AmountStyle -> Day -> Maybe Day -> Day -> Bool -> ValuationType -> MixedAmount -> MixedAmount Source #

Apply a specified valuation to this mixed amount, using the provided price oracle, commodity styles, reference dates, and whether this is for a multiperiod report or not. See amountApplyValuation.

mixedAmountValueAtDate :: PriceOracle -> Map CommoditySymbol AmountStyle -> Maybe CommoditySymbol -> Day -> MixedAmount -> MixedAmount Source #

Find the market value of each component amount in the given commodity, or its default valuation commodity, at the given valuation date, using the given market price oracle. When market prices available on that date are not sufficient to calculate the value, amounts are left unchanged.

marketPriceReverse :: MarketPrice -> MarketPrice Source #

priceDirectiveToMarketPrice :: PriceDirective -> MarketPrice Source #

tests_Valuation :: TestTree Source #