Insights | Firm C

Blog: The impact of AI on financial institutions. Part 1

Written by Marcel de Lange | Oct 2, 2024 11:18:03 AM

Firm C revolutionizes financial consulting with cutting-edge technology, driving innovation and growth for institutions. With expert insights and tailored strategies, Firm C stands at the forefront, transforming challenges into opportunities. Discover the future of finance at Firm C.

Artificial intelligence (AI) has revolutionized the way financial institutions operate, leading to enhanced efficiency, improved customer experiences, and better decision-making. One compelling instance of AI implementation in the financial sector is the use of chatbots for customer service. These virtual assistants use AI algorithms to understand and respond to customer queries, providing round-the-clock support and personalized interactions.
By incorporating chatbots, financial institutions can streamline their customer service operations, reduce response times, and handle a large volume of inquiries simultaneously. This not only enhances customer satisfaction but also saves time and resources for the institution. HSBC, for example, implemented a chatbot called Amy to assist its employees with HR-related questions, leading to a significant increase in efficiency and employee satisfaction.
AI algorithms are also widely utilized in financial institutions for fraud detection and prevention. These algorithms analyse vast amounts of data in real-time to identify suspicious patterns or transactions that deviate from a customer's typical behaviour. By swiftly flagging potential threats, AI helps financial institutions prevent fraudulent activities and protect the interests of their customers. One notable example is the use of AI by PayPal to detect and prevent fraudulent transactions, resulting in a significant decrease in financial losses due to fraud.
Moreover, AI-powered data analytics tools have enabled financial institutions to gain valuable insights into customer behaviour, market trends, and investment opportunities. By analysing data at a granular level and predicting future patterns, AI assists financial institutions in making informed decisions and offering personalized services to customers. Capital One, for instance, leverages AI algorithms to analyse customer data and provide customized financial recommendations to enhance engagement and loyalty.
The integration of artificial intelligence has brought about transformative changes in the business operations of financial institutions. From improving customer service through chatbots to enhancing fraud detection mechanisms and leveraging data analytics for better decision-making, AI continues to drive innovation and efficiency in the financial sector. As technology advances further, financial institutions that embrace AI will gain a competitive edge, providing superior services and experiences to their customers while optimizing their internal processes.

Various AI techniques
AI Techniques are the building blocks for creating intelligent systems that mimic human-like cognitive functions. The number of AI techniques is expanding rapidly. By categorising AI Techniques, we can better understand how AI systems operate and how they impact our world.

Supervised Learning 
Supervised Learning is a foundational AI Technique that plays a pivotal role in tasks requiring pattern recognition and prediction. In this method, AI systems learn from a labelled dataset, where each data point is associated with a known outcome. The primary goal is for the AI to identify patterns within the data that can be used to map input to the correct output. 
Supervised Learning finds extensive use in various applications, such as image classification, speech recognition, and recommendation systems. For instance, it enables email spam filters to distinguish between spam and legitimate emails based on learned patterns.


Unsupervised Learning  
Unsupervised Learning takes a different approach compared to Supervised Learning. In this technique, AI systems analyse unlabelled data, where no predefined outcomes are provided. The objective is to uncover inherent structures or patterns within the data without any prior knowledge. 
Clustering and dimensionality reduction are common applications of Unsupervised Learning. For instance, it can group similar customer behaviour data to identify customer segments for targeted marketing strategies. 

Reinforcement Learning 
Reinforcement Learning is a feedback-based Machine learning technique in which an agent learns to behave in an environment by performing the actions and seeing the results of actions. For each good action, the agent gets positive feedback, and for each bad action, the agent gets negative feedback or penalty.
Reinforcement Learning solves a specific type of problem where decision making is sequential, and the goal is long-term, such as game-playing, robotics, etc. 

Deep Learning 
At its core, Deep Learning relies on neural networks with multiple layers (deep neural networks) to model intricate patterns and representations within data.  
The impact of Deep Learning is evident in image and speech recognition and even in playing games like Go and Chess at a superhuman level. 

Natural Language Processing (NLP) 
Natural Language Processing focuses on allowing machines to understand, interpret, and generate human language. NLP techniques enable AI systems to process, analyse, and respond to text or speech data in a way that resembles human language comprehension.  
NLP powers applications like chatbots, language translation, sentiment analysis, and virtual assistants like Siri and Alexa. It has transformed how we interact with computers, making human-computer communication more intuitive. 

