Ultimate Python for Fintech Solutions
()
About this ebook
Creating Next Gen Apps in Finance
Key Features
● Master the Python libraries and packages essential for financial applications, enabling robust development.
● Utilize Python for developing applications that process financial information, visualize data in diverse formats, and create
Related to Ultimate Python for Fintech Solutions
Related ebooks
Financial Data Science with Python: An Integrated Approach to Analysis, Modeling, and Machine Learning Rating: 0 out of 5 stars0 ratingsUltimate Python Libraries for Data Analysis and Visualization Rating: 0 out of 5 stars0 ratingsUltimate Web Authentication Handbook Rating: 0 out of 5 stars0 ratingsUltimate Docker for Cloud Native Applications Rating: 0 out of 5 stars0 ratingsUltimate Web Automation Testing with Cypress Rating: 0 out of 5 stars0 ratingsUltimate Certified Kubernetes Administrator (CKA) Certification Guide Rating: 0 out of 5 stars0 ratingsUltimate Microservices with RabbitMQ Rating: 0 out of 5 stars0 ratingsUltimate Modern jQuery for Web App Development Rating: 0 out of 5 stars0 ratingsUltimate Flutter Handbook: Learn Cross-Platform App Development with Visually Stunning UIs and Real-World Projects Rating: 0 out of 5 stars0 ratingsAndroid Studio Ladybug Essentials - Java Edition: Developing Android Apps Using Android Studio Ladybug and Java Rating: 0 out of 5 stars0 ratingsThe JavaScript Journey: From Basics to Full-Stack Mastery Rating: 0 out of 5 stars0 ratingsUltimate Nuxt.js for Full-Stack Web Applications Rating: 0 out of 5 stars0 ratings50 Python Concepts Every Developer Should Know Rating: 0 out of 5 stars0 ratingsUltimate Snowflake Architecture for Cloud Data Warehousing Rating: 0 out of 5 stars0 ratingsBackbone.js Patterns and Best Practices Rating: 0 out of 5 stars0 ratingsJava Persistence with NoSQL: Revolutionize your Java apps with NoSQL integration (English Edition) Rating: 0 out of 5 stars0 ratingsUltimate Node.js for Cross-Platform App Development Rating: 0 out of 5 stars0 ratingsUltimate Machine Learning with Scikit-Learn Rating: 0 out of 5 stars0 ratingsRediscovering Redis: Mastering Data Management Rating: 0 out of 5 stars0 ratingsMastering Amazon Web Services: Essential AWS Techniques Rating: 0 out of 5 stars0 ratingsGitHub Actions Cookbook: A practical guide to automating repetitive tasks and streamlining your development process Rating: 0 out of 5 stars0 ratingsUltimate Ember.js for Web App Development Rating: 0 out of 5 stars0 ratingsModern API Design with gRPC Rating: 0 out of 5 stars0 ratings
Programming For You
JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Learn Python in 10 Minutes Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5PYTHON PROGRAMMING Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsAlgorithms For Dummies Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5Godot from Zero to Proficiency (Foundations): Godot from Zero to Proficiency, #1 Rating: 5 out of 5 stars5/5Beginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5
Reviews for Ultimate Python for Fintech Solutions
0 ratings0 reviews
Book preview
Ultimate Python for Fintech Solutions - Bhagvan Kommadi
CHAPTER 1
Getting Started on Python Infrastructure and Building Financial Apps
Introduction
This chapter will introduce the reader to Python Deployment, Anaconda, Python Quant Platform, and other tools such as IPython. The reader will be presented with examples to deploy and execute code to see the results. Python is easy to learn and has a wide range of popular open source frameworks. In fintech, Python is becoming a popular choice as more and more developers are choosing python to develop apps. New technologies like AI, Machine learning, Big data and IOT are being used in Fintech first because most of these tech frameworks are python based.
The many popular tech stacks in Python consist of Django, Django rest framework, Fast API, Flask, Pyramid, Bottle, and others. Most of the fintech popular tech stacks have the JavaScript frameworks as the presentation layer. They are Angular.js, React.js, and Vue.js. The backend is in REST API which can be DRF/Fast API or any other language based REST API.
Structure
In this chapter, we will discuss the following topics:
Python Installation
Anaconda
Python Quant Platform
Tools – Ipython
Figure 1.1: Python Infrastructure Topics
Python Installation
To begin, let us look at the process of installing Python. The setup requires Python 3.9.7, as the code examples will be based on this version of Python. Python software can be downloaded in accordance with the operating system and is available at: https://www.python.org/downloads/release/python-397/.
Figure 1.2: Python Execution Options
Now let us look at all Python execution options as shown in Figure 1.2.
Python Compiler and Executable
After installation, the version of the Python installed can be checked with the following command:
python3 --version
The output, after executing the preceding command, is as follows:
(base) apples-MacBook-Air:code bhagvan.kommadi$ python3 --version
Python 3.9.7
(base) apples-MacBook-Air:code bhagvan.kommadi$
You can test the initial Python program with the following code:
first_program.py
print(python program is working
)
def printString():
print(method print string working
)
if __name__==__main__
:
printString()
The preceding code can be executed using the following command:
python3 first_program.py
The output after executing the preceding command is as follows:
(base) apples-MacBook-Air:code bhagvan.kommadi$ ls
first_program.py
(base) apples-MacBook-Air:code bhagvan.kommadi$ python3 first_program.py
python program is working
method print string working
(base) apples-MacBook-Air:code bhagvan.kommadi$
Figure 1.3: Python Interpreter and Compiler
Figure 1.3 shows how a Python compiler interacts with code and bytecode through an interpreter to a Virtual machine.
JupyterLab
The commands for installing and launching JupyterLab are as follows:
pip3 install jupyterlab
jupyterlab
The output after executing the preceding command is as follows:
(base) apples-MacBook-Air:~ bhagvan.kommadi$ jupyter-lab
[I 2023-07-20 23:23:41.583 ServerApp] jupyterlab | extension was successfully linked.
[I 2023-07-20 23:23:41.584 ServerApp] jupytext | extension was successfully linked.
[I 2023-07-20 23:23:42.348 ServerApp] nbclassic | extension was successfully linked.
The output is shown in Figure 1.4.
Figure 1.4: Jupyter Notebook
A Jupyter notebook can be created by clicking the File Menu.
Figure 1.5: Jupyter Notebook Execution
Figure 1.5 shows the Jupyter Notebook code and the output when the Jupyter Notebook is executed.
Figure 1.6: Jupyter Notebook Naming
Rename the notebook as First Notebook.ipynb.
PipEnv – Python Environment
You can install pipenv using the following command:
Pip3 install --user pipenv
users_api.py
import requests
response = requests.get('https://reqres.in/api/users?page=2')
print (users list json
,response.json())
The preceding code can be executed using the following command:
pipenv install requests
The output, after executing the preceding command, is as follows:
(base) apples-MacBook-Air:pipenv_example bhagvan.kommadi$ pipenv install requests
Creating a virtualenv for this project…
The preceding code can be executed using the following command:
python3 users_api.py
The output after executing the preceding command is as follows:
(base) apples-MacBook-Air:pipenv_example bhagvan.kommadi$ pipenv run python3 users_api.py
users list json {'page': 2, 'per_page': 6, 'total': 12, 'total_pages': 2, 'data': [{'id': 7, 'email': '[email protected]', 'first_name': 'Michael', 'last_name': 'Lawson', 'avatar': 'https://reqres.in/img/faces/7-image.jpg'}, {'id': 8, 'email': '[email protected]', 'first_name': 'Lindsay', 'last_name': 'Ferguson', 'avatar': 'https://reqres.in/img/faces/8-image.jpg'}, {'id': 9, 'email': '[email protected]', 'first_name': 'Tobias', 'last_name': 'Funke', 'avatar': 'https://reqres.in/img/faces/9-image.jpg'}, {'id': 10, 'email': '[email protected]', 'first_name': 'Byron', 'last_name': 'Fields', 'avatar': 'https://reqres.in/img/faces/10-image.jpg'}, {'id': 11, 'email': '[email protected]', 'first_name': 'George', 'last_name': 'Edwards', 'avatar': 'https://reqres.in/img/faces/11-image.jpg'}, {'id': 12, 'email': '[email protected]', 'first_name': 'Rachel', 'last_name': 'Howell', 'avatar': 'https://reqres.in/img/faces/12-image.jpg'}], 'support': {'url': 'https://reqres.in/#support-heading', 'text': 'To keep ReqRes free, contributions towards server costs are appreciated!'}}
Figure 1.7: PipEnv Usecase
PipEnv can be used for different projects with different Python environments.
Virtual Env – Python Environment
You can install pipenv using the following command:
python3 -m pip install --user virtualenv
Now you can create a virtual environment using the following command:
python3 -m venv requestsenv
You can activate the requestenv environment by using the following command:
source requestsenv/bin/activate
The output after executing the preceding command is as follows:
(base) apples-MacBook-Air:venv_example bhagvan.kommadi$ python3 -m venv requestsenv
(base) apples-MacBook-Air:venv_example bhagvan.kommadi$ source requestsenv/bin/activate
(requestsenv) (base) apples-MacBook-Air:venv_example bhagvan.kommadi$ which python
/Users/bhagvan.kommadi/OldDesk/orange/Manuscript/chapter1/code/venv_example/requestsenv/bin/python
(requestsenv) (base) apples-MacBook-Air:venv_example bhagvan.kommadi$
Now, let us look at the code that needs to be executed. This is an example of the user’s API, enhanced with logging capability.
users_api_with_logging.py
import requests
import logging
import sys
def getUsers():
response = requests.get('https://reqres.in/api/users?page=2')
#print (users list json
,response.json())
logging.getLogger(usersapi
).debug(users list
,response.json())
if __name__ == __main__
:
logging.basicConfig(format=%(levelname)s - %(name)s - %(message)s
, level=logging.DEBUG)
logging.getLogger(usersapi
).setLevel(logging.DEBUG)
getUsers()
The preceding code can be executed using the following command:
pip3 install requests
python3 users_api_with_logging.py
The output after executing the preceding command is as follows:
(requestsenv) (base) apples-MacBook-Air:venv_example bhagvan.kommadi$ python3 users_api_with_logging.py
DEBUG - urllib3.connectionpool - Starting new HTTPS connection (1): reqres.in:443
DEBUG - urllib3.connectionpool - https://reqres.in:443 GET /api/users?page=2 HTTP/1.1
200 None
DEBUG - usersapi - users list
(requestsenv) (base) apples-MacBook-Air:venv_example bhagvan.kommadi
Figure 1.8: VirtualEnv Use Case
VirtualEnv can be used in multiple projects with different requirements and different Python versions.
Docker – Python Environment
You can first create a docker file, which is outlined as follows:
FROM python:3
WORKDIR /pythonapp
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .
CMD [ python3
, ./first_program.py
]
You can test your first Python program using the following code:
first_program.py
print(python program is working
)
def printString():
print(method print string working
)
if __name__==__main__
:
printString()
The preceding code can be executed using the following command:
docker build -t python-app.
docker run -it --rm --name run_python-app python-app
The output after executing the preceding command is as follows:
(requestsenv) (base) apples-MacBook-Air:docker_example bhagvan.kommadi$ docker build -t python-app.
Sending build context to Docker daemon 11.26kB
Step 1/7 : FROM python:3
---> 608c79ebc6d5
Step 2/7 : WORKDIR /pythonapp
---> Using cache
---> 78a0f6338f9a
Step 3/7 : COPY requirements.txt ./
---> Using cache
---> 28d9db138c8d
Step 4/7 : COPY pythonapp/first_program.py ./
---> 5bbde520d8f9
Step 5/7 : RUN pip3 install --no-cache-dir -r requirements.txt
---> Running in bafc78565b44
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behavior with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[notice] A new release of pip is available: 23.1.2 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
Removing intermediate container bafc78565b44
---> 973a2458737f
Step 6/7 : COPY . .
---> f7039ce59d4b
Step 7/7 : CMD [ python3
, ./first_program.py
]
---> Running in b708d12f6aad
Removing intermediate container b708d12f6aad
---> cfac745dffa6
Successfully built cfac745dffa6
Successfully tagged python-app:latest
(requestsenv) (base) apples-MacBook-Air:docker_example bhagvan.kommadi$ docker run -it --rm --name run_python-app python-app
python program is working
method print string working
(requestsenv) (base) apples-MacBook-Air:docker_example bhagvan.kommadi$
Figure 1.9: Docker Use Case
Docker can be used in projects running on different operating systems. Like Virtual env, it can also handle different requirements.
Anaconda
You can download the Anaconda installer package for your operating system from the provided link : https://www.anaconda.com/download#macos.
Figure 1.10: Anaconda Web Page
Installation can be verified by searching for anaconda in the search bar, as shown in Figure 1.11: