modelgrabwf2 module
Created on Wed Mar 30 10:06:26 2022
@author: ibhan
Module to handle models in wf1 files
Eviews is started and the wf1 file is loaded.
Some transformations are performed on data.
The model is unlinked.
The workspace is saved as a wf2 file. Same name with _modelflow appended.
Eviews is closed
The wf2 file is read as a json file.
Relevant objects are extracted.
The MFMSA variable is extracted, to be saved in the dumpfile.
The equations are transformed and normalized to modelflow format and classified into identities and stochastic
Stochastic equations are enriched by add_factor and fixing terms (dummy + fixing value)
For Stochastic equations new fitted variables are generated - without add add_factors and dummies.
A model to generate fitted variables is created
A model to generate add_factors is created.
A model encompassing the original equations, the model for fitted variables and for add_factors is created.
The data series and scalars are shoveled into a Pandas dataframe
Some special series are generated as the expression can not be incorporated into modelflow model specifications
The model for fitted values is simulated in the specified timespan
The model for add_factors is simulated in the timespan set in MFMSA
The data descriptions are extracted into a dictionary.
Data descriptions for dummies, fixed values, fitted values and add_factors are derived.
Now we have a model and a dataframe with all variables which are needed.
- modelgrabwf2.wf1_to_wf2(filename, modelname='', eviews_run_lines=[])[source]
Opens a eviews workfile in wf1 format
calculates the eviews_trend
unlink a model and
writes the workspace back to a wf2 file
- Parameters:
filename (TYPE) – DESCRIPTION.
modelname (TYPE) – default ‘’ then the three first letters of the filenames stem are asumed to be the modelname.
- Returns:
None.
- modelgrabwf2.wf2_to_clean(wf2name, modelname='', save_file=False, freq='A')[source]
Takes a eviews .wf2 file - which is in JSON format - and place a dictionary
- Parameters:
wf2name (TYPE) – name of wf2 file .
modelname (TYPE, optional) – Name og model. Defaults to ‘’.
save_file (TYPE, optional) – save the specification, data and description in a dictionary. Defaults to False.
- Returns:
the content of the wf2 file as a dict .
- Return type:
model_all_about (dict)
- class modelgrabwf2.GrabWfModel(filename: any = '', modelname: any = '', freq: str = 'A', eviews_run_lines: list = <factory>, start: any = None, end: any = None, country_trans: any = <function GrabWfModel.<lambda>>, country_df_trans: any = <function GrabWfModel.<lambda>>, make_fitted: bool = False, fit_start: any = 2000, fit_end: any = None, do_add_factor_calc: bool = True, test_frml: str = '', disable_progress: bool = False, save_file: bool = False, model_description: str = '')[source]
Bases:
objectThis class takes a world bank model specification, variable data and variable description and transform it to ModelFlow business language
- Parameters:
filename – any = ‘’ #wf1 name
modelname – any = ‘’
freq – str = ‘A’
eviews_run_lines – list =field(default_factory=list)
model_all_about – dict = field(default_factory=dict)
start – any = None # start of testing if not overruled by mfmsa
end – any = None # end of testing if not overruled by mfmsa
country_trans – any = lambda x:x[:] # function which transform model specification
country_df_trans – any = lambda x:x # function which transforms initial dataframe
make_fitted – bool = False # if True, a clean equation for fittet variables is created
fit_start – any = 2000 # start of fittet model
fit_end – any = None # end of fittet model unless overruled by mfmsa
do_add_factor_calc – bool = True # calculate the add factors
test_frml – str =’’ # a testmodel as string if used no wf processing
disable_progress – bool = False # Disable progress bar
save_file – bool = False # save information to file
model_description – str = ‘’ # model description
- filename: any = ''
- modelname: any = ''
- freq: str = 'A'
- eviews_run_lines: list
- model_all_about: dict
- start: any = None
- end: any = None
- country_trans()
- country_df_trans()
- make_fitted: bool = False
- fit_start: any = 2000
- fit_end: any = None
- do_add_factor_calc: bool = True
- test_frml: str = ''
- disable_progress: bool = False
- save_file: bool = False
- model_description: str = ''
- static trans_eviews(rawmodel)[source]
Takes Eviews specifications and wrangle them into modelflow specifications
- Parameters:
rawmodel (TYPE) – a raw model .
- Returns:
a model with the appropiate eviews transformations.
- Return type:
rawmodel6 (TYPE)
- property var_description
Adds var descriptions for add factors, exogenizing dummies and exoggenizing values
- property wb_default_descriptions
- property mfmsa_options
Grab the mfmsa options, a world bank speciality
- property mfmsa_start_end
Finds the start and end from the MFMSA entry
- property mfmsa_quasiIdentities
Finds the a set containing quasiidendities
- property var_groups
- property dfmodel
The original input data enriched with during variablees, variables containing values for specific historic years and model specific transformation
- test_model(start=None, end=None, maxvar=1000000, maxerr=100, tol=0.0001, showall=False, showinput=False, nofit=True)[source]
Compares a straight calculation with the input dataframe.
shows which variables dont have the same value
- Parameters:
df (TYPE) – dataframe to run.
start (TYPE, optional) – start period. Defaults to None.
end (TYPE, optional) – end period. Defaults to None.
maxvar (TYPE, optional) – how many variables are to be chekked. Defaults to 1_000_000.
maxerr (TYPE, optional) – how many errors to check Defaults to 100.
tol (TYPE, optional) – check for absolute value of difference. Defaults to 0.0001.
showall (TYPE, optional) – show more . Defaults to False.
showinput (TYPE, optional) – show the input values Defaults to False.
nofit – if True dont show the fitted values.default True
- Returns:
None.