Book description
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.
Table of contents
- Title Page
- Copyright and Credits
- About Packt
- Contributors
- Preface
-
Handling and Manipulating Date, Time, and Time Series Data
- Technical requirements
- Creating datetime objects
- Creating timedelta objects
- Operations on datetime objects
- Modifying datetime objects
- Converting a datetime object to a string
- Creating a datetime object from a string
- The datetime object and time zones
- Creating a pandas.DataFrame object
- DataFrame manipulation—renaming, rearranging, reversing, and slicing
- DataFrame manipulation—applying, sorting, iterating, and concatenating
- Converting a DataFrame into other formats
- Creating a DataFrame from other formats
-
Stock Markets - Primer on Trading
- Technical requirements
- Setting up Python connectivity with the broker
- Querying a list of instruments
- Fetching an instrument
- Querying a list of exchanges
- Querying a list of segments
- Knowing other attributes supported by the broker
- Placing a simple REGULAR order
- Placing a simple BRACKET order
- Placing a simple DELIVERY order
- Placing a simple INTRADAY order
- Querying margins and funds
- Calculating the brokerage charged
- Calculating the government taxes charged
-
Fetching Financial Data
- Technical requirements
- Fetching the list of financial instruments
- Attributes of a financial instrument
- Expiry of financial instruments
- Circuit limits of a financial instrument
- The market depth of a financial instrument
- The total pending buy quantity of a financial instrument
- The total pending sell quantity of a financial instrument
- The total volume traded for the day of a financial instrument
- The last traded price of a financial instrument
- The last traded time of a financial instrument
- The last traded quantity of a financial instrument
- The recorded open price of the day of a financial instrument
- The recorded highest price of the day of a financial instrument
- The recorded lowest price of the day of a financial instrument
- The recorded close price of the last traded day of a financial instrument
-
Computing Candlesticks and Historical Data
- Technical requirements
- Fetching historical data using the broker API
- Fetching historical data using the Japanese (OHLC) candlestick pattern
- Fetching the Japanese candlestick pattern with variations in candle intervals
- Fetching historical data using the Line Break candlestick pattern
- Fetching historical data using the Renko candlestick pattern
- Fetching historical data using the Heikin-Ashi candlestick pattern
- Fetching historical data using Quandl
-
Computing and Plotting Technical Indicators
- Technical requirements
- Trend indicators – simple moving average
- Trend indicators – exponential moving average
- Trend indicators – moving average convergence divergence
- Trend indicators – parabolic stop and reverse
- Momentum indicators – relative strength index
- Momentum indicators – stochastic oscillator
- Volatility indicators – Bollinger Bands
- Volatility indicators – average true range
- Volume indicators – on balance volume
- Volume indicators – volume-weighted average price
- Placing Regular Orders on the Exchange
- Placing Bracket and Cover Orders on the Exchange
-
Algorithmic Trading Strategies - Coding Step by Step
- Technical requirements
- EMA-Regular-Order strategy – coding the __init__, initialize, name, and versions_supported methods
- EMA-Regular-Order strategy – coding the strategy_select_instruments_for_entry method
- EMA-Regular-Order strategy – coding the strategy_enter_position method
- EMA-Regular-Order strategy – coding the strategy_select_instruments_for_exit method
- EMA-Regular-Order strategy – coding the strategy_exit_position method
- EMA-Regular-Order strategy – uploading the strategy on the AlgoBulls trading platform
- MACD-Bracket-Order strategy – coding the __init__, initialize, name, and versions_supported methods
- MACD-Bracket-Order strategy – coding the strategy_select_instruments_for_entry method
- MACD-Bracket-Order strategy – coding the strategy_enter_position method
- MACD-Bracket-Order strategy – coding the strategy_select_instruments_for_exit method
- MACD-Bracket-Order strategy – coding the strategy_exit_position method
- MACD-Bracket-Order strategy — uploading the strategy on the AlgoBulls trading platform
-
Algorithmic Trading - Backtesting
- Technical requirements
- EMA-Regular-Order strategy – fetching the strategy
- EMA-Regular-Order strategy – backtesting the strategy
- EMA-Regular-Order strategy – fetching backtesting logs in real time
- EMA-Regular-Order strategy – fetching a backtesting report – profit and loss table
- EMA-Regular-Order strategy — fetching a backtesting report – statistics table
- EMA-Regular-Order strategy – fetching a backtesting report – order history
- MACD-Bracket-Order strategy – fetching the strategy
- MACD-Bracket-Order strategy – backtesting the strategy
- MACD-Bracket-Order strategy – fetching backtesting logs in real time
- MACD-Bracket-Order strategy – fetching a backtesting report – profit and loss table
- MACD-Bracket-Order strategy – fetching a backtesting report – statistics table
- MACD-Bracket-Order strategy – fetching a backtesting report – order history
-
Algorithmic Trading - Paper Trading
- Technical requirements
- EMA-Regular-Order strategy – fetching the strategy
- EMA-Regular-Order strategy – paper trading the strategy
- EMA-Regular-Order strategy – fetching paper trading logs in real time
- EMA-Regular-Order strategy – fetching a paper trading report – profit and loss table
- EMA-Regular-Order strategy – fetching a paper trading report – statistics table
- EMA-Regular-Order strategy – fetching a paper trading report – order history
- MACD-Bracket-Order strategy – fetching the strategy
- MACD-Bracket-Order strategy – paper trading the strategy
- MACD-Bracket-Order strategy – fetching paper trading logs in real time
- MACD-Bracket-Order strategy – fetching a paper trading report – profit and loss table
- MACD-Bracket-Order strategy – fetching a paper trading report – statistics table
- MACD-Bracket-Order strategy – fetching a paper trading report – order history
-
Algorithmic Trading - Real Trading
- Technical requirements
- EMA–Regular–Order strategy – fetching the strategy
- EMA–Regular–Order strategy – real trading the strategy
- EMA–Regular–Order strategy – fetching real trading logs in real time
- EMA–Regular–Order strategy – fetching a real trading report – profit and loss table
- EMA–Regular–Order strategy – fetching a real trading report – statistics table
- MACD–Bracket–Order strategy – fetching the strategy
- MACD–Bracket–Order strategy – real trading the strategy
- MACD–Bracket–Order strategy – fetching real trading logs in real time
- MACD–Bracket–Order strategy – fetching a real trading report – profit and loss table
- MACD–Bracket–Order strategy – fetching a real trading report – statistics table
-
Appendix I
-
Setting up your Zerodha account
- Opening a Zerodha account online
- Logging in to the Zerodha trading platform website
- Setting up your Zerodha Developer Options account
- Logging in to the Zerodha Developer Options website
- Purchasing and enabling the Zerodha Developer Options API
- Testing API keys and authorizing the app by firing your first API call
-
Setting up your Zerodha account
- Appendix II
- Appendix III
- Other Books You May Enjoy
Product information
- Title: Python Algorithmic Trading Cookbook
- Author(s):
- Release date: August 2020
- Publisher(s): Packt Publishing
- ISBN: 9781838989354
You might also like
video
Hands-On Algorithmic Trading with Python
The pace of automation in the investment management industry has become frenetic in the last decade …
book
Python for Algorithmic Trading
Algorithmic trading, once the exclusive domain of institutional players, is now open to small organizations and …
book
Time Series Analysis with Python Cookbook
Perform time series analysis and forecasting confidently with this Python code bank and reference manual Key …
book
Python Automation Cookbook - Second Edition
Get a firm grip on the core processes including browser automation, web scraping, Word, Excel, and …