Credit Network Simulation with Transaction Fees

Overview

This repository contains Python simulations for studying the dynamics of credit networks with integrated transaction fees. The goal is to understand how various factors such as edge capacities, transaction fees, graph density, and topology influence the success rate of transactions within the network.

Repository Structure

The simulations are divided across multiple files, each pertaining to different aspects of the network:

  • transaction_simulator.py: Contains core functions used across various simulations.
  • edge_capacity_variation.py: Includes functions specific to simulations that vary edge capacity and transaction fees.
  • Additional simulation modules (to be named and added): Future simulation studies will be encapsulated in their respective modules.

Modeling Transactions

In transactions_simulator.py, we have the following key functions:

  • create_random_graph: Initializes a random directed graph to represent the credit network. Each node represents an entity, and each directed edge represents a credit line with a fixed total capacity and associated fee.

  • update_graph_capacity_fees: Simulates a transaction along a path within the graph. It updates the capacities of the edges based on the transaction amount and fees, returning a boolean indicating the success or failure of the transaction.

  • simulate_transactions_fees: Simulates multiple transactions over a credit network to calculate the steady-state success rate, defined as the ratio of successful transactions to the total number attempted once the system reaches equilibrium.

Transaction Simulation Process

The transaction simulation involves randomly selecting source and sink nodes and attempting to route a fixed transaction amount through the shortest available path. The transaction is deemed successful if each edge along the path can accommodate the transaction amount plus the accrued fees from subsequent nodes. The simulation iterates over transactions in defined windows until the success rate stabilizes within a convergence threshold, signaling a steady state.

Variant Simulations

In the edge_capacity_variation.py file, we have functions like simulate_network_capacity_fee_variation and plot_results_capacity_fee_variation that run simulations and plot results for scenarios where edge capacities and transaction fees are varied.

Future Extensions

We plan to extend our simulation to include the variation of other parameters like:

  • Average node degree (graph density)
  • Total number of nodes
  • Specific graph topologies such as complete graphs, balanced trees, and more

These simulations will leverage the graph generators provided by networkx to explore the influence of network structure on transaction success rates.

Running the Simulations

To execute a simulation, open the appropriate Python file and set the desired parameters in the configuration section, then call the appropriate functions to run the simulation and plot the results. For example, to run the scenario where edge capacities and transaction fees are varied, in edge_capacity_variation.py file:

# Set the simulation parameters
num_nodes = 100
capacity_range = np.arange(1.0, 20.0, 1)
transaction_amount = 1
fee_range = np.round(np.arange(0.1, 1, 0.01), 2)
epsilon = 0.002
num_runs = 20
avg_degree = 10
window_size = 1000

# Run the simulation
results_df = simulate_network_capacity_fee_variation(num_nodes, capacity_range, transaction_amount, fee_range, epsilon, window_size, num_runs, avg_degree)

# Plot the results
plot_results_capacity_fee_variation(results_df)

Dependencies

To install dependencies, run the following command in your terminal:

pip install -r requirements.txt

Alternatively, if you prefer Poetry:

poetry install

Just keep in mind that requirements.txt is the ground source of truth, and our pyproject.toml may run out of date.

Google Cloud

https://askubuntu.com/a/1261782