
Python Algorithmic Trading Cookbook
All the recipes you need to implement your own algorithmic trading strategies in Python
- 542 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Python Algorithmic Trading Cookbook
All the recipes you need to implement your own algorithmic trading strategies in Python
About this book
Build a solid foundation in algorithmic trading by developing, testing and executing powerful trading strategies with real market data using Python
Key Features
- Build a strong foundation in algorithmic trading by becoming well-versed with the basics of financial markets
- Demystify jargon related to understanding and placing multiple types of trading orders
- Devise trading strategies and increase your odds of making a profit without human intervention
Book Description
If you want to find out how you can build a solid foundation in algorithmic trading using Python, this cookbook is here to help.
Starting by setting up the Python environment for trading and connectivity with brokers, you'll then learn the important aspects of financial markets. As you progress, you'll learn to fetch financial instruments, query and calculate various types of candles and historical data, and finally, compute and plot technical indicators. Next, you'll learn how to place various types of orders, such as regular, bracket, and cover orders, and understand their state transitions. Later chapters will cover backtesting, paper trading, and finally real trading for the algorithmic strategies that you've created. You'll even understand how to automate trading and find the right strategy for making effective decisions that would otherwise be impossible for human traders.
By the end of this book, you'll be able to use Python libraries to conduct key tasks in the algorithmic trading ecosystem.
Note: For demonstration, we're using Zerodha, an Indian Stock Market broker. If you're not an Indian resident, you won't be able to use Zerodha and therefore will not be able to test the examples directly. However, you can take inspiration from the book and apply the concepts across your preferred stock market broker of choice.
What you will learn
- Use Python to set up connectivity with brokers
- Handle and manipulate time series data using Python
- Fetch a list of exchanges, segments, financial instruments, and historical data to interact with the real market
- Understand, fetch, and calculate various types of candles and use them to compute and plot diverse types of technical indicators
- Develop and improve the performance of algorithmic trading strategies
- Perform backtesting and paper trading on algorithmic trading strategies
- Implement real trading in the live hours of stock markets
Who this book is for
If you are a financial analyst, financial trader, data analyst, algorithmic trader, trading enthusiast or anyone who wants to learn algorithmic trading with Python and important techniques to address challenges faced in the finance domain, this book is for you. Basic working knowledge of the Python programming language is expected. Although fundamental knowledge of trade-related terminologies will be helpful, it is not mandatory.
Tools to learn more effectively

Saving Books

Keyword Search

Annotating Text

Listen to it instead
Information
- Fetching historical data using the broker API
- Fetching historical data with the Japanese (OHLC) candlestick pattern
- Fetching the Japanese candlestick pattern with variations in candle intervals
- Fetching historical data with the Line Break candlestick pattern
- Fetching historical data with the Renko candlestick pattern
- Fetching historical data with the Heikin-Ashi candlestick pattern
- Fetching historical data using Quandl
Technical requirements
- Python 3.7+
- Python packages:
- pyalgotrading ($ pip install pyalgotrading)
- quandl ($pip install quandl) this is optional and only needed for the last recipe
- Import the necessary modules:
>>> from pyalgotrading.broker.broker_connection_zerodha import BrokerConnectionZerodha
- Get the api_key and api_secret keys from the broker. These are unique to you and will be used by the broker to identify your Demat account:
>>> api_key = "<your-api-key>"
>>> api_secret = "<your-api-secret>"
>>> broker_connection = BrokerConnectionZerodha(api_key,
api_secret)
Installing package kiteconnect via pip...
Please login to this link to generate your request token: https://kite.trade/connect/login?api_key=<your-api-key>&v=3
https://127.0.0.1/?request_token=H06I6Ydv95y23D2Dp7NbigFjKweGwRP7&action=login&status=success
- Copy the alphanumeric token and paste it into request_token:
>>> request_token = "<your-request-token>"
>>> broker_connection.set_access_token(request_token)
Only the procedure of setting up the broker connection will vary from broker to broker. You can refer to the pyalgotrading documentation to learn how to set up the broker connection if you are not using Zerodha as your broker. For Zerodha users, the aforementioned steps will suffice.
Fetching historical data using the broker API
Table of contents
- Title Page
- Copyright and Credits
- About Packt
- Contributors
- Preface
- Handling and Manipulating Date, Time, and Time Series Data
- Stock Markets - Primer on Trading
- Fetching Financial Data
- Computing Candlesticks and Historical Data
- Computing and Plotting Technical Indicators
- Placing Regular Orders on the Exchange
- Placing Bracket and Cover Orders on the Exchange
- Algorithmic Trading Strategies - Coding Step by Step
- Algorithmic Trading - Backtesting
- Algorithmic Trading - Paper Trading
- Algorithmic Trading - Real Trading
- Appendix I
- Appendix II
- Appendix III
- Other Books You May Enjoy
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app