def add_transaction(self, type_, asset, from_id, to_id, amount, interest, maturity, time_of_default, environment): from sample_transaction import Transaction transaction = Transaction() transaction.this_transaction(type_, asset, from_id, to_id, amount, interest, maturity, time_of_default) transaction.add_transaction(environment)
def transaction__remove_transaction(self, args): import os from sample_agent import Agent from sample_config import Config from sample_transaction import Transaction text = "This test checks transaction.remove_transaction \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info('START logging for test transaction__remove_transaction in run: %s', environment_directory + identifier + ".xml") # Construct a config config = Config() agent_one = Agent("agent_one", {"test": "parameters"}, {"test": "variables"}) agent_two = Agent("agent_two", {"test": "parameters"}, {"test": "variables"}) config.agents = [] config.agents.append(agent_one) config.agents.append(agent_two) # # TESTING # print("Creating a transaction") transaction = Transaction() print("Assigning values") transaction.this_transaction("type", "asset", "agent_one", "agent_two", 1, 2, 3, 4) print("Adding the transaction to the books") transaction.add_transaction(config) print("The transaction:") print(transaction) print("Agent one:") print(config.get_agent_by_id("agent_one")) print("Agent two:") print(config.get_agent_by_id("agent_two")) print("Removing the transaction") transaction.remove_transaction() print("The transaction:") print(transaction) print("Agent one:") print(config.get_agent_by_id("agent_one")) print("Agent two:") print(config.get_agent_by_id("agent_two")) print("Removing the transaction")
def transaction__purge_accounts(self, args): import os from sample_agent import Agent from sample_config import Config from sample_transaction import Transaction text = "This test checks transaction.purge_accounts \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info( 'START logging for test transaction__purge_accounts in run: %s', environment_directory + identifier + ".xml") # Construct a config config = Config() agent_one = Agent("agent_one", {"test": "parameters"}, {"test": "variables"}) agent_two = Agent("agent_two", {"test": "parameters"}, {"test": "variables"}) config.agents = [] config.agents.append(agent_one) config.agents.append(agent_two) # # TESTING # print("Before purging the accounts") transaction = Transaction() transaction.this_transaction("type", "asset", "agent_one", "agent_two", 0, 2, 3, 4) transaction.add_transaction(config) transaction = Transaction() transaction.this_transaction("type", "asset", "agent_one", "agent_two", 1, 2, 3, 4) transaction.add_transaction(config) print(config.get_agent_by_id("agent_one")) print(config.get_agent_by_id("agent_two")) print("After clearing one bank's accounts") transaction.purge_accounts(config) print(config.get_agent_by_id("agent_one")) print(config.get_agent_by_id("agent_two"))
def transaction__write_transaction(self, args): import os from sample_agent import Agent from sample_config import Config from sample_transaction import Transaction text = "This test checks transaction.write_transaction \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info( 'START logging for test transaction__write_transaction in run: %s', environment_directory + identifier + ".xml") # Construct a config config = Config() agent_one = Agent("agent_one", {"test": "parameters"}, {"test": "variables"}) agent_two = Agent("agent_two", {"test": "parameters"}, {"test": "variables"}) config.agents = [] config.agents.append(agent_one) config.agents.append(agent_two) # # TESTING # print("Creating a transaction") transaction = Transaction() print("Assigning values") transaction.this_transaction("type", "asset", "agent_one", "agent_two", 1, 2, 3, 4) print("Adding the transaction to the books") transaction.add_transaction(config) print("Printing transaction:") print(transaction.write_transaction())
def transaction__purge_accounts(self, args): import os from sample_agent import Agent from sample_config import Config from sample_transaction import Transaction text = "This test checks transaction.purge_accounts \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info('START logging for test transaction__purge_accounts in run: %s', environment_directory + identifier + ".xml") # Construct a config config = Config() agent_one = Agent("agent_one", {"test": "parameters"}, {"test": "variables"}) agent_two = Agent("agent_two", {"test": "parameters"}, {"test": "variables"}) config.agents = [] config.agents.append(agent_one) config.agents.append(agent_two) # # TESTING # print("Before purging the accounts") transaction = Transaction() transaction.this_transaction("type", "asset", "agent_one", "agent_two", 0, 2, 3, 4) transaction.add_transaction(config) transaction = Transaction() transaction.this_transaction("type", "asset", "agent_one", "agent_two", 1, 2, 3, 4) transaction.add_transaction(config) print(config.get_agent_by_id("agent_one")) print(config.get_agent_by_id("agent_two")) print("After clearing one bank's accounts") transaction.purge_accounts(config) print(config.get_agent_by_id("agent_one")) print(config.get_agent_by_id("agent_two"))
def agent__purge_accounts(self, args): import os from sample_agent import Agent from sample_config import Config # needed for the bankDirectory text = "This test checks agent.purge_accounts \n" text = text + " Checking if after the purge_accounts the total amount \n" text = text + " of transactions in the firm stays the same. \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info('START logging for test agent__purge_accounts in run: %s', environment_directory + identifier + ".xml") # Construct firm filename config = Config() list_env = os.listdir(environment_directory) config.read_xml_config_file(environment_directory + list_env[0]) # get the firm_directory from the environment firm_directory = config.firm_directory # and loop over all firms in the directory listing = os.listdir(firm_directory) firmFilename = firm_directory + listing[0] # generate an agent agent = Agent("baseagent id", {"test": "parameters"}, {"test": "variables"}) agent.identifier = "test_agent" config.agents = [] config.agents.append(agent) agent.get_parameters_from_file(firmFilename, config) # # TESTING # account = 0.0 tranx = 0 for transaction in agent.accounts: account = account + transaction.amount tranx = tranx + 1 print(tranx) print(account) from sample_transaction import Transaction transaction = Transaction() transaction.this_transaction("deposits", "", agent.identifier, agent.identifier, 0.0, 0.09, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) # environment.households[0:1][0] is only for testing purposes DO NOT USE IN PRODUCTION # what it does is is takes the first household in environment, but if there are no # households (which happens in testing) it doesn't break down account = 0.0 tranx = 0 for transaction in agent.accounts: account = account + transaction.amount tranx = tranx + 1 print(tranx) print(account) agent.accounts[0].purge_accounts(config) account = 0.0 tranx = 0 for transaction in agent.accounts: account = account + transaction.amount tranx = tranx + 1 print(tranx) print(account)
def agent__get_account_num_transactions(self, args): import os from sample_agent import Agent from sample_config import Config # needed for the bankDirectory text = "This test checks agent.get_account_num_transactions \n" text = text + " The purpose of this method is to count the numbers of transaction for \n" text = text + " accounts firms hold. Our standard frm has 3 transactions by default. \n" text = text + " But we double count as we have only one agent, so you should see 6. \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info('START logging for test agent__get_account_num_transactions in run: %s', environment_directory + identifier + ".xml") # Construct firm filename config = Config() list_env = os.listdir(environment_directory) config.read_xml_config_file(environment_directory + list_env[0]) # get the firm_directory from the environment firm_directory = config.firm_directory # and loop over all firms in the directory listing = os.listdir(firm_directory) firmFilename = firm_directory + listing[0] # generate an agent agent = Agent("baseagent id", {"test": "parameters"}, {"test": "variables"}) agent.identifier = "test_agent" config.agents = [] config.agents.append(agent) agent.get_parameters_from_file(firmFilename, config) from sample_transaction import Transaction amount = 150.0 transaction = Transaction() transaction.this_transaction("loans", "", agent.identifier, agent.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) amount = 150.0 transaction = Transaction() transaction.this_transaction("cash", "", agent.identifier, agent.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) amount = 200.0 transaction = Transaction() transaction.this_transaction("goods", "", agent.identifier, agent.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) # # TESTING # num_transactions = 0.0 # counting all types in account together print(agent) # and checking if the number of transaction # is increasing by one for type in ["loans", "cash", "goods"]: if type == "loans": num_transactions = num_transactions + agent.get_account_num_transactions(type) print("L = " + str(num_transactions)) if type == "cash": num_transactions = num_transactions + agent.get_account_num_transactions(type) print("L+M = " + str(num_transactions)) if type == "goods": num_transactions = num_transactions + agent.get_account_num_transactions(type) print("L+M+G = " + str(num_transactions))
def agent__get_account(self, args): import os from sample_agent import Agent from sample_config import Config # needed for the bankDirectory text = "This test checks agent.get_account \n" text = text + " The purpose of this method is to establish an account for our firm which contains \n" text = text + " all kinds of assets and liabilities. The method simply adds all kinds of assets \n" text = text + " and stores them in one volume. As our firms holds 250.0 assets \n" text = text + " and 250 liabilites the total volume of our account should be 500.0 \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info('START logging for test agent__get_account in run: %s', environment_directory + identifier + ".xml") # Construct firm filename config = Config() list_env = os.listdir(environment_directory) config.read_xml_config_file(environment_directory + list_env[0]) # get the firm_directory from the environment firm_directory = config.firm_directory # and loop over all firms in the directory listing = os.listdir(firm_directory) firmFilename = firm_directory + listing[0] # generate an agent agent = Agent("baseagent id", {"test": "parameters"}, {"test": "variables"}) agent.identifier = "test_agent" config.agents = [] config.agents.append(agent) agent.get_parameters_from_file(firmFilename, config) agent_helper = Agent("helperagent id", {"test": "parameters"}, {"test": "variables"}) agent_helper.identifier = "helper_agent" config.agents.append(agent_helper) from sample_transaction import Transaction amount = 150.0 transaction = Transaction() transaction.this_transaction("loans", "", agent.identifier, agent_helper.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) amount = 100.0 transaction = Transaction() transaction.this_transaction("cash", "", agent.identifier, agent_helper.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) amount = 250.0 transaction = Transaction() transaction.this_transaction("goods", "", agent.identifier, agent_helper.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) # # TESTING # print(agent.accounts) account = 0.0 # counting all types in account together print(agent.__str__()) # and checking how much is the total # volume of the account for type in ["loans", "cash", "goods"]: if type == "loans": account = account + agent.get_account(type) print("L = " + str(account)) if type == "cash": account = account + agent.get_account(type) print("L+M = " + str(account)) if type == "goods": account = account + agent.get_account(type) print("L+M+G = " + str(account))
def agent__check_consistency(self, args): import os from sample_agent import Agent from sample_config import Config # needed for the bankDirectory text = "This test checks agent.check_consistency \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info('START logging for test agent__check_consistency in run: %s', environment_directory + identifier + ".xml") # Construct firm filename config = Config() list_env = os.listdir(environment_directory) config.read_xml_config_file(environment_directory + list_env[0]) # get the firm_directory from the environment firm_directory = config.firm_directory # and loop over all firms in the directory listing = os.listdir(firm_directory) firmFilename = firm_directory + listing[0] # generate an agent agent = Agent("baseagent id", {"test": "parameters"}, {"test": "variables"}) agent.identifier = "test_agent" config.agents = [] config.agents.append(agent) agent.get_parameters_from_file(firmFilename, config) from sample_transaction import Transaction amount = 150.0 transaction = Transaction() transaction.this_transaction("loans", "", agent.identifier, agent.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) amount = 150.0 transaction = Transaction() transaction.this_transaction("cash", "", agent.identifier, agent.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) amount = 200.0 transaction = Transaction() transaction.this_transaction("goods", "", agent.identifier, agent.identifier, amount, 0.0, 0, -1) # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION transaction.add_transaction(config) # # TESTING # print(agent.check_consistency())