Computer vision 
Computer vision is an AI Technique dedicated to helping machines to interpret and understand visual information from the world. It involves the analysis of images and videos to recognise objects, people, and scenes. 
Applications of computer vision range from autonomous vehicles that perceive and navigate their surroundings to facial recognition systems used for security and image analysis tools that detect defects in manufacturing processes.
--------------------------------------------------------------------------------------------------------
Blog 1.
In this blog, I will describe the impact of AI in general on the business of financial institutions and give some concrete examples of the application of a particular AI technique.
Such an application is the use of Adversarial Search which is a particular kind of Reinforcement Learning. Adversarial Search is a technique used in artificial intelligence to model decision-making in competitive multi-agent environments. It involves simulating possible future moves of both the agent and an opponent to determine the best course of action.
In Adversarial Search, the AI agent anticipates the moves of an opponent by exploring various possible actions and counter-actions. This is commonly used in games such as chess, poker, or Go, where the agent must make strategic decisions considering the potential moves of the opponent.
One of the most well-known algorithms for Adversarial Search is the Minimax algorithm, which aims to minimize the potential loss in the worst-case scenario. It works by recursively evaluating possible future moves and selecting the move that leads to the best possible outcome for the AI agent, assuming the opponent plays optimally as well.
Adversarial Search may be applied by financial institutions in trading securities in the development of algorithmic trading strategies to maximize profits while mitigating risks.
In this context, adversarial search algorithms are utilized to simulate the competitive nature of financial markets, where traders are constantly adjusting their strategies to outperform each other. By modelling the trading environment as an adversarial game, financial institutions can leverage these algorithms to analyse market data, predict price movements, and optimize their trading decisions in real-time.
Tic-tac-toe (Dutch: boter, kaas en eieren) is a simple example of an adversarial game: the algorithm faces an opponent that tries to achieve the opposite goal. Attached you will find an example of Python code that utilizes Adversarial Search to play tic-tac-toe.
It is based on the following functions given state s:
S₀: Initial state (in this case, an empty 3X3 board)
Players(s): a function that, given a state s, returns which player’s turn it is (X or O).
Actions(s): a function that, given a state s, return all the legal moves in this state (what spots are free on the board).
Result(s, a): a function that, given a state s and action a, returns a new state. This is the board that resulted from performing the action a on state s (making a move in the game).
Terminal(s): a function that, given a state s, checks whether this is the last step in the game, i.e. if someone won or there is a tie. Returns True if the game has ended, False otherwise.
Utility(s): a function that, given a terminal state s, returns the utility value of the state: -1, 0, or 1.
How the algorithm works:
Recursively, the algorithm simulates all possible games that can take place beginning at the current state and until a terminal state is reached. Each terminal state is valued as either (-1), 0, or (+1).
Feel free to copy and use this code and run it in your Python interpreter. You can play tic-tac-toe against the computer! Be aware: the computer never loses and occasionally wins if you don’t pay attention...

 

    
Python code.
"""
Tic-Tac-Toe Game
This code creates a functional Tic-Tac-Toe game with a graphical
user interface that allows a player to play against an AI opponent
using the Minimax algorithm for AI moves.

1. It defines constants for representing players (X and O) and an empty cell.
2. It defines functions for initializing the game board, 
determining the current player, available actions, making a move, 
checking for a winner, checking if the game has ended, 
calculating the utility value of the game board 
and implementing the Minimax algorithm for AI move selection.
3. It initializes the Pygame module, sets up the game window, fonts 
and colors. If the AI opponent makes the first move, this move is
randomly selected as the first move does not influence the come. As such,
the user does not always play the same game when he is the O-player.
4. It manages the game loop where players can interact with the game board 
by clicking on cells to make their moves.
5. It handles user input for selecting player X or O 
and alternates between user and AI turns.
6. It draws the game board, displays game status messages
and checks for game over conditions.
7. It allows players to play again or stop the game at the end.

"""
import copy
import pygame
import sys
import time
import random

X = "X"
O = "O"
EMPTY = None

def initial_state():
    return [[EMPTY, EMPTY, EMPTY],
            [EMPTY, EMPTY, EMPTY],
            [EMPTY, EMPTY, EMPTY]]

def current_player(board):
    total_x = sum(row.count(X) for row in board)
    total_o = sum(row.count(O) for row in board)

    if total_x > total_o:
        return O
    else:
        return X

def actions(board):
    possible_actions = set()

    for r in range(3):
        for c in range(3):
            if board[r][c] == EMPTY:
                possible_actions.add((r, c))

    return possible_actions

def result(board, action):
    copied_board = copy.deepcopy(board)
    player_turn = current_player(copied_board)
    copied_board[action[0]][action[1]] = player_turn

    return copied_board

def winner(board):
    for player in [X, O]:
        for i in range(3):
            if all(cell == player for cell in board[i]):
                return player
            if all(board[j][i] == player for j in range(3)):
                return player
        if all(board[i][i] == player for i in range(3)) or all(board[i][2 - i] == player for i in range(3)):
            return player

    return None

def terminal(board):
    return (winner(board) is not None) or not any(EMPTY == cell for row in board for cell in row)

def utility(board):
    if winner(board) == X:
        return 1
    elif winner(board) == O:
        return -1
    else:
        return 0

def minimax(board):
    if terminal(board):
        return None

    if current_player(board) == X:
        _, move = max_value(board)
        return move
    else:
        _, move = min_value(board)
        return move

def max_value(board):
    if terminal(board):
        return utility(board), None

    value = float('-inf')
    move = None

    for action in actions(board):
        val, _ = min_value(result(board, action))
        if val > value:
            value = val
            move = action
            if value == 1:
                return value, move

    return value, move

