Книга: Intelligent Banking
Назад: List of Figures
Дальше: Part I Money and the Government

List of Tables

Introduction

Contents

Traditional money and banking textbooks establish the central tenets of the science of macroeconomics and financial markets. Their main audience is undergraduate economics students. As such, they tend to offer comprehensive treatments with large breadth and scope. Material is presented in an academic fashion. Given their voluminous treatments, traditional money and banking textbooks may also serve as occasional reference beyond graduation.

There is another track where books on capital markets operate, which falls largely on what is commonly referred to as “trade books.” These books tend to be more advanced, since their intended audiences are professionals or continuing education clientele. These books are often technical and data-driven, but they are generally void of fundamental exposition of economic theory or the institutional aspects of various financial markets.

Since the ultimate purpose and intended audiences for these two types of book are quite different, a gap opens between the traditional textbook and the trade book. This book bridges that gap. It is neither a traditional textbook nor is it a trade book—though it combines aspects of both.

In the U. S., if you are an undergraduate student in economics, you are rarely trained in programming—particularly programming that is targeted to applications in economics and finance. Instead, if you are an economics or finance major, you would typically be exposed to the fundamentals of money and banking from traditional textbooks. This often leaves economics and finance majors untrained in programming for financial applications. Picking up programming skills from trade books would then be simply left until after graduation.

On the other hand, if you are an engineering and computer science major, you would finish your studies at university well trained in programming, but with a sparse understanding of the fundamentals of financial markets. The main objective of this book is to pull double duty and immerse you in economic concepts of financial markets and banking with an emphasis on programming. Thus, the main audience of this book is undergraduate students in economics, finance, and other quantitative fields. If you are in these fields, this book was written for you.

Traditional money and banking textbooks are written in a strictly academic fashion. Thus, they tend to be broad in scope with a large number of chapters often numbering 20, 25, and beyond! Two full semesters of intense training may still not do justice to all the material offered in these books. Instructors are left covering treatments at back-breaking speed. Another byproduct of these large treatments is that substantial portions of the prototypical money and banking textbook are left unattended by the instructor. So, parts of the book are left fallow.

This is not your typical money and banking textbook. Far from being encyclopedic, this is a lean book that leans heavily on Python programming. It was written so that it can be covered in its entirety over a single semester at a leisurely pace. Therefore, I have sacrificed breadth in the vast array of economic notions typically afforded by the standard textbook in favor of the depth in some of the fundamental concepts by reinforcing them with programming.

It is increasingly common that students in other (less technical) areas outside economics, finance, computer science, and engineering turn to studying finance, banking, and financial markets for master’s degrees. While it is difficult to avoid equations on a book on this subject, I have curated the material for a less mathematical and more accessible reading. I leave the more technical details or expanded treatments for other excellent books such as Python for Finance by Yves Hilpisch or The Economics of Money, Banking and Financial Markets by Frederic Mishkin. My choice of topics covered stems from my own university teaching experience with undergraduate and graduate courses in banking and financial markets. Therefore, if you are pursuing an MBA or MS in finance, this book may be useful to you.

In this book, we will cover the fundamentals of various monetary markets and several main treatments covered by more typical money and banking textbooks. And we will forgo some of the breadth usually found in the traditional textbooks in favor of a deeper treatment of technical topics and programming, more typically found in trade books. Specifically, we will lean heavily on Python programming to contextualize the fundamental concepts of money and banking. Our goal is to gain general Python skills (e. g., importing Python libraries, setting up Python environments to work, reading in data) as well as specific skills for Python programming for banking (e. g., modeling yield curves, forecasting stock prices, regressing market yields).

The book contains snippets of Python code interspersed throughout. A companion website is provided with all the Python snippets and additional expanded codes.

0.1 Structure and Treatments

The book is divided into four parts: Part —Money and the Government, Part —Time, Probability, and Risk, Part —Financial Markets, and Part —Machine Learning.

The first chapter of Money and the Government describes the role of government in the management and determination of the money supply. It describes money as a vehicle for incurring government debt. Fiscal policy broadly involves taxing, spending, and borrowing. This chapter focuses on the latter. Governments generally borrow by issuing “I-owe-you’s,” which we call bonds and we discuss in later chapters. These bonds are often issued by national and local governments. This chapter describes some historical trends in debt of various parts of the economy.

