@@ -374,3 +374,168 @@ def test_deriv_NDC(args, d_NDC_expected):
374
374
d_NDC = pensions .deriv_NDC (r , w , e , Y , per_rmn , p )
375
375
376
376
assert np .allclose (d_NDC , d_NDC_expected )
377
+
378
+
379
+
380
+
381
+
382
+ ################pension benefit: DB############
383
+ demographics_ndc = deepcopy (demographics )
384
+ households_pb = deepcopy (households )
385
+ pensions_db = deepcopy (pensions_class )
386
+ pensions_db .pension_system = 'DB'
387
+ households_pb .S = 7
388
+ households_pb .S_ret = 4
389
+ w_db = np .array ([1.2 , 1.1 , 1.21 , 1.0 , 1.01 , 0.99 , 0.8 ])
390
+ e_db = np .array ([1.1 , 1.11 , 0.9 , 0.87 , 0.87 , 0.7 , 0.6 ])
391
+ n_db = np .array ([0.4 , 0.45 , 0.4 , 0.42 , 0.3 , 0.2 , 0.2 ])
392
+ pensions_db .last_career_yrs = 3
393
+ pensions_db .yr_contr = S_ret
394
+ pensions_db .rep_rate_py = 0.2
395
+ Y = None
396
+ j_ind = 1
397
+ firms .g_y = 0.03
398
+ factor = 2
399
+ omegas = None
400
+ lambdas = 1
401
+ pension_expected_db = [0 , 0 , 0 , 0 , 0.337864778 , 0.327879365 , 0.318189065 ]
402
+ classes_pb = (demographics_ndc , households_pb , firms , pensions_db )
403
+ args_pb = (w_db , e_db , n_db , r , Y , lambdas , j_ind , factor )
404
+
405
+ ################pension benefit: NDC############
406
+ households_ndc = deepcopy (households )
407
+ pensions_ndc = deepcopy (pensions_class )
408
+ pensions_ndc .pension_system = 'NDC'
409
+ pensions_ndc .ndc_growth_rate = 'LR GDP'
410
+ pensions_ndc .dir_growth_rate = 'r'
411
+ households_ndc .S = 4
412
+ households_ndc .S_ret = 2
413
+ w_ndc = np .array ([1.2 , 1.1 , 1.21 , 1 ])
414
+ e_ndc = np .array ([1.1 , 1.11 , 0.9 , 0.87 ])
415
+ n_ndc = np .array ([0.4 , 0.45 , 0.4 , 0.3 ])
416
+ Y = None
417
+ j_ind = 1
418
+ firms .g_y = 0.03
419
+ demographics_ndc .g_n_SS = 0.0
420
+ r = 0.03
421
+ factor = 2
422
+ pensions_ndc .tau_p = 0.3
423
+ pensions_ndc .k_ret = 0.4615
424
+ demographics_ndc .mort_rates_SS = np .array ([0.01 , 0.05 , 0.3 , 0.4 , 1 ])
425
+ omegas = None
426
+ lambdas = 1
427
+ pension_expected_ndc = [0 , 0 , 0.279756794 , 0.271488732 ]
428
+ classes_ndc = (demographics_ndc , households_ndc , firms , pensions_ndc )
429
+ args_ndc = (w_ndc , e_ndc , n_ndc , r , Y , lambdas , j_ind , factor )
430
+
431
+ ################pension benefit: PS############
432
+ demographics_ppb = deepcopy (demographics )
433
+ households_ppb = deepcopy (households )
434
+ pensions_ppb = deepcopy (pensions_class )
435
+ pensions_ppb .pension_system = 'PS'
436
+ households_ppb .S = 7
437
+ households_ppb .S_ret = 4
438
+ w_ppb = np .array ([1.2 , 1.1 , 1.21 , 1.0 , 1.01 , 0.99 , 0.8 ])
439
+ e_ppb = np .array ([1.1 , 1.11 , 0.9 , 0.87 , 0.87 , 0.7 , 0.6 ])
440
+ n_ppb = np .array ([0.4 , 0.45 , 0.4 , 0.42 , 0.3 , 0.2 , 0.2 ])
441
+ omegas = (1 / households_ppb .S ) * np .ones (households_ppb .S )
442
+ demographics_ppb .omega_SS = omegas
443
+ pensions_ppb .vpoint = 0.4
444
+ factor = 2
445
+ Y = None
446
+ lambdas = 1
447
+ j_ind = 1
448
+ firms .g_y = 0.03
449
+ pension_expected_ppb = [0 , 0 , 0 , 0 , 0.004164689 , 0.004041603 , 0.003922156 ]
450
+ classes_ppb = (demographics_ppb , households_ppb , firms , pensions_ppb )
451
+ args_ppb = (w_db , e_db , n_db , r , Y , lambdas , j_ind , factor )
452
+
453
+ test_data = [(classes_pb , args_pb , pension_expected_db ),
454
+ (classes_ndc , args_ndc , pension_expected_ndc ),
455
+ (classes_ppb , args_ppb , pension_expected_ppb )]
456
+
457
+ @pytest .mark .parametrize ('classes,args,pension_expected' , test_data ,
458
+ ids = ['DB' , 'NDC' , 'PS' ])
459
+ def test_pension_benefit (classes , args , pension_expected ):
460
+ '''
461
+ Test of pensions.get_pension_benefit
462
+ '''
463
+
464
+ demographics_ndc , households , firms , pensions = classes
465
+ w , e , n , r , Y , lambdas , j_ind , factor = args
466
+
467
+ pension = pensions .pension_benefit (
468
+ demographics_ndc , households , firms , w , e , n , r ,
469
+ Y , lambdas , j_ind , factor )
470
+ assert (np .allclose (pension , pension_expected ))
471
+ ############SS or complete lifetimes############
472
+ households_pl1 = deepcopy (households )
473
+ pensions_pl1 = deepcopy (pensions_class )
474
+ households_pl1 .S = 3
475
+ households_pl1 .S_ret = 2
476
+ per_rmn = households_pl1 .S
477
+ w = np .array ([1.2 , 1.1 , 1.21 ])
478
+ e = np .array ([1.1 , 1.11 , 0.9 ])
479
+ firms .g_y = 0.03
480
+ demographics .g_n_SS = 0.0
481
+ pensions_pl1 .ndc_growth_rate = 'LR GDP'
482
+ pensions_pl1 .dir_growth_rate = 'r'
483
+ r = 0.02
484
+ pensions_pl1 .tau_p = 0.3
485
+ pensions_pl1 .k_ret = 0.4615
486
+ pensions_pl1 .delta_ret = 1.857010214
487
+ pensions_pl1 .g_ndc = firms .g_y + demographics .g_n_SS
488
+ demographics .mort_rates_SS = np .array ([0.1 , 0.2 , 0.4 , 1.0 ])
489
+ deriv_NDC_loop_expected1 = np .array ([0.757437326 , 0.680222841 , 0.0 ])
490
+ d_theta_empty = np .zeros_like (w )
491
+
492
+ #args3 = (pensions_pl1, households_pl1, w, e, per_rmn)
493
+ args3 = (w , e , per_rmn , households_pl1 .S , households_pl1 .S_ret , firms .g_y ,
494
+ pensions_pl1 .tau_p , pensions_pl1 .g_ndc , pensions_pl1 .delta_ret ,
495
+ d_theta_empty )
496
+
497
+ ################Incomplete lifetimes#################
498
+ households_pl2 = deepcopy (households )
499
+ pensions_pl2 = deepcopy (pensions_class )
500
+ households_pl2 .S = 4
501
+ households_pl2 .S_ret = 2
502
+ per_rmn = 3
503
+ #w = np.array([1.2, 1.1, 1.21, 1.25])
504
+ #e = np.array([1.1, 1.11, 0.9, 1.0])
505
+ w = np .array ([1.1 , 1.21 , 1.25 ])
506
+ e = np .array ([1.11 , 0.9 , 1.0 ])
507
+ firms .g_y = 0.04
508
+ demographics .g_n_SS = 0.0
509
+ pensions_pl2 .ndc_growth_rate = 'LR GDP'
510
+ pensions_pl2 .dir_growth_rate = 'r'
511
+ #r = np.array([0.05, 0.03, 0.04, 0.03])
512
+ r = np .array ([0.03 , 0.04 , 0.03 ])
513
+ pensions_pl2 .tau_p = 0.3
514
+ pensions_pl2 .k_ret = 0.4615
515
+ pensions_pl2 .delta_ret = 1.083288196
516
+ pensions_pl2 .g_ndc = firms .g_y + demographics .g_n_SS
517
+ #demographics.mort_rates_SS = np.array([0.1, 0.2, 0.4, 1.0])
518
+ demographics .mort_rates_SS = np .array ([0.2 , 0.4 , 1.0 ])
519
+ deriv_NDC_loop_expected2 = np .array ([0.396808466 , 0.0 , 0.0 ])
520
+ #d_theta_empty = np.zeros_like(w)
521
+ d_theta_empty = np .zeros (per_rmn )
522
+ args4 = (w , e , per_rmn , households_pl2 .S , households_pl2 .S_ret , firms .g_y ,
523
+ pensions_pl2 .tau_p , pensions_pl2 .g_ndc , pensions_pl2 .delta_ret ,
524
+ d_theta_empty )
525
+
526
+ test_data = [(args3 , deriv_NDC_loop_expected1 ),
527
+ (args4 , deriv_NDC_loop_expected2 )]
528
+
529
+ @pytest .mark .parametrize ('args,deriv_NDC_loop_expected' , test_data ,
530
+ ids = ['SS' , 'incomplete' ])
531
+ def test_deriv_NDC_loop (args , deriv_NDC_loop_expected ):
532
+ """
533
+ Test of the pensions.deriv_NDC_loop() function.
534
+ """
535
+ (w , e , per_rmn , households .S , households .S_ret , firms .g_y , pensions_pl2 .tau_p ,
536
+ pensions_pl2 .g_ndc , pensions_pl2 .delta_ret , d_theta_empty ) = args
537
+
538
+ deriv_NDC_loop = pensions .deriv_NDC_loop (
539
+ w , e , per_rmn , households .S , households .S_ret , firms .g_y ,
540
+ pensions_pl2 .tau_p , pensions_pl2 .g_ndc , pensions_pl2 .delta_ret ,
541
+ d_theta_empty )
0 commit comments