ModelFlowIb 2.53__tar.gz → 2.54__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {modelflowib-2.53 → modelflowib-2.54}/ModelFlowIb.egg-info/PKG-INFO +2 -2
- {modelflowib-2.53 → modelflowib-2.54}/PKG-INFO +2 -2
- {modelflowib-2.53 → modelflowib-2.54}/modelclass.py +16 -5
- {modelflowib-2.53 → modelflowib-2.54}/modelgrabwf2.py +74 -26
- {modelflowib-2.53 → modelflowib-2.54}/modelnormalize.py +5 -0
- {modelflowib-2.53 → modelflowib-2.54}/pyproject.toml +1 -1
- {modelflowib-2.53 → modelflowib-2.54}/ModelFlowIb.egg-info/SOURCES.txt +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/ModelFlowIb.egg-info/dependency_links.txt +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/ModelFlowIb.egg-info/requires.txt +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/ModelFlowIb.egg-info/top_level.txt +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelBLfunk.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_Excel.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_cvx.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_doable.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_dynare.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_financial_stability.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_ifrs9.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_latex.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_latex_class.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/model_run_numba.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelclass2.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeldash.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeldashboot.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeldashsidebar.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeldekom.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeldiff.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeldisplay.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelfeedback.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelgrab.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelhelp.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelinvert.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeljupyter.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeljupytermagic.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelmacrograb.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelmanipulation.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelmf.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelnet.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelnewton.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelpattern.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelpatternrev.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelreport.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelsandbox.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelsandbox_Mixin.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeltodo.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeluserfunk.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modeluserfunk_old.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelvis.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelwidget.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelwidget_input.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/modelwidget_shinypy.py +0 -0
- {modelflowib-2.53 → modelflowib-2.54}/setup.cfg +0 -0
|
@@ -332,7 +332,7 @@ class BaseModel():
|
|
|
332
332
|
self.endogene_true = self.endogene if self.normalized else {
|
|
333
333
|
v for v in self.exogene if v+'___RES' in self.endogene}
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
self.check_endo_rhs()
|
|
336
336
|
# dummy variables for variables for which to calculate adjustment variables
|
|
337
337
|
|
|
338
338
|
|
|
@@ -1070,8 +1070,19 @@ class BaseModel():
|
|
|
1070
1070
|
len(self.endogene))
|
|
1071
1071
|
return '<\n'+out+'>'
|
|
1072
1072
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1073
|
+
def check_endo_rhs(self):
|
|
1074
|
+
if self.normalized:
|
|
1075
|
+
for i,endovar in enumerate(sorted(self.endogene)):
|
|
1076
|
+
if i >= 2000000000000000 :break
|
|
1077
|
+
this_term = self.allvar[endovar]['terms']
|
|
1078
|
+
ap = self.allvar[endovar]['assigpos']
|
|
1079
|
+
lhs = {t.var for t in this_term[:ap] if t.var}
|
|
1080
|
+
rhs_nolag = {t.var for t in this_term[ap:] if t.var and not t.lag}
|
|
1081
|
+
both = lhs & rhs_nolag
|
|
1082
|
+
if both:
|
|
1083
|
+
print('\n\n*** PROBLEM **')
|
|
1084
|
+
print(self.allvar[endovar]['frml'])
|
|
1085
|
+
raise Exception (f'ERROR in frml for {endovar} this is on right hand side un-lagged {both}')
|
|
1075
1086
|
|
|
1076
1087
|
|
|
1077
1088
|
class Org_model_Mixin():
|
|
@@ -5005,7 +5016,7 @@ class Display_Mixin():
|
|
|
5005
5016
|
dfs = self.keep_var_dict(pat, start, end, start_ofset, end_ofset)
|
|
5006
5017
|
|
|
5007
5018
|
if showtype == 'growth':
|
|
5008
|
-
dfs = {v: vdf.pct_change()*100. for v, vdf in dfs.items()}
|
|
5019
|
+
dfs = {v: vdf.astype('float').pct_change()*100. for v, vdf in dfs.items()}
|
|
5009
5020
|
|
|
5010
5021
|
elif showtype == 'change':
|
|
5011
5022
|
dfs = {v: vdf.diff() for v, vdf in dfs.items()}
|
|
@@ -5071,7 +5082,7 @@ class Display_Mixin():
|
|
|
5071
5082
|
|
|
5072
5083
|
|
|
5073
5084
|
if showtype == 'growth':
|
|
5074
|
-
dfs = {v: vdf.pct_change()*100. for v, vdf in dfs.items()}
|
|
5085
|
+
dfs = {v: vdf.astype('float').pct_change()*100. for v, vdf in dfs.items()}
|
|
5075
5086
|
|
|
5076
5087
|
elif showtype == 'qoq_ar':
|
|
5077
5088
|
dfs = {v: ((1.+vdf.pct_change())**4.-1.)*100. for v, vdf in dfs.items()}
|
|
@@ -223,33 +223,81 @@ def wf2_to_clean(wf2name,modelname='',save_file = False,freq='A'):
|
|
|
223
223
|
|
|
224
224
|
@dataclass
|
|
225
225
|
class GrabWfModel():
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
args:
|
|
230
|
-
filename : any = '' #wf1 name
|
|
231
|
-
modelname : any = ''
|
|
232
|
-
freq : str = 'A'
|
|
233
|
-
eviews_run_lines : list =field(default_factory=list)
|
|
234
|
-
model_all_about : dict = field(default_factory=dict)
|
|
235
|
-
start : any = None # start of testing if not overruled by mfmsa
|
|
236
|
-
end : any = None # end of testing if not overruled by mfmsa
|
|
237
|
-
country_trans : any = lambda x:x[:] # function which transform model specification
|
|
238
|
-
country_df_trans : any = lambda x:x # function which transforms initial dataframe
|
|
239
|
-
make_fitted : bool = False # if True, a clean equation for fittet variables is created
|
|
240
|
-
fit_start : any = 2000 # start of fittet model
|
|
241
|
-
fit_end : any = None # end of fittet model unless overruled by mfmsa
|
|
242
|
-
do_add_factor_calc : bool = True # calculate the add factors
|
|
243
|
-
test_frml : str ='' # a testmodel as string if used no wf processing
|
|
244
|
-
disable_progress : bool = False # Disable progress bar
|
|
245
|
-
save_file : bool = False # save information to file
|
|
246
|
-
model_description : str = '' # model description
|
|
247
|
-
cty : str = '' # country ISO code like PAK, default to 3 first letter in modelname
|
|
248
|
-
cty_name : str = '' # country name like Pakistan, default to standard mapping in ISO standard
|
|
249
|
-
var_groups : dict = field(default_factory=dict,init=False) # var_groups
|
|
250
|
-
extra_var_descriptions : dict = field(default_factory=dict) # extra variable descriptions
|
|
226
|
+
"""
|
|
227
|
+
This class takes a World Bank model specification, variable data, and variable description,
|
|
228
|
+
and transforms it into ModelFlow business language.
|
|
251
229
|
|
|
252
|
-
|
|
230
|
+
Args:
|
|
231
|
+
filename : any = '' # wf1 name
|
|
232
|
+
modelname : any = ''
|
|
233
|
+
freq : str = 'A'
|
|
234
|
+
eviews_run_lines : list = field(default_factory=list)
|
|
235
|
+
model_all_about : dict = field(default_factory=dict)
|
|
236
|
+
start : any = None # start of testing if not overruled by mfmsa
|
|
237
|
+
end : any = None # end of testing if not overruled by mfmsa
|
|
238
|
+
country_trans : any = lambda x:x[:] # function which transforms model specification
|
|
239
|
+
country_df_trans : any = lambda x:x # function which transforms initial dataframe
|
|
240
|
+
make_fitted : bool = False # if True, a clean equation for fitted variables is created
|
|
241
|
+
fit_start : any = 2000 # start of fitted model
|
|
242
|
+
fit_end : any = None # end of fitted model unless overruled by mfmsa
|
|
243
|
+
do_add_factor_calc : bool = True # calculate the add factors
|
|
244
|
+
test_frml : str = '' # a test model as string; if used, no wf processing
|
|
245
|
+
disable_progress : bool = False # disable progress bar
|
|
246
|
+
save_file : bool = False # save information to file
|
|
247
|
+
model_description : str = '' # model description
|
|
248
|
+
cty : str = '' # country ISO code like PAK, defaults to first 3 letters of modelname
|
|
249
|
+
cty_name : str = '' # country name like Pakistan, default via ISO mapping
|
|
250
|
+
var_groups : dict = field(default_factory=dict, init=False) # variable groups
|
|
251
|
+
extra_var_descriptions : dict = field(default_factory=dict) # extra variable descriptions
|
|
252
|
+
|
|
253
|
+
Methods:
|
|
254
|
+
__post_init__():
|
|
255
|
+
Initialize and process the model, transform equations, perform syntax checks,
|
|
256
|
+
and set up the model and data for simulation and analysis.
|
|
257
|
+
|
|
258
|
+
print_frml(pat='*', eviews=''):
|
|
259
|
+
Print model equations matching a wildcard pattern and optional EViews content filter.
|
|
260
|
+
|
|
261
|
+
trans_eviews(rawmodel):
|
|
262
|
+
(staticmethod) Convert EViews-style equations into ModelFlow syntax.
|
|
263
|
+
|
|
264
|
+
var_description (property):
|
|
265
|
+
Return enriched variable descriptions combining WF1 file, WB defaults, and extras.
|
|
266
|
+
|
|
267
|
+
wb_default_descriptions (property):
|
|
268
|
+
Load default World Bank variable descriptions from an online repository.
|
|
269
|
+
|
|
270
|
+
mfmsa_options (property):
|
|
271
|
+
Return the raw MFMSA options XML string.
|
|
272
|
+
|
|
273
|
+
mfmsa_options_dict (property):
|
|
274
|
+
Parse and return MFMSA options as a nested dictionary.
|
|
275
|
+
|
|
276
|
+
mfmsa_start_end (property):
|
|
277
|
+
Retrieve start and end periods from MFMSA metadata.
|
|
278
|
+
|
|
279
|
+
mfmsa_country (property):
|
|
280
|
+
Retrieve the country ISO code from MFMSA metadata.
|
|
281
|
+
|
|
282
|
+
mfmsa_quasiIdentities (property):
|
|
283
|
+
Return a set of quasi-identity variable names from MFMSA.
|
|
284
|
+
|
|
285
|
+
var_groups_default (property):
|
|
286
|
+
Provide default variable groupings for World Bank models.
|
|
287
|
+
|
|
288
|
+
dfmodel (property):
|
|
289
|
+
Return the transformed and enriched dataframe for model calculation.
|
|
290
|
+
|
|
291
|
+
__call__():
|
|
292
|
+
Return the processed model object and base input dataframe.
|
|
293
|
+
|
|
294
|
+
test_model(start=None, end=None, maxvar=1_000_000, maxerr=100, tol=0.0001,
|
|
295
|
+
showall=False, showinput=False, nofit=True):
|
|
296
|
+
Compare model calculations against input data to validate model fidelity.
|
|
297
|
+
|
|
298
|
+
iso_countries (property):
|
|
299
|
+
Return a dictionary mapping ISO country codes to country names.
|
|
300
|
+
"""
|
|
253
301
|
|
|
254
302
|
filename : any = '' #wf1 name
|
|
255
303
|
modelname : any = ''
|
|
@@ -167,12 +167,17 @@ def preprocess(udtryk,funks=[]):
|
|
|
167
167
|
while pct_match := funk_in('PCT_GROWTH',udtryk_up):
|
|
168
168
|
forpc,pcudtryk,efterpc=funk_find_arg(pct_match,udtryk_up)
|
|
169
169
|
udtryk_up=f'{forpc} (100 * ( ({pcudtryk}) / ({lagone(pcudtryk,funks=funks)}) -1)) {efterpc}'
|
|
170
|
+
|
|
171
|
+
while pct_match := funk_in('PCY',udtryk_up):
|
|
172
|
+
forpc,pcudtryk,efterpc=funk_find_arg(pct_match,udtryk_up)
|
|
173
|
+
udtryk_up=f'{forpc} (100 * ( ({pcudtryk}) / ({lagone(pcudtryk,funks=funks,laglead=-4)}) -1)) {efterpc}'
|
|
170
174
|
|
|
171
175
|
while diff_match := funk_in('DIFF' , udtryk_up):
|
|
172
176
|
fordif,difudtryk_up,efterdif=funk_find_arg(diff_match,udtryk_up)
|
|
173
177
|
udtryk_up=fordif+'(('+difudtryk_up+')-('+lagone(difudtryk_up+'',funks=funks)+'))'+efterdif
|
|
174
178
|
|
|
175
179
|
while diff_match := funk_in('D' , udtryk_up):
|
|
180
|
+
print(f'{udtryk_up} on D')
|
|
176
181
|
fordif,difudtryk_up,efterdif=funk_find_arg(diff_match,udtryk_up)
|
|
177
182
|
difudtryk_up = difudtryk_up.replace(' ','').replace(',0,1','') if difudtryk_up.endswith(',0,1') else difudtryk_up
|
|
178
183
|
udtryk_up=fordif+'(('+difudtryk_up+')-('+lagone(difudtryk_up+'',funks=funks)+'))'+efterdif
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|