py_wlc.generic package¶
Submodules¶
py_wlc.generic.growth module¶
Generic functionality for modelling growth series.
-
class
py_wlc.generic.growth.
IndexSeries
(base_year, rates, initial_value, year_zero=None)[source]¶ Bases:
object
Growth rates and factors for indexation series.
The
_rates
dictionary is fully-populated at initialisation, but the_values
dictionary is filled lazily - values are only calculated as needed.The class supports a
Mapping
-like interface; factors can be accessed withvalue = growth_rate[year]
orvalue = growth_rate.get(year, default)
.Note
The term ‘relative year’ refers to the year relative to
year_zero
e.g.3
. The term ‘absolute year’ refers to a calendar year, e.g.2013
. Relative years are used internally, absolute years for the external interface.Parameters: - base_year (
int
) – the year in which the value is equal to theinitial_value
- rates (
dict
ofint
:float
) – the growth rates to use, keyed by relative year - initial_value (
float
) – the first value for the output series. - year_zero (
int
, optional) – the zeroth year for accessing growth rates. Defaults tobase_year
.
-
base_year
¶ int
The base year for growth, i.e. the year in which the value is the
initial_value
.
-
year_zero
¶ int
The zeroth year for growth, i.e. the year from which the rates are selected from
_rates
.
-
_rates
¶ dict
ofint
:float
The growth rates, where the key is the relative start year and the value is the rate to apply.
-
_initial_rate
¶ float
The growth rate corresponding to the first year in the
rates
dictionary.
-
_final_rate
¶ float
The growth rate corresponding to the last year in the
rates
dictionary.
-
_values
¶ dict
ofint
:float
The values, keyed by year.
-
get
(year, default=None)[source]¶ Retrieve value or supplied default for given year.
Parameters: - year (int) – The year to retrieve the value for.
- default (float or None, optional) – The value to return if
retrieval fails. Defaults to
None
.
Returns: The retrieved or
default
value.Return type: float or None
- base_year (
Module contents¶
Generic functionality supporting the core modelling.
-
class
py_wlc.generic.
ExtendedDict
[source]¶ Bases:
dict
Dictionary subclass that provides values beyond defined keys.
Provides values outside the predefined range, according to the following rules:
- If the key is larger than the largest key in the dictionary, the value from the largest key is returned.
- If the key is smaller than the smallest key in the dictionary, the value from the smallest key is returned.
- If the key is between the smallest and largest keys in the
dictionary but no value is found, a
KeyError
occurs.
-
copy
()[source]¶ Create a copy of the extended dictionary.
Returns: A new class instance. Return type: ExtendedDict