Another aspect of money in the government refers to its management. This falls under the umbrella of monetary policy. The second chapter of Money and the Government describes the role the U. S. central bank—the Federal Reserve system—has in the determination of the money supply and its connection with interest rates. This chapter defines the money supply and discusses two different ways to aggregate money balances: simple-sum (equal weighing) aggregation versus Divisia (liquidity-weighing) aggregation. The chapter also describes interest rates obtained in the market, such as the federal funds rate, and differentiates them from managed rates, like the discount window rate or interest on reserve balances (IORB). Finally, it makes some connections between the Federal Reserve’s own balance sheet, the monetary base, and bank reserves.

The second part of the book is titled Time, Probability, and Risk. This part contains three chapters. The first chapter of this part of the book introduces the concept of interest rates by connecting them with the concepts of monetary assets discussed in previous sections. Interest rates place value on monetary assets at different times by bringing them backward or forward in time to a time when they can be compared. This first chapter covers the foundations of the analysis of time value of money with important concepts of future value and present value.

The second chapter of Time, Probability, and Risk covers the main axioms of probability theory and establishes the concepts of expectations, the central limit theorem, and long-term averaging. All these concepts are crucial to modeling the levels and trends of interest rates and many other financial variables. The third chapter of Time, Probability, and Risk covers the fundamentals of risk by differentiating between expected values and volatilities of various financial instruments. It explains the trade-offs between financial risk and financial returns. And it covers the basics of risk management.

The third part of the book is titled Financial Markets. This part is subdivided into three chapters—the first of which presents the bond market. It covers discount and coupon bonds issues by treasuries as well as corporations. It discusses yields, returns, and risk in the bond market. The next chapter covers theories of interest rates. It discusses interest rate spreads, risk spreads, and the term structure of interest rates. The final chapter in this section covers the stock market. It discusses valuation of single stocks as well as overall index measures. It covers methods for assessing risk and returns of stock. It explains the concept of Monte Carlo simulations and gives a primer on forecasting equity prices.

The final part of the book is titled Machine Learning. Beginning from the concept of a perceptron, it covers its connection with neural networks and linear regression. It also discusses basic tasks of machine learning, such as classification, prediction, and inference.

0.2 Why Python?

Banks and financial companies are increasingly demanding these skills from recent college graduates. Yet, traditional money and banking textbooks rarely offer these skills. If you are a typical economics major, you would likely need to supplement what you get from the traditional approach to money and banking, with coursework in computer science to add to your general knowledge of programming. Importantly, these skills would not be directed to applications in finance or economics—leaving you to make those connections on your own, possibly after college graduation.

Banking and finance have always required high degrees of human intelligence, which is now beginning to be artificially enhanced. Programming languages are the nexus of interaction between human and artificial intelligence. And banks and financial institutions have already begun to make the transition by requiring programming training of many of their analysts.

Important financial companies such as JPMorgan Chase and Citi require their asset management trainees to learn how to code (typically in Python). This fosters better communication between the business teams and the technology teams. These two major banks, as well as other financial institutions, now run summer Python coding camps for their recent hires. This clearly reflects the lack of Python programming training available to business and economics students outside engineering schools. This book was written in part to remedy this.

A report by PricewaterhouseCoopers LLP, found that almost one-third of financial services jobs could be displaced by automation—related to machine learning and AI—by the mid-2030s. In the opinion of this author, the advent of AI analytics will not simply remove jobs in banking and finance. Instead, it is more likely AI will expand the definition of the roles financial analysts and bankers are known for. It is also likely it will create new types of jobs, some ancillary and some central to the expertise one expects from financial analysts, wealth managers, and bankers.

Job seekers with fluency in machine learning, artificial intelligence, and data sciences will likely be in even higher demand than ever before. This motivates a revamping of the curriculum of financial markets and economics to emphasize these skills at earlier stages of the educational track. This book argues for some introduction of these programming skills at the beginning stages of college-level economics and financial degrees rather than at the last stages. And often these skills are not gained at college at all! Instead, these skills have been typically acquired beyond graduation—for example with coding camps offered by the banking industry for their newly minted employees. This book was written for students who might want to get a head start on acquiring these tools.

