To get the most out of this book
In this book, we attempt to give the readers a high-level overview of various techniques used in the financial domain, while focusing on the practical applications of these methods. That is why we put special emphasis on showing how to use various popular Python libraries to make the work of an analyst or data scientist much easier and less prone to errors.
As the best way to learn anything is by doing, we highly encourage the readers to experiment with the code samples provided (the code can be found in the accompanying GitHub repository), apply the techniques to different datasets, and explore possible extensions (some of them mentioned in the See also sections of the recipes).
For a deeper dive into the theoretical foundations, we provide references for further reading. Those also include even more advanced techniques that are outside of the scope of this book.
Download the example code files
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Python-for-Finance-Cookbook-2E. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/JnpTe.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in text, names of Python libraries, database table names, folder names, filenames, file extensions, and pathnames. For example: “We can also use the get_by_id
function to download a particular CPI series.”
A block of code is set as follows:
def realized_volatility(x):
return np.sqrt(np.sum(x**2))
Any command-line input or output is written as follows:
Downloaded 2769 rows of data.
Bold: Indicates a new term or an important word. For example: “Volume bars are an attempt at overcoming this problem “
Information boxes appear like this.
Tips and tricks appear like this.
Furthermore, at the very beginning of each Jupyter Notebook (available on the book’s GitHub repository), we run a few cells that import and set up plotting with matplotlib
. For brevity’s sake, we will not mention this later on in the book. So at any time, assume that the following commands were executed.
First, we (optionally) increased the resolution of the generated figures using the following snippet:
%config InlineBackend.figure_format = "retina"
Then we execute the second snippet:
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
from pandas.core.common import SettingWithCopyWarning
warnings.simplefilter(action="ignore", category=FutureWarning)
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)
# feel free to modify, for example, change the context to "notebook"
sns.set_theme(context="talk", style="whitegrid",
palette="colorblind", color_codes=True,
rc={"figure.figsize": [12, 8]})
In this cell, we import matplotlib
, warnings
, and seaborn
. Then, we disabled some of the warnings and set up the style of the plots. In some chapters, we might modify these settings for better readability of the figures (especially in black and white).