def nomalize_a_model(equations):
    ''' a symbolic normalization is performed if there is a syntaxerror '''

    out = '\n'.join([
        frml if check_syntax_frml(frml) else normalize_a_frml(frml, True)
        for frml in find_frml(equations)
    ])
    return out
def find_hist_model(equations):
    ''' takes a unrolled model and create a model which can be run for historic periode \n
        The model calculates residuals for equations with a <res= > clause and \n
        and the identities are also calculeted'''
    hist = []
    for f in find_frml(equations):
        hist.append(find_res(f))
        a, fr, n, udtryk = split_frml(f.upper())
        if kw_frml_name(n, 'IDENT') or kw_frml_name(n, 'I'):
            # identites are just replicated in order to calculate backdata
            hist.append(f)
    return (' '.join(hist))
def find_res_dynare_new(equations):
    ''' equations to calculat _res formulas
    FRML <> x=a*b+c +x_RES  $ -> FRML <> x_res =x-a*b+c  $
    not finished to speed time up '''
    out = []
    for f in find_frml(equations):
        a, fr, n, udtryk = split_frml(f.upper())
        lhs, rhs = udtryk.split('=', 1)
        lhs = lhs.strip()
        rhs = rhs.strip()[:-1]
        res = lhs + '_RES'
        if res in rhs:
            rep = rhs.replace(res, '').strip()[:-1]
            new = f'frml <> {res} =  {lhs} - ({rep}) $'
            out.append(new)

    return '\n'.join(out)
Esempio n. 4
0
def find_res_dynare(equations):
    ''' equations to calculat _res formulas
    FRML <> x=a*b+c +x_RES  $ -> FRML <> x_res =x-a*b+c  $'''
    from sympy import solve, sympify
    out=[]
    for f in find_frml(equations):
        a, fr, n, udtryk = split_frml(f.upper())
        lhs, rhs = udtryk.split('=', 1)
        res= lhs.strip()+'_RES'
        if res in rhs:
            # we take the the $ out
            kat = sympify('Eq(' + lhs + ',' + rhs[0:-1] + ')')
            res_frml = sympify('res_frml')
            res_frml = solve(kat, res)
            udres = 'FRML ' + 'RES' + ' ' + res + ' = ' + str(res_frml)[1:-1] + ' $'
            out.append(udres)
    return   '\n'.join(out)