A distinct advantage of this book is that it is an introduction to first-principle concepts of finance and financial markets while providing a first introduction to Python programming. It is not meant for advanced practitioners or Ph. D. students who may have taken multiple courses in each. If you are taking your first steps in the world of finance or economics, and you want to learn some programming along the way, this book is for you.

0.3 Integrated Development Environments (IDEs)

An integrated development environment (IDE) is a software application that provides a comprehensive suite of components with similar user interfaces acting as a single program in which all development can be done.

While IDEs may vary widely, they tend to include: a source code editor where programming is done, a compiler/interpreter that runs the code, and some graphical user interface (GUI) that can offer some added features, like graphing, editing, code completion, syntax highlighting, debugging, etc.

The fact that IDEs are integrated environments allows for creating, running, and debugging code all in one. Some programmers prefer to work exclusively in code editors where code can be written, edited, and saved. But then it must be subsequently run elsewhere. Code editors are generally simpler than IDEs, as they do not include many other IDE components.

21 icons for integrated development environments (IDEs) for Python, including PyCharm, Visual Studio Code, Sublime Text, Spyder, Thonny Jupyter Notebook, and more.

Figure 0.1 Searching for IDEs to work with Python.

If we Google Best IDEs for Python programming, we get many different ones: PyCharm, IDLE, Spyder, Atom, Sublime, Vim, and Jupyter Notebook are particularly popular. See . All of these can be downloaded and installed in our computer as free shareware—though some IDEs may have a premium paid version, they are generally just cosmetic upgrades. All the analysis in this book can be accomplished free of charge with these shareware IDEs. Throughout the book we will be using .

Again, these can be installed locally on our machine free of charge. An alternative to installing IDEs on our machine is to work on cloud-based IDEs. Cloud IDEs rely on powerful servers hosted in remote data centers. When we open a cloud IDE in your browser, it spins up a virtual environment—essentially a remote container or virtual machine—that acts as our development workspace. This workspace includes all the tools and dependencies we need for a specific version of Python we might need. The advantages of cloud-based IDEs include the ability to collaborate with partners and friends in real time as well as the ability to leverage computational power of remote servers that may often exceed the memory and processing capabilities of our own machine. A disadvantage is that they require a stable internet connection and/or WIFI signal, and processing speed can be less reliable over WIFI than locally in our computer.

0.4 Setting up a Python Environment

The ancient Romans had a popular refrain: “Omnes viae Romam ducunt” roughly translating to “All roads lead to Rome.” At the height of the Roman Empire, more than 350 major roads resembling the spokes on a large wheel spanned roughly 50,000 miles, ranging as far away as Hispania (modern day Spain, my country of origin), or from the “Hadrian’s Wall” in Scotland, or from the Euphrates River in Mesopotamia (modern day Iraq), or from Northern Germany, or from the Sahara desert in North Africa—all leading to Rome as the final destination, the center of the wheel.

We could say Rome was at the center of a highly integrated network. One could start from far-ranging origins, but it did not matter whether one started their journey from Northern Europe, Southern Europe, Northern Africa, or the Middle East, one could invariably arrive in Rome.

Similarly, we could say that Python is the center of a highly integrated network of software applications and programming. Python is a rich ecosystem with wide applicability across multiple fields. Just as it did not matter whether you were a German, a Scot, or a Spaniard… you could arrive in Rome—it does not matter whether you are a software engineer, a physicist, or an economist… you can arrive at Python!

Moreover, the rich Python ecosystem allows for multiple ways to accomplish similar tasks. For example, there are myriad ways to set up a Python environment. Just as the road from Northern Europe, Southern Europe, or North Africa would lead to Rome, setting up a working environment locally from an MS-DOS prompt or from a graphical unit interface (GUI) or setting up an environment in the cloud, all lead to a working Python setup.

