import pandas as pd import numpy as np import hazard pd.set_option('display.max_columns', 13) hz_static_data = pd.read_csv('static.csv', thousands=',') hz = hazard.Hazard(hz_static_data, prepay_col="prepay", end_col="period_end", beg_col="period_begin", end_max=60, cov_cols=["cpn_gap", "summer"]) #hz.fit_parameters_brute() hz.fit_parameters_grad() #hz.baseline_hazard() hz.parameters_hessian() hz.parameters_se() #Part d ##Dynamic covariates hz_dynamic_data = pd.read_csv('dynamic.csv', thousands=',') hz_dynamic = hazard.Hazard(hz_static_data, prepay_col="prepay", end_col="period_end", beg_col="period_begin", end_max=60, cov_cols=["cpn_gap", "summer"]) hz_dynamic.param_estimate_dynamic()
pools_info, classes_info, principal_sequential_pay, accruals_sequential_pay, simulated_rates_A, tables_file, show_prints=True, show_plots=False) # Static Hazard Model and consequent REMIC bonds results hz_static_data = pd.read_csv('./Given_Files/static.csv', thousands=',') hz = hazard.Hazard(hz_static_data, prepay_col="prepay", end_col="period_end", beg_col="", end_max=60, cov_cols=["cpn_gap", "summer"], tables_file=tables_file, show_prints=True, show_plots=False) hz.fit_parameters_grad() hz.parameters_se() hw_remic.simulation_result(hz, simulated_lagged_10_year_rates_A, 'B', 'C', 'Static Data') # Dynamic Hazard Model and consequent REMIC bonds results hz_dynamic_data = pd.read_csv('./Given_Files/dynamic.csv', thousands=',') hz_dynamic = hazard.Hazard(hz_dynamic_data, prepay_col="prepay", end_col="period_end", beg_col="period_begin",
def play(): "returns true if the game should quit, false if another game should be played" def get_status_string(players): parts = [ str.format('{0.name: >8}: {0.score: <4}', i) for i in players ] if winner is not None: parts += ['Winner: ' + winner.name] elif paused: parts += ['***PAUSED***'] return string.join(parts, ' ') # set up objects on the game board game_area = pygame.Surface(config.size) paused = False winner = None players = [] keys_up = {} keys_down = {} hazards = pygame.sprite.Group() paddles = pygame.sprite.Group() collideables = pygame.sprite.Group() score_zones = pygame.sprite.Group() balls = pygame.sprite.Group() for i in hazard.Hazard.ALL: hazards.add(hazard.Hazard(config, i)) for i in config.hazard['custom']: hazards.add(hazard.Hazard(config, **i)) for i in config.PLAYER_ALL: players.append( player.Player(config, i, paddles, score_zones, hazards, balls, paddle_type=config.paddle['paddle_type'][i])) for i in players: try: keys_down[i.paddle.key_pos] = i.paddle.move_pos keys_down[i.paddle.key_neg] = i.paddle.move_neg keys_up[i.paddle.key_pos] = i.paddle.move_stop keys_up[i.paddle.key_neg] = i.paddle.move_stop except AttributeError: pass collideables.add(hazards) collideables.add(paddles) for i in xrange(config.ball['num']): balls.add(ball.Ball(config, collideables, score_zones)) for i in collideables: i.balls = balls # run the game while True: ticks = pygame.time.get_ticks() for event in pygame.event.get(): if event.type == pygame.QUIT: return True elif event.type == pygame.KEYDOWN: try: keys_down[event.key]() except KeyError: pass if event.key == pygame.K_PAUSE or (event.key == pygame.K_p and event.mod & pygame.KMOD_CTRL): paused = not paused elif event.key == pygame.K_n and event.mod & pygame.KMOD_CTRL: return False elif event.key == pygame.K_q and event.mod & pygame.KMOD_CTRL: return True elif event.key == pygame.K_o and event.mod & pygame.KMOD_CTRL: config_dialog.show() return False elif event.type == pygame.KEYUP: try: keys_up[event.key]() except KeyError: pass winner = config.get_winner(players) if not paused and winner is None: hazards.update() paddles.update() balls.update() while len(balls) < config.ball['num']: balls.add(ball.Ball(config, collideables, score_zones)) # draw everything screen.fill(config.colors['bg']) screen.fill(config.colors['border'], border_rect) game_area.fill(config.colors['bg']) balls.draw(game_area) paddles.draw(game_area) hazards.draw(game_area) screen.blit(game_area, game_area_rect) screen.blit( font.render(get_status_string(players), True, config.colors['fg']), status_rect) line_num = 0 for line in string.split(config.help_string, '\n'): screen.blit(font.render(line, True, config.colors['fg']), \ (help_rect.left, help_rect.top + line_num*font.get_linesize(), help_rect.width, help_rect.height)) line_num += 1 pygame.display.flip() pygame.time.wait( max(0, config.sleep - (pygame.time.get_ticks() - ticks)))
for obj in m.objectgroups["Objects"].get_by_type("Subghost"): sg = subghost.SubGhost( pyglet.sprite.Sprite(img=resources.subghost_frames[0], x=obj.get(u'x'), y=m_height - obj.get(u'y'))) sg.frames = resources.subghost_frames game_objects.append(sg) """ sg = subghost.SubGhost(pyglet.sprite.Sprite(img = resources.subghost_frames[0], x=400, y=200)) sg.frames = resources.subghost_frames game_objects.append(sg) """ for obj in m.objectgroups["Objects"].get_by_type("Hazard"): hz = hazard.Hazard( pyglet.sprite.Sprite(img=resources.salamander_frames[0], x=obj.get(u'x'), y=m_height - obj.get(u'y'))) hz.frames = resources.salamander_frames game_objects.append(hz) """ sg = subghost.SubGhost(pyglet.sprite.Sprite(img = resources.subghost_frames[0], x=200, y=400)) sg.frames = resources.subghost_frames game_objects.append(sg) """ #game_objects.append(subghost.SubGhost(pyglet.sprite.Sprite(img = resources.subghost_image, x=100, y=600))) #game_objects.append(speech.Speech("Hi")) sp = spirit.Spirit( pyglet.sprite.Sprite(img=resources.sprite_frames[0], x=200, y=m_height / 2))
# House price evolutions for FRM and ARM rental_flow_rate = 0.025 vol_house_prices = 0.12 hw_remic.simulate_house_prices(n_simulations, rental_flow_rate, vol_house_prices) # Hazard models optimize_hazard_models = True # True to run all hazard models optimizations. # FRM prepayment hz_frm_data = pd.read_csv('./Given_Files/FRM_perf.csv') hz_frm_prepay = hazard.Hazard(hz_frm_data, prepay_col="Prepayment_indicator", end_col="Loan_age", beg_col="period_beginning", end_max=44, cov_cols=["Spread", "spring_summer"], tables_file=tables_file, show_prints=True, show_plots=False) hz_frm_prepay.param_estimate_dynamic( optimize_flag=optimize_hazard_models, theta=[1.196813, 0.013147, -0.048916, -0.215195]) # FRM default hz_frm_default = hazard.Hazard(hz_frm_data, prepay_col="Default_indicator", end_col="Loan_age", beg_col="period_beginning", end_max=44, cov_cols=["LTV"],