def min_value(board):
    if terminal(board):
        return utility(board), None
    
    value = float('inf')
    move = None

    for action in actions(board):
        val, _ = max_value(result(board, action))
        if val < value:
            value = val
            move = action
            if value == -1:
                return value, move

    return value, move

pygame.init()
size = width, height = 600, 550
black = (0, 0, 0)
white = (255, 255, 255)
screen = pygame.display.set_mode(size)

mediumFont = pygame.font.Font(None, 28)  # Changed the font file to None for default font
largeFont = pygame.font.Font(None, 40)  # Changed the font file to None for default font
moveFont = pygame.font.Font(None, 60)  # Changed the font file to None for default font

user = None
board = initial_state()
ai_turn = False
running = True
first_move = True 

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill(black)

    if user is None:
        title = largeFont.render("Play Tic-Tac-Toe", True, white)
        titleRect = title.get_rect()
        titleRect.center = (width / 2, 50)
        screen.blit(title, titleRect)

        playXButton = pygame.Rect((width / 8), (height / 2), width / 4, 50)
        playX = mediumFont.render("Play as X", True, black)
        playXRect = playX.get_rect()
        playXRect.center = playXButton.center
        pygame.draw.rect(screen, white, playXButton)
        screen.blit(playX, playXRect)

        playOButton = pygame.Rect(5 * (width / 8), (height / 2), width / 4, 50)
        playO = mediumFont.render("Play as O", True, black)
        playORect = playO.get_rect()
        playORect.center = playOButton.center
        pygame.draw.rect(screen, white, playOButton)
        screen.blit(playO, playORect)

        click, _, _ = pygame.mouse.get_pressed()
        if click == 1:
            mouse = pygame.mouse.get_pos()
            if playXButton.collidepoint(mouse):
                time.sleep(0.2)
                user = X
            elif playOButton.collidepoint(mouse):
                time.sleep(0.2)
                user = O

    else:
        tile_size = 80
        tile_origin = (width / 2 - (1.5 * tile_size), height / 2 - (1.5 * tile_size))
        tiles = []
        for i in range(3):
            row = []
            for j in range(3):
                rect = pygame.Rect(tile_origin[0] + j * tile_size, tile_origin[1] + i * tile_size, tile_size, tile_size)
                pygame.draw.rect(screen, white, rect, 3)

                if board[i][j] != EMPTY:
                    move = moveFont.render(board[i][j], True, white)
                    moveRect = move.get_rect()
                    moveRect.center = rect.center
                    screen.blit(move, moveRect)
                row.append(rect)
            tiles.append(row)

        game_over = terminal(board)
        player = current_player(board)

        if game_over:
            winner_player = winner(board)
            title_text = f"Game Over: {winner_player} wins." if winner_player else "Game Over: Tie."
        elif user == player:
            title_text = f"Play as {user}"
        else:
            title_text = "Computer thinking..."
        title = largeFont.render(title_text, True, white)
        titleRect = title.get_rect()
        titleRect.center = (width / 2, 30)
        screen.blit(title, titleRect)

        if user != player and not game_over:
            if ai_turn:
                time.sleep(0.5)
                if player == X and first_move:
                # Make a random move for the first turn as X player
                    empty_positions = [(i, j) for i in range(3) for j in range(3) if board[i][j] == EMPTY]
                    random_move = random.choice(empty_positions)
                    board = result(board, random_move)
                    ai_turn = False
                    first_move = False
                else:
                    move = minimax(board)
                    board = result(board, move)
                    ai_turn = False
            else:
                ai_turn = True

        click, _, _ = pygame.mouse.get_pressed()
        if click == 1 and user == player and not game_over:
            mouse = pygame.mouse.get_pos()
            for i in range(3):
                for j in range(3):
                    if board[i][j] == EMPTY and tiles[i][j].collidepoint(mouse):
                        board = result(board, (i, j))
                     

        if game_over:
            againButton = pygame.Rect(width / 3, height - 125, width / 3, 50)
            stopButton = pygame.Rect(width / 3, height - 60, width / 3, 50)
            stop = mediumFont.render("Stop Game", True, black)
            stopRect = stop.get_rect()
            stopRect.center = stopButton.center
            pygame.draw.rect(screen, white, stopButton)
            screen.blit(stop, stopRect)
            again = mediumFont.render("Play Again", True, black)
            againRect = again.get_rect()
            againRect.center = againButton.center
            pygame.draw.rect(screen, white, againButton)
            screen.blit(again, againRect)
            click, _, _ = pygame.mouse.get_pressed()
            if click == 1:
                mouse = pygame.mouse.get_pos()
                if againButton.collidepoint(mouse):
                    time.sleep(0.2)
                    user = None
                    board = initial_state()
                    ai_turn = False
                    first_move = True
                if stopButton.collidepoint(mouse):
                    time.sleep(0.2)                
                    pygame.quit()
                    running = False
                    sys.exit()

                    
    pygame.display.flip()