There is a wealth of information on the internet on how to set up a Python environment: in the , in the , or in . Just as many roads lead to Rome, many roads lead to a working Python setup. Just as Rome was a rich network of roads and cities, Python is also a rich ecosystem of dozens of IDEs and hundreds of libraries. There are multiple ways to set up a Python environment locally in your computer or in the cloud. You may already have a Python setup yourself, or you may find a setup that works for you. There is no right or wrong setup, there is just what works for you. And you may find along the way that a setup can be quite idiosyncratic and mostly driven by personal preference. But at the end of the day, it does not really matter for your day-to-day work. One can be just as productive working with different setups.

I will now discuss a step-by-step setup to getting Python working on your PC so you can run the codes and follow along throughout the various chapters of this book. While all of this can also be done for Mac OS or Linux operating systems, the discussion below focuses on the Microsoft Windows operating system.

0.4.1 Laying the Groundwork: Installing Anaconda

There are many ways to install Python on our computer. One of the most popular ones is through the distributor/repository called . Anaconda (or simply Conda) is an open source distribution platform for Python and other languages created by Anaconda, Inc.—an American company founded in 2012. As of 2025, Anaconda claims it has about 50 million users worldwide. The reason for its popularity is that it serves as a package manager and it is free (though it also has a subscription-based premium version). Python is an object-oriented programming language. What makes it powerful is its rich and deep ecosystem of libraries, packages, and applications. Often, different packages and libraries are developed independently and may not necessarily play nice (compatibility-wise) with each other. These packages act as a patchwork in the fabric that is Python. Anaconda’s main service is to fit these patches together into “the Python quilt” and create environments where the libraries and native Python work well together.

We can download and install Anaconda from their free of charge. Anaconda provides download and installing documentation for the three major operating systems . Anaconda also provides a GUI called , which offers a simple and intuitive toolkit for installing and managing packages as shown in in .

12 icons in Anaconda's graphical user interface, including PyCharm Professional, Anaconda Toolbox, Anaconda Cloud Notebooks, and more.

Figure 0.2 Anaconda Navigator’s graphical user interface.

A different way to download and install Anaconda without the Navigator GUI is to do so through a command line interface (or CLI), which is a program on our computer that processes text commands to do various tasks. Conda is a CLI program, which means it can only be used via the command line. On Windows computers, Anaconda recommends that we use the Anaconda Prompt CLI to work with Conda. This CLI is called Conda Powershell and it is included in the installation for free. On MacOS and Linux, users can use their built-in command line applications.

Anaconda contains a large suite of packages. There is a streamlined version called , which is a smaller version of Anaconda that includes only Conda, Python, the packages they depend on, and a small number of other packages. The smaller Miniconda allows for a streamlined installation, which we can then grow organically by installing packages as we need them. We discuss this practice below.

0.4.2 Getting Started: Step-by-step

Let’s get started by downloading and installing Miniconda.

  • Turn our computer on and ensure we are connected to the internet.

  • Open a web browser and navigate to the , or the .

shows what the installation website looks like in 2025. In the future, the layout of the website may look slightly different but the features and functionality should remain the same.

Downloads for Anaconda install pages for Windows, Mac and Linux.

Figure 0.3 Anaconda install page.

And scrolling down the same page, we can find the Miniconda installation button, which I highlighted in yellow. Click on it to install it on our computer. See .

Miniconda installers for Windows, Mac and Linux, with the Windows 64-Bit Graphical Installer highlighted in yellow.

Figure 0.4 Miniconda install page.

shows that I downloaded Miniconda to my Windows 11 machine via Google Chrome. You can find it on your browser’s Downloads icon (highlighted in green). We can install it in our computer by clicking on the self-extracting link (highlighted in yellow).

The install of Miniconda.

Figure 0.5 Miniconda downloaded locally to a Windows 11 PC.

Then we can follow the self installer, which will ask for a directory to save our Conda and Python environments to.

SILENT INSTALL

Another way to install Conda is through what is known as a “silent installation.” On a Windows 11 PC:

  • Select the Start menu (the Windows icon) on the taskbar or press the Windows key.

  • Type ‘cmd.’

  • Select the Command Prompt from the list.

The command prompt will open to wherever the default path is located, which may look something like what is shown in .

