Best Python code snippet using localstack_python
cf_test.py
Source:cf_test.py
1# -*- coding: utf-8 -*-2import pandas as pd3import numpy as np4import CashFlowModelMain as cf_main5import PySimpleGUI as sg6import json7import gc8gc.collect()9pd.set_option('display.max_columns', 500)10#import DataPrep.DataMover as data_mover11#import openpyxl as xl12#import GUI.index as gui13gui.app.run_server(debug=False)14pd.options.display.float_format = '{:20,.2f}'.format15import DataPrep.DataMover as data_prep16prep = data_prep.DataPrep()17asset_class = 'solar'18sql="""19 SELECT TOP 1 model_key20 ,model_name21 --,scenario_key22 --,seq_order23 FROM fra.cf_model.vw_scenario24 WHERE 1=125 AND uw_type='template'26 --AND asset_class='{}'27 ORDER BY seq_order28""".format(asset_class)29sql = """30SELECT top 1 uw_month31 , scenario_key32 from fra.cf_model.vw_scenario33 where 1=134 and model_name='{}'35 """.format('Solar Template')36model_attr = prep.sql_engine_import.execute(sql, output=True)37model_attr.squeeze()38len(model_attr)39model_attr40#########################################41# testing42#########################################43import CashFlowModelMainV2 as cf_main44############################################################45#Build Solar Asset Class Template46solar_template_model = cf_main.CashFlowModel.new_model(model_name='Solar Template', deal_ids=[], batch_keys=[], asset_class='solar',uw_month=None, uw_type='template')47#import sample data48solar_template_model.import_data_tape_sql(source='cdw')49#create curve group50solar_template_model.create_curve_group('Solar Asset Class - 201909')51file_path = r"\\SRV-NWUS-SHR\BA$\Credit Strategy\4. RUW\2. Deliverables\2019\201908 - Mosaic\Model\Mosaic RUW 201908 V11.xlsm"52solar_template_model.import_rate_curves_excel('Solar Asset Class - 201909', 'default', 'base', file_path, 'MDR', 'C3:NF363', key_cols=['Key'])53solar_template_model.import_rate_curves_excel('Solar Asset Class - 201909', 'prepay', 'base', file_path, 'MPR', ws_range='C3:NF363', key_cols=['Key'])54solar_template_model.import_rate_curves_excel('Solar Asset Class - 201909', 'curtail', 'base', file_path, 'MCR', ws_range='C3:NF363', key_cols=['Key'])55solar_template_model.create_recovery_curve('Solar Asset Class - 201909', (18, 0.25))56#create segments57solar_template_model.create_segment(use_gui=False, curve_group_name='Solar Asset Class - 201909', segment_type='default', OriginationTerm=[], OriginationCreditScore=[700,750,800]) 58solar_template_model.create_segment(use_gui=False, curve_group_name='Solar Asset Class - 201909', segment_type='prepay', OriginationCreditScore=[700,750,800]) 59solar_template_model.create_segment(use_gui=False, curve_group_name='Solar Asset Class - 201909', segment_type='curtail', OriginationTerm=[], OriginationCreditScore=[700,750,800], OriginationMonth=[]) 60solar_template_model.return_curve_map('Solar Asset Class - 201909')61#manual map for missing62manual_map = {63 'default': {'120|700-750': '120|700-750',64 '120|750-800': '120|750-800',65 '120|<700': '120|<700',66 '180|700-750': '180|700-750',67 '180|750-800': '180|750-800',68 '180|<700': '180|<700',69 '240|700-750': '240|700-750',70 '240|750-800': '240|750-800',71 '240|<700': '240|<700',72 '300|700-750': '300|700-750',73 '300|750-800': '300|750-800',74 '300|<700': '300|<700',75 '120|>800': '120|800-850',76 '144|>800': '144|800-850',77 '180|>800': '180|800-850',78 '240|>800': '240|800-850',79 '300|>800': '300|800-850'},80 'prepay': {'700-750': '700-750',81 '750-800': '750-800',82 '<700': '<700',83 '>800': '800-850'},84 'curtail': {'120|700-750|1': '120|700-750|1',85 '120|700-750|10': '120|700-750|10',86 '120|700-750|11': '120|700-750|11',87 '120|700-750|12': '120|700-750|12',88 '120|700-750|2': '120|700-750|2',89 '120|700-750|3': '120|700-750|3',90 '120|700-750|4': '120|700-750|4',91 '120|700-750|5': '120|700-750|5',92 '120|700-750|6': '120|700-750|6',93 '120|700-750|7': '120|700-750|7',94 '120|700-750|8': '120|700-750|8',95 '120|700-750|9': '120|700-750|9',96 '120|750-800|1': '120|750-800|1',97 '120|750-800|10': '120|750-800|10',98 '120|750-800|11': '120|750-800|11',99 '120|750-800|12': '120|750-800|12',100 '120|750-800|4': '120|750-800|4',101 '120|750-800|5': '120|750-800|5',102 '120|750-800|6': '120|750-800|6',103 '120|750-800|7': '120|750-800|7',104 '120|750-800|8': '120|750-800|8',105 '120|750-800|9': '120|750-800|9',106 '120|<700|1': '120|<700|1',107 '120|<700|10': '120|<700|10',108 '120|<700|11': '120|<700|11',109 '120|<700|12': '120|<700|12',110 '120|<700|2': '120|<700|2',111 '120|<700|3': '120|<700|3',112 '120|<700|4': '120|<700|4',113 '120|<700|5': '120|<700|5',114 '120|<700|6': '120|<700|6',115 '120|<700|7': '120|<700|7',116 '120|<700|8': '120|<700|8',117 '120|<700|9': '120|<700|9',118 '180|700-750|1': '180|700-750|1',119 '180|700-750|10': '180|700-750|10',120 '180|700-750|11': '180|700-750|11',121 '180|700-750|12': '180|700-750|12',122 '180|700-750|2': '180|700-750|2',123 '180|700-750|3': '180|700-750|3',124 '180|700-750|4': '180|700-750|4',125 '180|700-750|5': '180|700-750|5',126 '180|700-750|6': '180|700-750|6',127 '180|700-750|7': '180|700-750|7',128 '180|700-750|8': '180|700-750|8',129 '180|700-750|9': '180|700-750|9',130 '180|750-800|1': '180|750-800|1',131 '180|750-800|10': '180|750-800|10',132 '180|750-800|11': '180|750-800|11',133 '180|750-800|12': '180|750-800|12',134 '180|750-800|4': '180|750-800|4',135 '180|750-800|5': '180|750-800|5',136 '180|750-800|6': '180|750-800|6',137 '180|750-800|7': '180|750-800|7',138 '180|750-800|8': '180|750-800|8',139 '180|750-800|9': '180|750-800|9',140 '180|<700|1': '180|<700|1',141 '180|<700|10': '180|<700|10',142 '180|<700|11': '180|<700|11',143 '180|<700|12': '180|<700|12',144 '180|<700|2': '180|<700|2',145 '180|<700|3': '180|<700|3',146 '180|<700|4': '180|<700|4',147 '180|<700|5': '180|<700|5',148 '180|<700|6': '180|<700|6',149 '180|<700|7': '180|<700|7',150 '180|<700|8': '180|<700|8',151 '180|<700|9': '180|<700|9',152 '240|700-750|1': '240|700-750|1',153 '240|700-750|10': '240|700-750|10',154 '240|700-750|11': '240|700-750|11',155 '240|700-750|12': '240|700-750|12',156 '240|700-750|2': '240|700-750|2',157 '240|700-750|3': '240|700-750|3',158 '240|700-750|4': '240|700-750|4',159 '240|700-750|5': '240|700-750|5',160 '240|700-750|6': '240|700-750|6',161 '240|700-750|7': '240|700-750|7',162 '240|700-750|8': '240|700-750|8',163 '240|700-750|9': '240|700-750|9',164 '240|750-800|1': '240|750-800|1',165 '240|750-800|10': '240|750-800|10',166 '240|750-800|11': '240|750-800|11',167 '240|750-800|12': '240|750-800|12',168 '240|750-800|4': '240|750-800|4',169 '240|750-800|5': '240|750-800|5',170 '240|750-800|6': '240|750-800|6',171 '240|750-800|7': '240|750-800|7',172 '240|750-800|8': '240|750-800|8',173 '240|750-800|9': '240|750-800|9',174 '240|<700|1': '240|<700|1',175 '240|<700|10': '240|<700|10',176 '240|<700|11': '240|<700|11',177 '240|<700|12': '240|<700|12',178 '240|<700|2': '240|<700|2',179 '240|<700|3': '240|<700|3',180 '240|<700|4': '240|<700|4',181 '240|<700|5': '240|<700|5',182 '240|<700|6': '240|<700|6',183 '240|<700|7': '240|<700|7',184 '240|<700|8': '240|<700|8',185 '240|<700|9': '240|<700|9',186 '300|700-750|1': '300|700-750|1',187 '300|700-750|10': '300|700-750|10',188 '300|700-750|11': '300|700-750|11',189 '300|700-750|12': '300|700-750|12',190 '300|700-750|2': '300|700-750|2',191 '300|700-750|3': '300|700-750|3',192 '300|700-750|4': '300|700-750|4',193 '300|700-750|5': '300|700-750|5',194 '300|700-750|6': '300|700-750|6',195 '300|700-750|7': '300|700-750|7',196 '300|700-750|8': '300|700-750|8',197 '300|700-750|9': '300|700-750|9',198 '300|750-800|1': '300|750-800|1',199 '300|750-800|10': '300|750-800|10',200 '300|750-800|11': '300|750-800|11',201 '300|750-800|12': '300|750-800|12',202 '300|750-800|2': '300|750-800|2',203 '300|750-800|3': '300|750-800|3',204 '300|750-800|4': '300|750-800|4',205 '300|750-800|5': '300|750-800|5',206 '300|750-800|6': '300|750-800|6',207 '300|750-800|7': '300|750-800|7',208 '300|750-800|8': '300|750-800|8',209 '300|750-800|9': '300|750-800|9',210 '300|<700|1': '300|<700|1',211 '300|<700|10': '300|<700|10',212 '300|<700|11': '300|<700|11',213 '300|<700|12': '300|<700|12',214 '300|<700|2': '300|<700|2',215 '300|<700|3': '300|<700|3',216 '300|<700|4': '300|<700|4',217 '300|<700|5': '300|<700|5',218 '300|<700|6': '300|<700|6',219 '300|<700|7': '300|<700|7',220 '300|<700|8': '300|<700|8',221 '300|<700|9': '300|<700|9',222 '120|>800|1': '120|800-850|1',223 '120|>800|10': '120|800-850|10',224 '120|>800|11': '120|800-850|11',225 '120|>800|12': '120|800-850|12',226 '120|>800|2': '120|800-850|2',227 '120|>800|3': '120|800-850|3',228 '120|>800|4': '120|800-850|4',229 '120|>800|5': '120|800-850|5',230 '120|>800|6': '120|800-850|6',231 '120|>800|7': '120|800-850|6',232 '120|>800|8': '120|800-850|8',233 '120|>800|9': '120|800-850|9',234 '144|>800|1': '144|800-850|1',235 '144|>800|10': '144|800-850|10',236 '144|>800|11': '144|800-850|11',237 '144|>800|12': '144|800-850|12',238 '144|>800|2': '144|800-850|2',239 '144|>800|3': '144|800-850|3',240 '144|>800|4': '144|800-850|4',241 '144|>800|5': '144|800-850|5',242 '144|>800|6': '144|800-850|6',243 '144|>800|7': '144|800-850|6',244 '144|>800|8': '144|800-850|8',245 '144|>800|9': '144|800-850|9',246 '180|>800|1': '180|800-850|1',247 '180|>800|10': '180|800-850|10',248 '180|>800|11': '180|750-800|11',249 '180|>800|12': '180|800-850|12',250 '180|>800|2': '180|800-850|2',251 '180|>800|3': '180|800-850|3',252 '180|>800|4': '180|800-850|4',253 '180|>800|5': '180|800-850|5',254 '180|>800|6': '180|800-850|6',255 '180|>800|7': '180|800-850|7',256 '180|>800|8': '180|800-850|8',257 '180|>800|9': '180|800-850|9',258 '240|>800|1': '240|800-850|1',259 '240|>800|10': '240|800-850|10',260 '240|>800|11': '240|800-850|11',261 '240|>800|12': '240|800-850|12',262 '240|>800|2': '240|800-850|2',263 '240|>800|3': '240|800-850|3',264 '240|>800|4': '240|800-850|4',265 '240|>800|5': '240|800-850|5',266 '240|>800|6': '240|800-850|6',267 '240|>800|7': '240|800-850|7',268 '240|>800|8': '240|800-850|8',269 '240|>800|9': '240|800-850|9',270 '300|>800|1': '300|800-850|1',271 '300|>800|10': '300|800-850|10',272 '300|>800|11': '300|800-850|11',273 '300|>800|12': '300|800-850|12',274 '300|>800|2': '300|800-850|2',275 '300|>800|3': '300|800-850|3',276 '300|>800|4': '300|800-850|4',277 '300|>800|5': '300|800-850|5',278 '300|>800|6': '300|800-850|6',279 '300|>800|7': '300|800-850|7',280 '300|>800|8': '300|800-850|8',281 '300|>800|9': '300|800-850|9'},282 'recovery': {},283 'collection': {}}284solar_template_model.map_curves(curve_group_name='Solar Asset Class - 201909', manual_map=manual_map)285#create model configuration286config={}287config['amort_formula'] = {}288config['amort_timing'] = {}289config['amort_timing']['promo'] = "['MonthsToAcquisition'] == 0" #(['MonthsOnBook'] < 18) & (['ProjectionMonth']==1)290config['amort_formula']['promo'] = "np.pmt(['InterestRate'], ['OriginationTerm']-['PromoTerm'], ['PromoTargetBalance'])"291config['amort_timing']['promo end'] = "['MonthsOnBook'] == ['PromoTerm']"292config['amort_formula']['promo end'] = ''293config['default_amort_type'] = 'scale'294solar_template_model.create_model_config(model_config_name='Solar Asset Class', config_type=1, config_dict=config)295#create Base Case Sceanrio296solar_template_model.create_cf_scenario('Base Case', cutoff_date=None, curve_group='Solar Asset Class - 201909', index_projection_date=None, model_config='Solar Asset Class')297#######################################################################################298## create Mosaic Model299mosaic = cf_main.CashFlowModel.new_model(model_name='Mosaic', deal_ids=[171], batch_keys=[], asset_class='solar', uw_type='ruw', uw_month='201909')300mosaic.create_cf_scenario('Backtest', cutoff_date='2016-10-31', curve_group='Solar Asset Class - 201909', index_projection_date=None, model_config='Solar Asset Class')301mosaic.create_cf_scenario('Base Case', cutoff_date='2019-08-31', curve_group='Solar Asset Class - 201909', index_projection_date=None, model_config='Solar Asset Class')302mosaic.run_cash_flows()303mosaic.eval.create_plot('ScheduledPaymentAmount', end_period=150)304mosaic.eval.create_table('ContractualPrincipalPayment', end_period=120, rate=True)305mosaic.eval.create_plot('Historical ChargeOff Recovery', end_period=200)306stress = {307 'default': [(0, 0.50), (12, 0.50), (24, 0)],308 'recovery': [(0, -0.25)]309 }310##########################################################################################311## Create Galileo 1312cf_model = cf_main.CashFlowModel.new_model(model_name='Galileo', deal_ids=[193], batch_keys=[], asset_class='solar', uw_type='ruw', uw_month='201909')313#import curves314#cf_model.import_rate_curves(use_gui=True)315#import model template316#cf_model.download_model_template()317#create a new curve set318#cf_model.copy_curves('Galileo - Default', 'Solar Asset Class - 201909') #curve_type=['prepay', 'curtail']319#create new curve group and load with base solar curves320cf_model.create_curve_group('Galileo Defaults')321cf_model.import_rate_curves_sql(curve_group_name='Galileo Defaults', model_name='Solar Template', scenario_name='Base Case', curve_type='all')322#import Galileo Specific Curves323file_path = r"\\SRV-NWUS-SHR\BA$\Credit Strategy\4. RUW\2. Deliverables\2019\201909 - Galileo 1\Model\Galileo 1 Solar RUW 201909 V5 (CPR Adj).xlsm"324cf_model.import_rate_curves_excel('Galileo Defaults', 'default', 'base', file_path, 'MDR', ws_range='C3:NF363', key_cols=['Key'])325#curtail adjust326cf_model.import_rate_curves_excel('Galileo Defaults', 'curtail', 'adjust', file_path, 'MCR', ws_range='ABQ3:APT363', key_cols=['Key'])327#prepay adjust328cf_model.import_rate_curves_excel('Galileo Defaults', 'prepay', 'adjust', file_path, 'MPR', ws_range='ABQ3:APT363', key_cols=['Key'])329cf_model.create_cf_scenario('Base Case', cutoff_date='2019-08-31', curve_group='Galileo Defaults', model_config='Solar Asset Class')330cf_model.create_cf_scenario('Backtest', cutoff_date='min', curve_group='Galileo Defaults', model_config='Solar Asset Class')331cf_model.run_cash_flows()332#check actuals/projections333cf_model.eval.create_plot('TotalPaymentMade')334##########################################################################################335## Download Test336import CashFlowModelMain as cf_main337import numpy as np338import pandas as pd339new_template = cf_main.CashFlowModel.create_template('solar')340new_template341template = cf_main.CashFlowModel.load_model(model_name='Solar Template')342download_model = cf_main.CashFlowModel.load_model(model_name='Faraday', uw_month=None) 343download_model.set_final_scenario('Base2')344download_model.import_data_tape_sql() 345download_model.run_cash_flows() 346download_model.eval.create_avp()347refresh_model = cf_main.CashFlowModel.refresh_model(model_name='Faraday', uw_month=202108)348refresh_model.run_cash_flows()349refresh_model.eval.create_avp()350refresh_model.cf_scenarios351month_end_date = datetime.date(int(str(uw_month)[0:4]), int(str(uw_month)[4:6]), 1) + relativedelta(months=-1, day=31)352new_cutoff = month_end_date.strftime("%Y-%m-%d")353download_model.rate_curve_groups['Solar Asset Class - 201909'].map_segments_to_curves('recovery')354download_model.rate_curve_groups['Solar Asset Class - 201909'].segments['recovery'].segment_rules __dict__.keys()355download_model= cf_main.CashFlowModel.load_model(model_name='Casser')356download_model.run_cash_flows(['Casser 052021 Backtest v2'])357download_model.import_rate_curves_sql(curve_group_name='single_curve_test', source_curve_group_name='FaradayOrigP2', update_curve_map=False)358download_model.rate_curve_groups['FaradayOrigP1'].segment_curve_map359download_model.rate_curve_groups['FaradayOrigP1'].segment_map_manual360download_model = cf_main.CashFlowModel.load_model(model_name='Voyager2')361download_model.run_cash_flows()362download_model.cf_scenarios363download_model.run_single_account(scenario='Base', account_id=20618302)364download_model.eval.create_avp()365download_model.cf_scenarios366download_model.set_final_scenario('Stress2')367download_model.eval.create_plot('PostChargeOffCollections')368download_model.eval.create_table('PrincipalFullPrepayment')369download_model.eval.create_avp()370download_model.eval.return_metric_list()371download_model.rate_curve_groups['VoyagerFFOrigP'].curves[('recovery', 'base')].data_rate_curves['rate'].values372download_model.model_configs['VoyagerFFBase'].config_dict373download_model.data_tape.cutoff_tape374download_model.cf_scenarios['Base'][1]._cf_data.keys()375stress = {'default': [(0, 0.1), (12, 0.1), (24, 0.0)],376 'prepay': [(0, -0.25), (12, -0.25), (24, 0.0)]}377import json378stress_json = json.dumps(stress)379stress_convert = json.loads(stress_json)380{k:[tuple(i) for i in v] for (k, v) in stress_convert.items()}381download_model.rate_curve_groups['VoyagerFFOrigP'].curves[('default','base')].data_rate_curves382download_model.data_tape.cutoff_tape['BOM_PrincipalBalance'].sum()383download_model.data_tape.cutoff_tape['TotalPrincipalBalance'].sum()384download_model.import_rate_curves(use_gui=True)385download_model.rate_curve_groups386download_model.rate_curve_groups['Galileo Defaults'].segment_account_map387download_model.rate_curve_groups['Galileo Defaults'].curve_account_map388download_model.rate_curve_groups['Galileo Defaults'].transition_keys #curve_keys, transition_keys389download_model.rate_curve_groups['Galileo Defaults'].curve_keys390download_model.rate_curve_groups['Galileo Defaults'].transition_keys391download_model.rate_curve_groups['Galileo Defaults'].curve_type_info392download_model.rate_curve_groups['Galileo Defaults']393download_model.rate_curve_groups['CasserCurves'].394stress_test = '{"default": [[0, 0.1], [12, 0.1], [24, 0.0]], "prepay": [[0, -0.25], [12, -0.25], [24, 0.0]]}'395import json396json.loads(stress_test)397promo_types = {'No Interest': (0, 1, )}398download_model.eval.create_avp()399os.startfile(in_mem_file)400download_model.rate_curve_groups['Galileo Defaults'].return_curve_group(['default', 'prepay'])401download_model.rate_curve_groups['Galileo Defaults'].curve_account_map402curve_keys = download_model.rate_curve_groups['Galileo Defaults'].curve_keys403trans_keys = download_model.rate_curve_groups['Galileo Defaults'].transition_keys404download_model.rate_curve_groups['Galileo Defaults'].return_transition_matrix2()405download_model.rate_curve_groups['Galileo Defaults'].return_rate_matrix('recovery')406download_model.rate_curve_groups['Galileo Defaults'].curves[('default','base')].data_rate_curves407curve_keys[curve_keys['curve_type']=='rollrate']408rr_matrix = download_model.rate_curve_groups['Galileo Defaults'].return_transition_matrix()409curtail_matrix = download_model.rate_curve_groups['Galileo Defaults'].return_rate_matrix('curtail')410rate_data = download_model.rate_curve_groups['Galileo Defaults'].return_curve_group(['default','prepay','rollrate'])411rate_data.droplevel(['curve_type', 'curve_key'])412rr_matrix[0, :, 1, 8]413trans_keys[trans_keys['curve_type']=='curtail']414rr_segment = download_model.rate_curve_groups['Galileo Defaults'].return_transition_matrix()415rr_segment[1, :, 0, 8]416#isolate the default rolls417default_ix = (rr_segment['from_status']==1) & (rr_segment['to_status']==8)418rr_duplicate = pd.concat([rr_segment[default_ix.values]]*6) # , ignore_index=True)419rr_duplicate['from_status'] = rr_duplicate.groupby(['rollrate']).cumcount()+2420rr_duplicate421batch_array = download_model.eval.cf_output.index.get_level_values('BatchKey').values 422np.in1d(batch_array, [504, 522]))423download_model.eval.return_metric_list()424download_model.eval.create_plot('PrincipalPartialPrepayment')425download_model.eval.create_plot('PrincipalFullPrepayment')426download_model.eval.create_plot('PrincipalTotalPrepayment')427download_model.eval.create_plot('ChargeOffAmount')428download_model.eval.create_table('ChargeOffAmount')429download_model.eval.create_plot('TotalPaymentMade')430download_model.eval.create_plot('ScheduledPaymentMade')431download_model.eval.create_plot('BOM_PrincipalBalance')432download_model.eval.create_plot('ContractualPrincipalPayment')433download_model.eval.create_plot('InterestPayment')434download_model.eval.return_metric_list()435trans_matrix = download_model.rate_curve_groups['Galileo Defaults'].return_transition_matrix()436download_model.rate_curve_groups['Galileo Defaults'].curves437download_model.rate_curve_groups['Galileo Defaults'].curve_account_map438download_model.rate_curve_groups['Galileo Defaults'].segment_account_map439download_model.rate_curve_groups['Galileo Defaults'].return_rate_matrix('default')440download_model.rate_curve_groups['Galileo Defaults'].return_curve_group('prepay')441download_model.rate_curve_groups['Galileo Defaults'].curves[('default','base')].data_rate_curves442download_model.rate_curve_groups['Galileo Defaults'].__dict__.keys()443download_model.rate_curve_groups['Galileo Defaults'].curve_keys444download_model.import_rate_curves(use_gui=True)445download_model.map_curves(use_gui=True, curve_group_name='Galileo - Default')446download_model.rate_curve_groups['Galileo - Default'].segment_curve_map[['segment_type','segment_name','curve_name']]447download_model.rate_curve_groups['Galileo - Default'].curve_keys[['curve_name', 'curve_type']].drop_duplicates()448download_model.data_tape.raw_tape449proj_test = download_model.data_prep.import_index_projections('2020-01-31')450name_ix = proj_test.raw_projections['IndexName'].isin(proj_test.index_list.values())451#projection_select = proj_test.raw_projections.loc[name_ix].copy()452projection_select = proj_test.raw_projections.copy()453#index_name_swap = {v:k for k,v in proj_test.index_list.items()}454#projection_select['IndexID'] = projection_select['IndexName'].map(index_name_swap)455#################################################################################456## RUW test457galileo_refresh = cf_main.CashFlowModel.ruw_model(model_name='Galileo', uw_month=202011, scenario_list=['Base Case'])458type(galileo_refresh.model_id)459galileo_refresh.uw_month460####################################################################################461## Roll Rate Test462rr_test = cf_main.CashFlowModel.new_model(model_name='ja adhoc', deal_ids=[], batch_keys=[], asset_class=None, uw_month=None, uw_type='test')463rr_test.create_curve_group(curve_group_name='rr_test')464rr_test.import_rate_curves_sql(curve_group_name='rr_test', source_curve_group_name='Express 201706')465rr_test.rate_curve_groups['rr_test'].curves[('rollrate','base')].data_rate_curves466rr_test.rate_curve_groups['rr_test'].curves[('rollrate','base')].return_transition_matrix()467rr_test.rate_curve_groups['rr_test'].curve_keys468rr_test.rate_curve_groups['rr_test'].curve_account_map469curve_frame = rr_test.rate_curve_groups['rr_test'].curves[('rollrate','base')].data_rate_curves.set_index(['from_status', 'to_status'], append=True)470dict_test = curve_frame.xs('Career', level='curve_id')['rate'].groupby(['from_status','to_status']).apply(list).to_dict()471dict_len = len(next(iter(dict_test.values())))472import numpy as np473rr_array = np.ones(shape=[15,15,dict_len])474for key, value in dict_test.items():475 rr_array[key[0], key[1]] = value476 477rr_array[1, 2] 478 479np.fromiter480rr_test.rate_curve_groups481download_model.rate_curve_groups['Galileo Defaults'].data_tape.account_status_list482len(curve_frame)['Career'])483rate_dict = {l: rate_data_fill.xs(l, level=0).groupby('curve_key').apply(list).to_dict() for l in rate_data_fill.index.levels[0]}484import DataPrep.DataMover as data_prep485xl_engine = data_prep.ExcelEngine()486sql_engine = data_prep.SQLEngine()487file_path = r"M:\Credigy\Financial Risk Analytics\Re-Underwrite\Deliverables\2021\202103 - Express\Express - PM - RUW 61217 v6 (Revert to 3-16 RUW after 12 months).xlsm"488file_path = r"R:\PL\1. US\A. Banking\Acquired\3. Performing Loans\2015\11-2014 - Express\3. RUW 6-17\Express RUW\Express - PM - RUW 61217 v6 (Revert to 3-16 RUW after 12 months).xlsm"489rr_excel_range = xl_engine.from_excel(file_path=file_path, ws_name='RR', ws_range='E4:GF')490rr_excel_range.dropna(axis=0, inplace=True)491rr_excel_range.drop(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'], axis=1, inplace=True)492rr_pivot = rr_excel_range.melt(id_vars= ['Month', 'Segment'], var_name='transition', value_name='rate')493rr_pivot[['from_status', 'to_status']] = rr_pivot['transition'].str.split(' to ', 1, expand=True)494rr_pivot.drop('transition', axis=1, inplace=True)495rr_pivot['curve_name']=rr_pivot['Segment']496column_map = {497 'Segment':'curve_id',498 'Month':'period'499 }500rr_pivot.rename(column_map, axis=1, inplace=True)501rr_pivot['curve_type']='rollrate'502rr_pivot['curve_sub_type']='base'503rr_pivot = rr_pivot.astype({'period':'int32'})504rr_pivot.set_index(['curve_id','period'], inplace=True)505rr_pivot.set_index(['from_status', 'to_status'], append=True, inplace=True)506rr_pivot.xs(('Career',59,'5','5'))507express_rr.508express_rr = data_prep.CurveGroup(curve_group_key=3, curve_group_name='Express 201706', data_tape=None, period_type='calendar') 509express_rr.add_curve(rr_pivot, 'rollrate', 'base', 'calendar', 'Excel Custom Curves')510express_rr.curves[('rollrate', 'base')]511express_rr.curves[('rollrate', 'base')].data_rate_curves.set_index(['from_status','to_status'], append=True).xs(('Career',59,'5'))512curve_group_key = express_rr.curve_group_key513rate_json = express_rr.curves[('rollrate', 'base')].curve_json()514#look for corresponding segment if exists515#segment_key = self.rate_curve_groups[curve_group].segments[curve_type].segment_key516segment_key=None517sql_cmd = "exec fra.cf_model.usp_upload_curve_rates ?, ?, ?, ?, ?, ?, ?"518params = [curve_group_key, 'rollrate', 'base', 'calendar', 'Excel Custom Curves', rate_json, segment_key]519sql_engine.execute(sql_cmd, params)520pd.read_json(rate_json).set_index(['period','from_status','to_status']).xs((1, 0, 0))521cf_main.CashFlowModel.new_model('JA AdHoc')522download_model.rate_curve_groups['Galileo Defaults'].curves[('default', 'base')].data_rate_curves523projection_select['curve_type'] = 'index'524projection_select['curve_sub_type'] = 'base'525projection_select['from_status'] = -1526projection_select['to_status'] = -1527column_map = {'IndexName':'curve_id',528 'ProjectionMonth':'period',529 }530projection_select.rename(column_map, axis=1, inplace=True)531projection_select532projection_select = projection_select[['curve_type','curve_sub_type','curve_id', 'period','rate', 'from_status', 'to_status']].set_index(['curve_type','curve_sub_type','curve_id', 'period']).sort_index()533projection_select.xs('1 Month LIBOR Rate')534download_model.rate_curve_groups['Galileo - Default'].curves[('default', 'base')].data_rate_curves #curve_ids535download_model.cf_scenarios['Base Case']536download_model.run_cash_flows(['Backtest'], False)537rollrates = download_model.cf_scenarios['Base Case'][1]._cf_modules['rate_curves'].cf_model_data['rate_arrays']['rollrate']538pd.DataFrame(rollrates[1, 1])539np.zeros([14,14])540download_model.data_tape.cutoff_tape541download_model.cf_scenarios['Base Case'][1]._model_config542download_model.cf_scenarios['Base Case'][1]._cf_data543download_model.cf_scenarios['Base Case'][1]._cf_modules['time'].cf_model_data544download_model.cf_scenarios['Base Case'][1]._cf_metrics545download_model.cf_scenarios['Base Case'][1].model_state_output['MonthsOnBook']546#self._cf_data[key][0] = np.nan #value547download_model.cf_scenarios['Base Case'][1]._cf_data['month_of_year'][0] = np.nan548download_model.cf_scenarios['Base Case'][1]._cf_data['month_of_year'][0].dtype549for key in download_model.cf_scenarios['Base Case'][1]._cf_data.keys():550 print(download_model.cf_scenarios['Base Case'][1]._cf_data[key].dtype)551download_model.cf_scenarios['Base Case'][1]._cf_data.keys() 'upb_trans_agg' 'PrincipalPartialPrepayment'552pd.DataFrame(download_model.cf_scenarios['Base Case'][1]._cf_data['upb_trans_agg'][1,1]) .shape553pd.DataFrame(np.sum(download_model.cf_scenarios['Base Case'][1]._cf_data['upb_trans_agg'][1,1], axis=0))554download_model.cf_scenarios['Base Case'][1]._cf_data['PrincipalPartialPrepayment'].shape555download_model.cf_scenarios['Base Case'][1]._cf_data['TotalPrincipalBalance'].shape556prepay = download_model.cf_scenarios['Base Case'][1]._cf_data['PrincipalPartialPrepayment']557download_model.cf_scenarios['Base Case'][1]._cf_data.keys()558download_model.eval.559pd.DataFrame(np.sum(download_model.cf_scenarios['Backtest'][1].cf_input_data['BOM_PrincipalBalance'], axis=0))560download_model.cf_scenarios['Base Case'][1].cf_input_data['TotalPrincipalBalance'].shape561prepay_sum = np.sum(prepay, axis=0)562prepay_sum.shape563download_model.cf_scenarios['Backtest'][1]._cf_data['AsOfDate'][0].shape564import ECL.RollRateConvert as rr_convert565ecl_rr = rr_convert.RollRateConvert(variance_step=6)566ecl_rr.calibrate_rolls(download_model.cf_scenarios['Backtest'][1])567test_frame = pd.DataFrame(index=download_model.cf_scenarios['Backtest'][1]._cf_data['AsOfDate'][0])568test_frame['co_target'] = ecl_rr.scenario_metrics['co_target']569test_frame['goal_seek_output'] = ecl_rr.co_output570test_frame.plot.line()571test_frame.sum()572po_frame = pd.DataFrame(index=download_model.cf_scenarios['Backtest'][1]._cf_data['AsOfDate'][0])573po_frame['po_target'] = ecl_rr.scenario_metrics['po_target']574po_frame['goal_seek_output'] = ecl_rr.po_output575po_frame.plot.line()576po_frame.sum()577pd.DataFrame(ecl_rr.full_roll_matrix[0])578pd.DataFrame(ecl_rr.forward_drift_matrix)579pd.DataFrame(ecl_rr.combined_mask)580ecl_rr.cf_metrics['eom_upb_sum'][:, 8]581ecl_rr.base_rolls582np.sum(ecl_rr.full_roll_matrix, axis=2)583np.sum(ecl_rr.full_roll_matrix[0], axis=0)584pd.DataFrame(ecl_rr.full_roll_matrix[0])585pd.DataFrame(ecl_rr.combined_mask)5861-np.sum(ecl_rr.full_roll_matrix, axis=2, where=ecl_rr.combined_mask[np.newaxis, :, :])587ecl_rr.rr_inputs_flatten()588ecl_rr.rr_inputs_reshape(ecl_rr.goal_seek_input)589len(inputs_reshape[3])590ecl_rr.po_drift_matrix.shape591ecl_rr.goal_seek_input592np.array_split(ecl_rr.goal_seek_input, [15,10, 20])593np.sum(ecl_rr.full_roll_matrix, axis=2)594ecl_rr.cf_metrics.keys()595ecl_rr.cf_metrics['C'].shape596ecl_rr.cf_metrics['ppmt'][1]597test_output = np.multiply(ecl_rr.cf_metrics['bom_upb'][0], ecl_rr.full_roll_matrix[0])598pd.DataFrame(ecl_rr.cf_metrics['bom_upb'][0])599pd.DataFrame(np.sum(test_output, axis=0))600pd.DataFrame(ecl_rr.full_roll_matrix[0])601ecl_rr.cf_metrics['eom_upb'][0].shape602ecl_rr.scenario603metric = download_model.cf_scenarios['Backtest'][1]._cf_data['upb_trans_agg']604np.nan_to_num(np.sum(metric[:, :, 13,1], axis=0))605curtail = download_model.cf_scenarios['Base Case'][1]._cf_data['PrincipalPartialPrepayment']606download_model.cf_scenarios['Base Case'][1]._cf_data['TotalPrincipalBalance'][0,0]607download_model.cf_scenarios['Base Case'][1].cf_input_data['BOM_PrincipalBalance'].shape608curtail.shape609metric.shape610def eom_status_sum(metric):611 #sum accounts612 metric_sum = np.sum(metric, axis=0)613 #sum begin status614 metric_sum = np.sum(metric_sum, axis=2)615 return metric_sum616upb_final = eom_status_sum(metric)617upb_final.shape618#target619scenario output 620 Status 8 = CO621 Status 12 + Curtail = PO622 623#month loop. 624#find total month end values625bom_principal*roll rates = upb_trans626upb_trans - contractualprincipalpayment = upb_final627loop output628 Status 8 CO629 Status 12 PO630#goal to minimize variance 631 abs(co_output-co_goal)632 abs(po_output-po_goal)633 634pd.DataFrame(metric_sum[4])635pd.DataFrame(metric_sum[1])636metric637eom_balance = np.sum(download_model.cf_scenarios['Base Case'][1]._cf_data['TotalPrincipalBalance'], axis=0)638eom_balance[4]639################################################################################640## new model test641galileo_test = cf_main.CashFlowModel.new_model('Galileo Test', [193], [], 4, 'solar')642galileo_test.download_model_template()643galileo_refresh = cf_main.CashFlowModel.refresh_model('202010 - Galileo 1 Refresh', 13, scenario_list=['Base Case'])644galileo_refresh.run_cash_flows()645galileo_refresh.eval.create_plot('ChargeOffAmount')646#Scenario with Mosaic Default curve647galileo_refresh.copy_curves('Mosaic Defaults', 'Galileo 1 - Default')648galileo_refresh.import_rate_curves_sql('Mosaic Defaults', model_id=11, scenario_name='Base Case', curve_type='default')649galileo_refresh.create_cf_scenario('Mosaic Defaults', cutoff_date='max', curve_group='Mosaic Defaults', model_config='Solar Asset Class')650#scenario with +50% default Stress651stress = {652 'default': [(0, 0.50), (12, 0.50), (24, 0.0)]653 }654galileo_refresh.create_cf_scenario('Default Stress +50%', cutoff_date='max', curve_group='Galileo 1 - Default', curve_stress=stress, model_config='Solar Asset Class')655galileo_refresh.run_cash_flows()656galileo_refresh.eval.create_plot('ChargeOffAmount', end_period=120)657g1_refresh = cf_main.CashFlowModel.new_model('202010 - Galileo 1 Refresh', [193], [], 3, 'solar')658g1_refresh.import_data_tape_sql()659g1_refresh.download_model_template()660g1_refresh.download_cf_scenario(13, scenario_list=['Base Case'])661g1_refresh.create_cf_scenario('Base Case', cutoff_date='max', curve_group='Galileo 1 - Default', model_config='Solar Asset Class')662g1_refresh.run_cash_flows()663g1_refresh.create_curve_group('mosaic defaults')664g1_refresh.copy_curves('mosaic defaults', 'Galileo 1 - Default')665g1_refresh.import_rate_curves_sql('mosaic defaults', model_id=8, scenario_name='Base Case', curve_type='default')666g1_refresh.rate_curve_groups['mosaic defaults'].curve_type_info667g1_refresh.create_cf_scenario('Mosaic Defaults', cutoff_date='max', curve_group='mosaic defaults', model_config='Solar Asset Class')668g1_refresh.run_cash_flows()669g1_refresh.cf_scenarios.keys()670g1_refresh.eval.create_plot('PrincipalFullPrepayment')671np.zeros672#import curves manually673#create curve object674cf_model.create_curve_group('Solar Asset Class - 201909')675#file_path = r"\\SRV-NWUS-SHR\BA$\Credit Strategy\4. RUW\2. Deliverables\2019\201908 - Mosaic\Model\Mosaic RUW 201908 V11.xlsm"676file_path = r"\\SRV-NWUS-SHR\BA$\Credit Strategy\4. RUW\2. Deliverables\2019\201909 - Galileo 1\Model\Galileo 1 Solar RUW 201909 V5 (CPR Adj).xlsm"677cf_model.import_rate_curves_excel('Solar Asset Class', 'default', 'base', file_path, 'MDR', ws_range='C3:NF363', key_cols=['Key'])678cf_model.create_segment(use_gui=False, curve_group_name='Solar Asset Class', segment_type='default', OriginationTerm=[], OriginationCreditScore=[700,750,800]) 679cf_model.import_rate_curves_excel('Solar Asset Class', 'prepay', 'base', file_path, 'MPR', ws_range='C3:NF363', key_cols=['Key'])680cf_model.import_rate_curves_excel('Solar Asset Class', 'prepay', 'adjust', file_path, 'MPR', ws_range='ABQ3:APT363', key_cols=['Key'])681cf_model.create_segment(use_gui=False, curve_group_name='Solar Asset Class', segment_type='prepay', OriginationCreditScore=[700,750,800]) 682cf_model.import_rate_curves_excel('Solar Asset Class', 'curtail', 'base', file_path, 'MCR', ws_range='C3:NF363', key_cols=['Key'])683cf_model.import_rate_curves_excel('Solar Asset Class', 'curtail', 'adjust', file_path, 'MCR', ws_range='ABQ3:APT363', key_cols=['Key'])684cf_model.create_segment(use_gui=False, curve_group_name='Solar Asset Class', segment_type='curtail', OriginationTerm=[], OriginationCreditScore=[700,750,800], OriginationMonth=[]) 685#download curve test686cf_model.create_curve_group('Download Test')687cf_model.import_rate_curves_sql('Download Test', 1, 'Base Case')688#manually map any missing689cf_model.map_curves(curve_group_name='Solar Asset Class', manual_map=manual_map)690cf_model.map_curves(curve_group_name='Download Test', manual_map=manual_map)691#manually map any missing curves692cf_model.map_curves(use_gui=True)693#generate model694config={}695config['amort_formula'] = {}696config['amort_timing'] = {}697config['amort_timing']['promo'] = "['MonthsToAcquisition'] == 0" #(['MonthsOnBook'] < 18) & (['ProjectionMonth']==1)698#config['amort_formula']['promo'] = "np.pmt(['rate'],['OriginationTerm']-['PromoEndMOB'], ['OriginationBalance']-['PromoTargetBalance']))))" #"np.pmt(['rate'],['OriginationTerm'], (-['BOM_PrincipalBalance']*(1+['rate'])+np.pv(['rate'], ['PromoEndMOB'], 0, (['OriginationBalance']-['PromoTargetBalance']))))"699#config['amort_formula']['promo'] = "np.pmt(['rate'],['RemainingTerm']-['PromoTerm'], ['BOM_PrincipalBalance']-(['OriginationBalance']-['PromoTargetBalance']))"700#config['amort_formula']['promo'] = "np.pmt(['InterestRate'], ['OriginationTerm']-['PromoTerm'], ['BOM_PrincipalBalance']-(['OriginationBalance']-['PromoTargetBalance']))"701config['amort_formula']['promo'] = "np.pmt(['InterestRate'], ['OriginationTerm']-['PromoTerm'], ['PromoTargetBalance'])"702config['amort_timing']['promo end'] = "['MonthsOnBook'] == ['PromoTerm']"703config['amort_formula']['promo end'] = ''704config['default_amort_type'] = 'scale'705cf_model.create_model_config('Solar Asset Class', 1, config)706stress = {'default': [(0, 0.10), (12, 0.10), (24, 0)],707 'prepay': [(0, -0.25), (12, -0.25), (24, 0)],708 'curtail': [(0, -0.25), (12, -0.25), (24, 0)]709 }710stress_test = cf_model.create_curve_stress(stress)711stress_array = stress_test.return_stress_array(['curtail'], 301)712stress_array['curtail'][np.newaxis, :]713cf_model.cf_scenarios['Base Case'][1]._cf_modules['rate_curves'].cf_model_data['rate_arrays']['rollrate'].shape714cf_model.cf_scenarios['Base Case'][1]._cf_modules['rate_curves'].cf_model_data['cur_month_rates']['curtail']715cf_model.cf_scenarios['Base Case'][1]._cf_modules['payments'].cf_model_data.keys()716cf_model.cf_scenarios['Base Case'][1]._cf_modules['payments'].cf_model_data['ScheduledPaymentCalc'][500]717cf_model.cf_scenarios['Base Case'][1]._cf_modules['payments'].cf_model_data['ScheduledPaymentAmount'][500]718cf_model.cf_scenarios['Base Case'][1].cf_input_data['ScheduledPaymentAmount'][500]719cf_model.cf_scenarios['Base Case'][1]._cf_modules['payments'].cf_model_data['amort_rule_used'][500]720cf_model.cf_scenarios['Base Case'][1]._cf_modules['payments'].amort_timing721cf_model.cf_scenarios['Base Case'][1]._cf_modules['payments'].cf_input_data['ProjectionMonth']722cf_model.cf_scenarios['Base Case'][1]._cf_data['PrincipalPartialPrepayment'][0][1]723cf_model.cf_scenarios['Base Case'][1]._model_config.keys()724cf_model.cf_scenarios['Base Case'][1]._cf_modules['time'].cf_model_data['MonthsOnBook'][500]725cf_model.data_prep.model_configs['Solar Asset Class'].config_dict['amort_timing']726cf_model.create_cf_scenario(scenario_name='Base Case', cutoff_date='2019-09-30', curve_group='Solar Asset Class', model_config='Solar Asset Class')727cf_model.create_cf_scenario(scenario_name='Covid Stress', cutoff_date='2019-09-30', curve_group='Solar Asset Class', model_config='Solar Asset Class', curve_stress=stress)728cf_model.create_cf_scenario(scenario_name='Download Test', curve_group='Download Test', model_config=config) #cutoff_date='2019-09-30'729cf_model.run_cash_flows()730cf_model.cf_scenarios731cf_model.save_model('Base Case')732#eval output733cf_model.eval.create_plot('ChargeOffAmount')734cf_model.eval.create_table('ChargeOffAmount')735cf_model.data_prep.rate_curve_groups['Solar Asset Class'].curves[('default','base')].data_rate_curves736cf_model.data_prep.rate_curve_groups['Solar Asset Class'].__dict__.keys()737cf_model.data_prep.rate_curve_groups['Solar Asset Class'].curve_type_info 738segment_group.create_account_map()739segment_group.segment_account_map 740 741import DataPrep.DataMover as ETL742sql_engine = ETL.SQLEngine(db_name='FRA')743import sqlalchemy as sa744rows = [(2, 'curtail', 'base', 14, '10028 - Galileo Test - Base Case', 'MOB'),745 (2, 'curtail', 'adjust', 15, '10028 - Galileo Test - Base Case', 'MOB')]746cols = ['new_curve_group', 'curve_type', 'curve_sub_type', 'curve_set_key', 'curve_source', 'period_type']747pd.DataFrame(rows, columns=cols)748cf_model.cf_scenarios['Covid Stress']._cf_modules['payments']._cf_input_fields749cf_model.cf_scenarios['Base Case']._cf_modules['payments'].cf_model_data['ScheduledPaymentCalc'][400]750cf_model.cf_scenarios['Base Case']._cf_modules['payments'].cf_model_data['ScheduledPaymentAmount'][400]751cf_model.cf_scenarios['Base Case']._cf_modules['payments'].cf_model_data['TotalPaymentMade'][400]752cf_model.cf_scenarios['Base Case']._cf_modules['payments'].cf_model_data['sch_pmt_trans'][400]753pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_modules['balance'].cf_model_data['upb_trans_agg'][0])754cf_model.cf_scenarios['Base Case']._model_config.keys()755cf_model.cf_scenarios['Base Case']._cf_data.keys()756pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['ScheduledPaymentCalc'][400])757pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['ScheduledPaymentAmount'][400])758cf_model.cf_scenarios['Base Case']._cf_data['TotalPaymentMade'][400,2]759pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['sch_pmt_trans'][400,1])760pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['amort_rule_used'][400])761pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['rate'][400])762pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['upb_trans_agg'][400,2])763cf_model.cf_scenarios['Base Case']._cf_data['sch_pmt_trans']764pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['BOM_PrincipalBalance'][400,0])765cf_model.cf_scenarios['Base Case']._cf_data['MonthsToAcquisition'][400]766cf_model.cf_scenarios['Base Case'].cf_input_data['ScheduledPaymentAmount'][400]767cf_model.cf_scenarios['Base Case'].cf_input_data['OriginationBalance'][400]768cf_model.cf_scenarios['Base Case'].cf_input_data['PromoTargetBalance'][400]769cf_model.cf_scenarios['Base Case'].cf_input_data['OriginationTerm'][400]770cf_model.cf_scenarios['Base Case'].cf_input_data['RemainingTerm'][400]771cf_model.cf_scenarios['Base Case'].cf_input_data['InterestRate'][400]772cf_model.cf_scenarios['Base Case']._cf_data['MonthsOnBook'][:,0]773cf_model.data_prep.prior_uw_projections.head()774cf_model.eval.cf_output.index.names775cf_model.eval.comb_index_names776cf_model.save_model()777json.dumps(cf_model.model_config)778#aggregate results779cf_model.data_prep.data_tape.raw_tape.columns780cf_model.cf_scenarios['Base Case']._cf_modules['payments'].amort_formula781cf_model.cf_scenarios['Base Case']._cf_modules['payments'].amort_formula782np.where(cf_model.cf_scenarios['Base Case']._cf_data['BOM_PrincipalBalance'][:,200,13]>0)783cf_model.cf_scenarios['Base Case']._cf_data['MonthsToAcquisition'][:,0]784cf_model.cf_scenarios['Base Case']._cf_data['MonthsOnBook'][:,0]785cf_model.cf_scenarios['Base Case']._cf_data['BOM_PrincipalBalance'][:,4,13]786cf_model.cf_scenarios['Base Case']._cf_data['TotalPrincipalBalance'][:,1,13]787cf_model.cf_scenarios['Base Case']._cf_data['ScheduledPaymentAmount'][0,17,:]788pd.DataFrame(np.sum(cf_model.cf_scenarios['Base Case']._cf_data['sch_pmt_trans'][:,10,:,:], axis=1))789cf_model.cf_scenarios['Base Case'][1]._cf_modules['rate_curves'].cf_model_data['rate_arrays']['curtail']790pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_modules['rate_curves'].cf_model_data['cur_month_rates']['rollrate'][0])791pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['bom_final_trans'][0]) , 200]792cf_model.cf_scenarios['Base Case']._cf_data['TotalPrincipalBalance'][987][3]793cf_model.cf_scenarios['Base Case']._cf_data['MonthsOnBook'][972][1]794cf_model.cf_scenarios['Base Case']._cf_modules['time'].cf_model_data['ProjectionMonth']795cf_model.cf_scenarios['Base Case']._cf_data['AsOfDate']796cf_model.cf_scenarios['Base Case']._cf_data['eom_upb'][972][4]797pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_modules['roll_rates'].cf_model_data['rate_arrays']['transition'][987][1])798cf_model.cf_scenarios['Base Case']._cf_modules['time'].cf_model_data['MonthsOnBook'][987]799np.arange(len(cf_model.cf_scenarios['Base Case']._cf_data['BOM_PrincipalBalance']))800pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['sch_pmt'][972])801cf_model.cf_scenarios['Base Case']._cf_data['sch_pmt_trans'][972][3][1]802cf_model.cf_scenarios['Base Case']._cf_data['upb_trans'][972][3]803cf_model.cf_scenarios['Base Case']._cf_data['upb_trans_agg'][972][3]804cf_model.cf_scenarios['Base Case']._cf_data['int_accrue'][972][4]805pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['bom_units'][972])806cf_model.cf_scenarios['Base Case']._cf_data['pmt_made'][972][4]807cf_model.cf_scenarios['Base Case']._cf_data['curtail'][972][3]808cf_model.cf_scenarios['Base Case']._cf_data['rate'][972][2]809cf_model.cf_scenarios['Base Case']._cf_data.keys()810cf_model.cf_scenarios['Base Case']._cf_modules['payments'].amort_timing811cf_model.cf_scenarios['Base Case']._cf_modules['payments'].pmt_matrix812pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_data['amort_rule_used'][972])813cf_model.cf_scenarios['Base Case']._cf_data.keys()814cf_model.cf_scenarios['Base Case']._model_config['data_tape'].iloc[987]815cf_model.cf_scenarios['Base Case'].cf_input_data['MonthsOnBook'][987]816cf_model.cf_scenarios['Base Case']._cf_modules['time'].cf_model_data['MonthsOnBook'][987]817cf_model.cf_scenarios['Base Case']._cf_modules['time'].cf_model_data['month_to_acq'][987]818rule_df = cf_model.data_prep.segment_rules_combined819cf_model.data_prep.segment_input820import numpy as np821np.where(cf_model.cf_scenarios['Base Case'].cf_input_data['MonthsOnBook']<0)822min(cf_model.cf_scenarios['Base Case'].cf_input_data['MonthsOnBook'])<0823cf_model.cf_scenarios['Base Case']._model_config['rate_curves']824pd.DataFrame(cf_model.cf_scenarios['Base Case']._cf_modules['roll_rates'].cf_model_data['rate_arrays']['transition'][972,-1,:,:])825cf_model.cf_scenarios['Base Case']._cf_modules['roll_rates'].cf_model_data['rate_arrays']['transition'][:,-1,:,:]826test_range = list(range(0,2+2))827#cheat for now828manual_map = {829 'default': {'120|700-750': '120|700-750',830 '120|750-800': '120|750-800',831 '120|<700': '120|<700',832 '180|700-750': '180|700-750',833 '180|750-800': '180|750-800',834 '180|<700': '180|<700',835 '240|700-750': '240|700-750',836 '240|750-800': '240|750-800',837 '240|<700': '240|<700',838 '300|700-750': '300|700-750',839 '300|750-800': '300|750-800',840 '300|<700': '300|<700',841 '120|>800': '120|800-850',842 '144|>800': '144|800-850',843 '180|>800': '180|800-850',844 '240|>800': '240|800-850',845 '300|>800': '300|800-850'},846 'prepay': {'700-750': '700-750',847 '750-800': '750-800',848 '<700': '<700',849 '>800': '800-850'},850 'curtail': {'120|700-750|1': '120|700-750|1',851 '120|700-750|10': '120|700-750|10',852 '120|700-750|11': '120|700-750|11',853 '120|700-750|12': '120|700-750|12',854 '120|700-750|2': '120|700-750|2',855 '120|700-750|3': '120|700-750|3',856 '120|700-750|4': '120|700-750|4',857 '120|700-750|5': '120|700-750|5',858 '120|700-750|6': '120|700-750|6',859 '120|700-750|7': '120|700-750|7',860 '120|700-750|8': '120|700-750|8',861 '120|700-750|9': '120|700-750|9',862 '120|750-800|1': '120|750-800|1',863 '120|750-800|10': '120|750-800|10',864 '120|750-800|11': '120|750-800|11',865 '120|750-800|12': '120|750-800|12',866 '120|750-800|4': '120|750-800|4',867 '120|750-800|5': '120|750-800|5',868 '120|750-800|6': '120|750-800|6',869 '120|750-800|7': '120|750-800|7',870 '120|750-800|8': '120|750-800|8',871 '120|750-800|9': '120|750-800|9',872 '120|<700|1': '120|<700|1',873 '120|<700|10': '120|<700|10',874 '120|<700|11': '120|<700|11',875 '120|<700|12': '120|<700|12',876 '120|<700|2': '120|<700|2',877 '120|<700|3': '120|<700|3',878 '120|<700|4': '120|<700|4',879 '120|<700|5': '120|<700|5',880 '120|<700|6': '120|<700|6',881 '120|<700|7': '120|<700|7',882 '120|<700|8': '120|<700|8',883 '120|<700|9': '120|<700|9',884 '180|700-750|1': '180|700-750|1',885 '180|700-750|10': '180|700-750|10',886 '180|700-750|11': '180|700-750|11',887 '180|700-750|12': '180|700-750|12',888 '180|700-750|2': '180|700-750|2',889 '180|700-750|3': '180|700-750|3',890 '180|700-750|4': '180|700-750|4',891 '180|700-750|5': '180|700-750|5',892 '180|700-750|6': '180|700-750|6',893 '180|700-750|7': '180|700-750|7',894 '180|700-750|8': '180|700-750|8',895 '180|700-750|9': '180|700-750|9',896 '180|750-800|1': '180|750-800|1',897 '180|750-800|10': '180|750-800|10',898 '180|750-800|11': '180|750-800|11',899 '180|750-800|12': '180|750-800|12',900 '180|750-800|4': '180|750-800|4',901 '180|750-800|5': '180|750-800|5',902 '180|750-800|6': '180|750-800|6',903 '180|750-800|7': '180|750-800|7',904 '180|750-800|8': '180|750-800|8',905 '180|750-800|9': '180|750-800|9',906 '180|<700|1': '180|<700|1',907 '180|<700|10': '180|<700|10',908 '180|<700|11': '180|<700|11',909 '180|<700|12': '180|<700|12',910 '180|<700|2': '180|<700|2',911 '180|<700|3': '180|<700|3',912 '180|<700|4': '180|<700|4',913 '180|<700|5': '180|<700|5',914 '180|<700|6': '180|<700|6',915 '180|<700|7': '180|<700|7',916 '180|<700|8': '180|<700|8',917 '180|<700|9': '180|<700|9',918 '240|700-750|1': '240|700-750|1',919 '240|700-750|10': '240|700-750|10',920 '240|700-750|11': '240|700-750|11',921 '240|700-750|12': '240|700-750|12',922 '240|700-750|2': '240|700-750|2',923 '240|700-750|3': '240|700-750|3',924 '240|700-750|4': '240|700-750|4',925 '240|700-750|5': '240|700-750|5',926 '240|700-750|6': '240|700-750|6',927 '240|700-750|7': '240|700-750|7',928 '240|700-750|8': '240|700-750|8',929 '240|700-750|9': '240|700-750|9',930 '240|750-800|1': '240|750-800|1',931 '240|750-800|10': '240|750-800|10',932 '240|750-800|11': '240|750-800|11',933 '240|750-800|12': '240|750-800|12',934 '240|750-800|4': '240|750-800|4',935 '240|750-800|5': '240|750-800|5',936 '240|750-800|6': '240|750-800|6',937 '240|750-800|7': '240|750-800|7',938 '240|750-800|8': '240|750-800|8',939 '240|750-800|9': '240|750-800|9',940 '240|<700|1': '240|<700|1',941 '240|<700|10': '240|<700|10',942 '240|<700|11': '240|<700|11',943 '240|<700|12': '240|<700|12',944 '240|<700|2': '240|<700|2',945 '240|<700|3': '240|<700|3',946 '240|<700|4': '240|<700|4',947 '240|<700|5': '240|<700|5',948 '240|<700|6': '240|<700|6',949 '240|<700|7': '240|<700|7',950 '240|<700|8': '240|<700|8',951 '240|<700|9': '240|<700|9',952 '300|700-750|1': '300|700-750|1',953 '300|700-750|10': '300|700-750|10',954 '300|700-750|11': '300|700-750|11',955 '300|700-750|12': '300|700-750|12',956 '300|700-750|2': '300|700-750|2',957 '300|700-750|3': '300|700-750|3',958 '300|700-750|4': '300|700-750|4',959 '300|700-750|5': '300|700-750|5',960 '300|700-750|6': '300|700-750|6',961 '300|700-750|7': '300|700-750|7',962 '300|700-750|8': '300|700-750|8',963 '300|700-750|9': '300|700-750|9',964 '300|750-800|1': '300|750-800|1',965 '300|750-800|10': '300|750-800|10',966 '300|750-800|11': '300|750-800|11',967 '300|750-800|12': '300|750-800|12',968 '300|750-800|2': '300|750-800|2',969 '300|750-800|3': '300|750-800|3',970 '300|750-800|4': '300|750-800|4',971 '300|750-800|5': '300|750-800|5',972 '300|750-800|6': '300|750-800|6',973 '300|750-800|7': '300|750-800|7',974 '300|750-800|8': '300|750-800|8',975 '300|750-800|9': '300|750-800|9',976 '300|<700|1': '300|<700|1',977 '300|<700|10': '300|<700|10',978 '300|<700|11': '300|<700|11',979 '300|<700|12': '300|<700|12',980 '300|<700|2': '300|<700|2',981 '300|<700|3': '300|<700|3',982 '300|<700|4': '300|<700|4',983 '300|<700|5': '300|<700|5',984 '300|<700|6': '300|<700|6',985 '300|<700|7': '300|<700|7',986 '300|<700|8': '300|<700|8',987 '300|<700|9': '300|<700|9',988 '120|>800|1': '120|800-850|1',989 '120|>800|10': '120|800-850|10',990 '120|>800|11': '120|800-850|11',991 '120|>800|12': '120|800-850|12',992 '120|>800|2': '120|800-850|2',993 '120|>800|3': '120|800-850|3',994 '120|>800|4': '120|800-850|4',995 '120|>800|5': '120|800-850|5',996 '120|>800|6': '120|800-850|6',997 '120|>800|7': '120|800-850|6',998 '120|>800|8': '120|800-850|8',999 '120|>800|9': '120|800-850|9',1000 '144|>800|1': '144|800-850|1',1001 '144|>800|10': '144|800-850|10',1002 '144|>800|11': '144|800-850|11',1003 '144|>800|12': '144|800-850|12',1004 '144|>800|2': '144|800-850|2',1005 '144|>800|3': '144|800-850|3',1006 '144|>800|4': '144|800-850|4',1007 '144|>800|5': '144|800-850|5',1008 '144|>800|6': '144|800-850|6',1009 '144|>800|7': '144|800-850|6',1010 '144|>800|8': '144|800-850|8',1011 '144|>800|9': '144|800-850|9',1012 '180|>800|1': '180|800-850|1',1013 '180|>800|10': '180|800-850|10',1014 '180|>800|11': '180|750-800|11',1015 '180|>800|12': '180|800-850|12',1016 '180|>800|2': '180|800-850|2',1017 '180|>800|3': '180|800-850|3',1018 '180|>800|4': '180|800-850|4',1019 '180|>800|5': '180|800-850|5',1020 '180|>800|6': '180|800-850|6',1021 '180|>800|7': '180|800-850|7',1022 '180|>800|8': '180|800-850|8',1023 '180|>800|9': '180|800-850|9',1024 '240|>800|1': '240|800-850|1',1025 '240|>800|10': '240|800-850|10',1026 '240|>800|11': '240|800-850|11',1027 '240|>800|12': '240|800-850|12',1028 '240|>800|2': '240|800-850|2',1029 '240|>800|3': '240|800-850|3',1030 '240|>800|4': '240|800-850|4',1031 '240|>800|5': '240|800-850|5',1032 '240|>800|6': '240|800-850|6',1033 '240|>800|7': '240|800-850|7',1034 '240|>800|8': '240|800-850|8',1035 '240|>800|9': '240|800-850|9',1036 '300|>800|1': '300|800-850|1',1037 '300|>800|10': '300|800-850|10',1038 '300|>800|11': '300|800-850|11',1039 '300|>800|12': '300|800-850|12',1040 '300|>800|4': '300|800-850|4',1041 '300|>800|5': '300|800-850|5',1042 '300|>800|6': '300|800-850|6',1043 '300|>800|7': '300|800-850|7',1044 '300|>800|8': '300|800-850|8',1045 '300|>800|9': '300|800-850|9'},1046 'recovery': {},...
setup.py
Source:setup.py
...27])28clone_github_repo("MSFTserver/pytorch3d-lite.git")29add_to_path('./pytorch3d-lite')30pathlib.Path(DefaultPaths.model_path).mkdir(parents=True, exist_ok=True)31def download_model(url, file_name = None):32 out_dir = DefaultPaths.model_path33 if file_name is None:34 file_name = url.split("/")[-1]35 if path_exists(f"{out_dir}/{file_name}"):36 print(f"{file_name} already exists")37 else: 38 print(f"Downloading {url}")39 cmd(f'curl -L --progress-bar -o {out_dir}/{file_name} {url}')40download_model("https://the-eye.eu/public/AI/models/512x512_diffusion_unconditional_ImageNet/512x512_diffusion_uncond_finetune_008100.pt")41download_model("https://the-eye.eu/public/AI/models/v-diffusion/secondary_model_imagenet_2.pth")42download_model("https://cloudflare-ipfs.com/ipfs/Qmd2mMnDLWePKmgfS8m6ntAg4nhV5VkUyAydYBp8cWWeB7/AdaBins_nyu.pt")43 44# ImageNet 1638445download_model("https://heibox.uni-heidelberg.de/d/a7530b09fed84f80a887/files/?p=%2Fconfigs%2Fmodel.yaml&dl=1", "vqgan_imagenet_f16_16384.yaml");46download_model("https://heibox.uni-heidelberg.de/d/a7530b09fed84f80a887/files/?p=%2Fconfigs%2Flast.ckpt&dl=1", "vqgan_imagenet_f16_16384.ckpt");47download_model("https://dall-3.com/models/glid-3-xl/diffusion.pt");48download_model("https://dall-3.com/models/glid-3-xl/finetune.pt");49download_model("https://dall-3.com/models/glid-3-xl/bert.pt");50download_model("https://dall-3.com/models/glid-3-xl/kl-f8.pt");51clone_github_repo("CompVis/taming-transformers.git")52clone_github_repo("openai/CLIP.git")53clone_github_repo("crowsonkb/guided-diffusion.git")54clone_github_repo("assafshocher/ResizeRight.git")55clone_github_repo("isl-org/MiDaS.git")56if not path_exists(f'{DefaultPaths.root_path}/MiDaS/midas_utils.py'):57 os.rename("MiDaS/utils.py", "MiDaS/midas_utils.py")58clone_github_repo("CompVis/latent-diffusion.git")59clone_github_repo("shariqfarooq123/AdaBins.git")60clone_github_repo("alembics/disco-diffusion.git")61clone_github_repo("Jack000/glid-3-xl")62if not path_exists(f'{DefaultPaths.root_path}/glid-3-xl/jack_guided_diffusion'):63 os.rename('glid-3-xl/guided_diffusion', 'glid-3-xl/jack_guided_diffusion')64if not path_exists(f'{DefaultPaths.root_path}/disco_xform_utils.py'):...
__main__.py
Source:__main__.py
1import os2import requests3from tqdm import tqdm4def download_model(url: str) -> None:5 filename = url.split('/')[-1]6 r = requests.get(url, stream=True)7 with open(os.path.join(os.path.dirname(__file__), filename), 'wb') as f:8 with tqdm(unit='B', unit_scale=True, unit_divisor=1024, miniters=1, desc=filename, total=int(r.headers.get('content-length', 0))) as pbar:9 for chunk in r.iter_content(chunk_size=4096):10 f.write(chunk)11 pbar.update(len(chunk))12if __name__ == '__main__':13 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/001_classicalSR_DF2K_s64w8_SwinIR-M_x2.pth')14 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/001_classicalSR_DF2K_s64w8_SwinIR-M_x3.pth')15 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/001_classicalSR_DF2K_s64w8_SwinIR-M_x4.pth')16 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/001_classicalSR_DF2K_s64w8_SwinIR-M_x8.pth')17 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/002_lightweightSR_DIV2K_s64w8_SwinIR-S_x2.pth')18 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/002_lightweightSR_DIV2K_s64w8_SwinIR-S_x3.pth')19 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/002_lightweightSR_DIV2K_s64w8_SwinIR-S_x4.pth')20 download_model('https://github.com/HolyWu/vs-swinir/releases/download/model/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!