def get_exogenous(self): if "exogenous" not in self.data: return {} exo = self.data['exogenous'] calibration = self.get_calibration() from dolo.compiler.language import eval_data exogenous = eval_data(exo, calibration) from ruamel.yaml.comments import CommentedMap, CommentedSeq from dolo.numeric.processes import ProductProcess, Process if isinstance(exogenous, Process): # old style return exogenous elif isinstance(exo, list): # old style (2) return ProductProcess(*exogenous) else: # new style syms = self.symbols['exogenous'] # first we check that shocks are defined in the right order ssyms = [] for k in exo.keys(): vars = [v.strip() for v in k.split(',')] ssyms.append(vars) ssyms = tuple(sum(ssyms, [])) if tuple(syms) != ssyms: from dolo.compiler.language import ModelError lc = exo.lc raise ModelError( f"{lc.line}:{lc.col}: 'exogenous' section. Shocks specification must match declaration order. Found {ssyms}. Expected{tuple(syms)}" ) return ProductProcess(*exogenous.values())
def inject_process(process, exogenous, to=None, options={}): if isinstance(process, np.ndarray) and isinstance(exogenous, ProductProcess): q0 = process assert process.ndim == 1 if to is None: if isinstance(exogenous.processes[1], IIDProcess): to = "iid" else: to = "mc" exg = ProductProcess(ConstantProcess(μ=q0), *exogenous.processes[1:]) else: raise Exception("Not implemented.") dp = exg.discretize(to=to, options=options) return dp