See caption.

Figure 0.6 A standard command prompt.

Then type the following three commands:

These three lines instruct the computer to download the latest 64-bit Windows installer. We might want to rename it to a shorter file name or leave the three lines untouched. This performs a silent install, and then deletes the installer. It is called silent because it runs quietly in native MS-DOS, it does not open any screens, and all we can see as proof that it downloaded and installed is the following in the command prompt. See .

Miniconda prompt displaying the anaconda URL for a silent install.

Figure 0.7 Silent installation of Miniconda on a Windows 11 machine.

The command prompt now shows that 100% of the 88.9M Miniconda package was successfully installed on my Windows 11 machine.

There are additional ways to install Miniconda, such as from the Windows Powershell or directly from the Anaconda Navigator GUI. Instructions on these, as well as on how to install for Mac IOS and Linux are all available on the .

0.4.3 Working from the Miniconda Powershell

As we mentioned earlier, Python is a rich ecosystem of libraries and packages. These libraries are often developed independently, so they constitute a patchwork, and Conda is the quilt that gathers and patches up the various libraries. We will be doing analysis in an IDE. But before we can start working, we must set up an environment to do so. Miniconda is what we will use to set up the environment to work. Once we have installed Miniconda on our Windows 11 machine, we can simply go to the search box next to the Windows icon and type “miniconda”. See .

Search box for `Miniconda' next to the windows icon for Windows 11 Prompt.

Figure 0.8 Finding the Miniconda Powershell in the computer.

Clicking on the Miniconda Powershell is our first step into the world of Python. Clicking on it will open a window in our machine that will look reminiscent of an MS-DOS prompt. It will typically look like a black screen very similar to the Command Prompt screen shown in . Or it may look different if we have reformatted the look of the Conda Powershell in advance.

Since I have played with the look of my own Powershell in the past, my Conda Powershell does not look black. Regardless of how it looks, the prompt will automatically open wherever the Miniconda installation placed the base install on our computer. See .

See caption.

Figure 0.9 Conda base prompt.

At the Conda prompt, typing “conda - -version” will return the version of Conda installed in our computer. Our Miniconda installation would have already installed a few libraries along with the base installation. Typing “conda list” at the prompt will show the list of libraries originally installed with Miniconda. See .

Miniconda prompt displaying a partial set of libraries in the base Conda environment.

Figure 0.10 A list of libraries installed in the (base) Conda installation.

We can always install more libraries onto our (base) installation as needed. However, I recommend keeping our base installation as light as possible. Why?

Let’s remember that Python libraries are often developed and updated independently by different parties—Who knows? You might create your own libraries yourself in the future? As a package manager, Conda patches up all these independent libraries and often creates dependencies that get these various libraries to play nice with each other. Since these Python libraries are independent, some libraries tend to be updated more regularly than others. This means that sometimes some libraries or packages get updated and no longer work nicely with the other libraries until other updates take place. So, it is a common occurrence that a project works one day and the next day, if a library gets updated, it stops working.

Here is where the utility of Conda really shines! Conda is not only a package manager, but also an environment manager. This means that we can set up an environment in Conda that is project specific. We can set up the libraries and packages we want under a given environment. And this environment acts as a freezer. If we do not update the libraries within that environment, the code is nearly guaranteed to continue to work even if versions subsequently change and libraries get updated.

Therefore, we can create different environments for different projects. We can create as many environments as we want and use them for different projects or for multipurpose. We can keep the libraries in an environment frozen or update them. We can share environments with friends. We can clone environments and we can delete environments when we no longer need them. Environments are our friends!

0.4.4 Python Environments with Conda

First, we want to find out whether we have Conda environments set up in our computer. At the Conda prompt, typing “conda env list” returns whatever environments we may have. If we just installed Conda, we likely have a single environment created with the base installation. We call this the (base) environment. See .

See caption.

Figure 0.11 Conda (base) environment.

But again, a best practice is to leave (base) light and unencumbered with library/pckg bloat and, instead, to work in other environments. To do this, let us create the first environment. At the Conda prompt, type “conda create” followed by a space and a double hyphen and the word “name”. Whatever we write after the command “name” will be the name we are giving to the new environment. The name must be alphanumeric and it may not contain spaces. Let’s call our environment ‘Banking Intelligence 1’. This name will not work because of the spaces. An easy workaround is to connect words with underscores, hyphens, or periods.

To sum up, type “conda create - -name Banking_Intelligence_1. See .

Miniconda prompt displaying a package plan to download into a specified environment location and a request to proceed.

Figure 0.12 Create a new environment called Banking Intelligence 1.

This command gathers the necessary files and asks whether we want to proceed. Notice a warning that a newer version of Conda exists. (This will likely not appear on your end if you installed Conda recently.) But in any event, this will create the new environment without incident. Typing “y” for “yes” creates the package and returns us to the (base) prompt. See .

See caption.

Figure 0.13 A new environment called Banking Intelligence 1 is installed.

To verify that we did create our new environment, type again “conda env list” at the prompt and we can see two environments now. See .

See caption.

Figure 0.14 Banking Intelligence 1 is a new environment.

Notice there is an asterisk next to (base), the asterisk denotes the environment that is currently active. Let us now activate our new environment. At the prompt, type “conda activate Banking_Intelligence_1” and then type again “conda env list” and we can see that our newly installed environment is now activated as we can see its name in the parenthesis at the prompt and we can see the asterisk next to the name in the environment list. See .

See caption.

Figure 0.15 Banking Intelligence 1 is activated.

For practice, take some time now and create another environment called Banking Intelligence 2 and activate it. You should arrive at a new environment list that looks like .

See caption.

Figure 0.16 Banking Intelligence 2 is activated.

Now let us say that in a few months we no longer need this newest environment and decide to delete it from your environments folder. This can be easily accomplished with the Conda command “remove.” However, we cannot delete the environment while the environment is active. We need to exit the environment first before removing it from the computer.

We can do it as before by activating another environment. For example, at the (Banking_Intelligence_2) prompt we could type “conda activate Banking_Intelligence_1” and we could then delete Banking_Intelligence_2 environment from there.

Alternatively, we could exit this environment by deactivating it, which would return us to the (base) environment by default. At the (Banking_Intelligence_2) prompt, we could type “conda deactivate Banking_Intelligence_2” and that will return us to base. See .

See caption.

Figure 0.17 Banking Intelligence 2 is deactivated.

We can now safely delete this environment by typing “conda remove - -name Banking_Intelligence_2 - - all”. See .

Notice the environment is now gone from the list. As the environment was being deleted, Conda attempted to remove all packages, but it found none to remove. This is natural, since we had not installed any packages in that environment yet.

See caption.

Figure 0.18 Banking Intelligence 2 has been deleted from the environment list.

0.4.5 Python Libraries in Conda

Returning to our ‘Banking Intelligence 1’ environment, if we type “conda list” it returns an empty set since we have not yet installed any libraries in this new environment. See Figure .

See caption.

Figure 0.19 Banking Intelligence 1 environment is empty.

Let’s now install the IDE we will use in this book. We will install the suite locally in our computer through the Conda Power shell. The Jupyter suite is a powerful IDE that enables interactive computing across many programming languages (the name is an amalgamation of the Julia, Python and R programming languages) in a web browser environment. Jupyter is an open-source, free software written in the open-standards paradigm, which means it is completely free of licensing and allows for free use, to be repurposed and freely distributed. This allows both the software and the code in this book to be available free of charge without any limitations or guarantees.

Jupyter suite provides a range of packages and libraries organized around two main IDEs: Jupyter Notebook and JupyterLab. Jupyter Notebook is the first IDE; therefore, it is older and possibly more popular. In recent years, JupyterLab is increasingly gaining popularity. All the codes in this book were written in JupyterLab. Those Python programmers (who often call themselves Pythonistas) who have been coding in Jupyter Notebook find transitioning to JupyterLab virtually seamless. If we are starting out fresh today, we need not begin from ‘Notebook’; we can begin to work and learn directly from ‘Lab’. One can do virtually the same things in both. The differences are mostly cosmetic, apart from the look of the ‘shell’ and a few additional toolbars and capabilities of the web browser one uses to work with the IDE.

One can install a package or a library in the Conda Powershell with the command conda install followed by the name of the library. Often Conda will install the desired package as well as all the required sub-packages, libraries, sub-libraries, and dependencies required for the package to run. At the (Banking_Intelligence_1) prompt of the Conda Power shell, typing “conda install jupyter” will gather all requisite components and ask to proceed([y],n)? See Figures and .

Miniconda prompt displaying a package plan to download Jupyter into a specified environment location and a request to proceed.

Figure 0.20 Installing the Jupyter Suite.

Miniconda prompt displaying a full list of libraries in the Jupyter ti be downloaded along with a request to proceed.

Figure 0.21 Installing the Jupyter Suite (ctd).

Typing ‘y’ will gather the packages and dependencies and install the Jupyter suite in the active environment. Once the suite and all its dependencies are installed, we can simply scroll down the shell to look for the libraries that were installed (the list is always organized alphabetically). See .

See caption.

Figure 0.22 Scrolling down the Conda Powershell to find the Jupyter installation.

Alternatively, if we want to check whether a particular library or package is currently installed in the active environment, we can simply type the name of the package or library followed by two dashes and the word “version.” For example, at the prompt typing “jupyter - -version” returns the version of the libraries in the Jupyter suite. See .

See caption.

Figure 0.23 Versions of the various Jupyter libraries.

We can easily see JupyterLab was also installed. Had it not been installed, we would need to type “conda install jupyterlab.” This would verify that the dependencies and libraries are all ready—if some libraries required some updating, Conda would prompt us whether we want to update them at this time or not—and subsequently it would install JupyterLab. Remember that this installation of the Jupyter suite has only been downloaded and installed in the currently active environment and not in (base) or in any other environment we might have created.

Two other libraries we will use often throughout the book are and . If we type “numpy - -version” or “pandas - -version,” we get an error if the library is not installed in the (Banking_Intelligence_1) environment. See .

See caption.

Figure 0.24 Numpy and Pandas are not installed in the environment.

At the prompt, we can easily install Numpy by typing “conda install numpy.” See .

See caption.

Figure 0.25 Installing Numpy.

Similarly, we can easily install Pandas by typing “conda install pandas.” Once we have completed this, we can verify these libraries are installed in the current environment by typing: “conda list numpy” and “conda list pandas.” See .

See caption.

Figure 0.26 The Numpy and Pandas libraries are now installed.

We will use Numpy and Pandas frequently throughout the book. We will also need other libraries and packages in this book and, later on, other projects you might undertake. Any additional library can be downloaded and installed in the same way as we described so far for Jupyter, Numpy and Pandas.

Sometimes, we may need a relatively large suite of libraries and packages, and (re-)installing them one-by-one may be time consuming. Let’s say that we have all the packages we need in our ‘Banking_Intelligence_1’ environment and we have been working in that environment for a while. Now, say, we want to create another environment—in our computer or in a different computer—that shares all the same libraries. Reinstalling each library and package one-by-one is always an option, but it can be time consuming. Also, the packages we might download today could be newly updated versions and, instead, we may want to keep the same versions of the libraries we had used before.

There are two ways to reinstall all the same versions of the libraries and packages onto a new environment, depending on whether we want the environment in the same machine or whether we want to create it in a different computer.

To easily replicate all the libraries we have in our environment onto a new environment in the same computer, we can simply clone the environment. Let’s say we want to create a new environment called Banking_Intelligence_5 and we want it to be identical to our Banking_Intelligence_1. This can be easily done at the Conda Powershell prompt by typing: “conda create - - Banking_Intelligence_5 - - clone Banking_Intelligence_1.”

0.4.6 (Re-)creating a Conda Environment via YAML

There is a somewhat more involved process to replicate an existing environment onto another computer. When working with Conda, a file can be used to list all the necessary packages for our project. This makes it easy to share our environment across different computers or with friends, which ensures all the necessary packages and correct versions are available in a new environment to run our code.

Starting from the environment we want to copy—say, ‘Banking_Intelligence_1’— we can export the current environment (with all libraries and packages in their current versions) by exporting it as .yml file in our computer. At the Conda Powershell, typing “conda env export > ‘name your new environment’.yml” will save a YAML file with the name we gave it locally in our computer—in the same directory where your environment is located. See .

See caption.

Figure 0.27 Exporting a Conda environment to a YAML file.

This example creates a file I called “MyIB_env.” Typing “notepad myIB_env.yml” at the Conda prompt opens the YAML file, which contains a listing of all the libraries and packages installed in the “‘Banking_Intelligence_1’” environment. The “myIB_env.yml” YAML file is saved in the default folder. We can simply find it using the search box next to the start button on a Windows 11 machine. For example, the full path to my YAML file on my own computer was saved in “C:\Users\vicva\MyIB_env.yml.”

We can now create a new environment with all the libraries/packages reflected in the YAML file. Typically, we could do this by typing at the Conda Powershell prompt: “conda env create -f MyIB_env.yml.” However, notice that opening the “myIB_env.yml” YAML file in a notepad reveals the name of the original environment ‘Banking_Intelligence_1’. See .

See caption.

Figure 0.28 Exporting a Conda environment to a YAML file.

See caption.

Figure 0.29 Changing the name in the YAML file to ‘Banking_Intelligence_7’.

See caption.

Figure 0.30 An exact duplicate of ‘Banking_Intelligence_1’ is created.

This means that—while the name of the YAML file is “myIB_env.yml”—the name of the environment the YAML file calls is the original name “Banking_Intelligence_1.” So, if we attempt to create the environment from the YAML file, Conda will throw an error because the name of that environment (Banking_Intelligence_1) is already taken. But we can simply open the notepad, and right after the name field, type whatever new name we would like to give to the new environment and save the notepad. For example, let’s change the name in the name field from Banking_Intelligence_1 to Banking_Intelligence_7. See Figure .

We are now ready to create a new environment. At the Conda Powershell prompt type: “conda env create -f MyIB_env.yml.” See .

And voila! We can verify by typing “conda env list” that the new environment Banking_Intelligence_7, which is an exact replica of Banking_Intelligence_1, is now in our list of environments. See .

See caption.

Figure 0.31 An exact duplicate of ‘Banking_Intelligence_1’ is now in the environment list.

A YAML file with all the libraries required to run the codes for this book is available on the companion website .

0.5 Working our Intelligent Banking Book with JupyterLab

Once we have installed all the requisite libraries in our environment and we are ready to start, do the following:

  • Open a Conda Powershell, which automatically opens in the (base) environment.

  • At the prompt, type “conda env list” to see the various environments we have installed in your computer.

  • We will now want to navigate to the environment we want to use—where we have previously installed all the libraries we needed. To do this, type “conda activate” followed by the name of our environment. For example, at the (base) prompt type “conda activate Banking_Intelligence_1.”

  • The prompt will now have switched to (Banking_Intelligence_1), indicating this is now the current environment.

  • At this prompt, typing JupyterLab will open Jupyter in our default web browser (such as Chrome, Internet Explorer, Safari, Bing… or whichever browser you most frequently use).

  • Once JupyterLab is open in the browser, the Conda Powershell must be kept open while we are working in JupyterLab. However, it can be minimized and kept running in the background. Closing or exiting from the Powershell will terminate the JupyterLab session. See .

The interface of the JupyterLab IDE is quite intuitive. Comprehensive documentation for getting started coding in JupyterLab is provided by the open source . The various worksheets provided for each chapter of the book will typically begin by importing the requisite libraries from the environment where the libraries were installed.

See caption.

Figure 0.32 JupyterLab on a Chrome browser.

We will want to make sure the libraries (e. g., Numpy, Pandas, etc.) are installed in the current environment. JupyterLab will show an error if we attempt to import a library that is not installed in the environment. If we ever get an error after we import a library, we must return to the Conda Powershell and install it (see previous sections). Alternatively, some libraries can be installed/updated directly in JupyterLab. Please consult the great wealth of free documentation for JupyterLab at .

A bank of JupyterLab scripts to run the codes for this book is available at the companion website . Let’s get to the fun and the business of finance and banking!

Назад: List of Figures
Дальше: Part I Money and the Government