Python Algorithmic Trading Cookbook
eBook - ePub

Python Algorithmic Trading Cookbook

All the recipes you need to implement your own algorithmic trading strategies in Python

Pushpak Dagade

  1. 542 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Python Algorithmic Trading Cookbook

All the recipes you need to implement your own algorithmic trading strategies in Python

Pushpak Dagade

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Python Algorithmic Trading Cookbook als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Python Algorithmic Trading Cookbook von Pushpak Dagade im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Ciencia de la computación & Aplicaciones de escritorio. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Computing Candlesticks and Historical Data
The historical data of a financial instrument is data about all the past prices at which a financial instrument was brought or sold. An algorithmic trading strategy is always vpot_candlestickirtually executed on historical data to evaluate its past performance before it's deployed with real money. This process is called backtesting. Historical data is quintessential for backtesting (covered in detail in Chapter 8, Backtesting Strategies). Also, historical data is needed for computing technical indicators (covered in detail in Chapter 5, Computing and Plotting Technical Indicators), which help in making buy-or-sell decisions in real-time. Candlestick patterns are widely used tools for stock analysis. Various types of candlestick patterns are commonly used by analysts. This chapter provides recipes that show you how to fetch historical data using broker APIs, how to fetch and compute multiple candlestick patterns Japanese (open-high-low-close (OHLC)), Line Break, Renko, and Heikin-Ashi and how to fetch historical data using a third-party tool.
In this chapter, we will cover the following recipes:
  • 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
Let's get started!

Technical requirements

You will need the following to successfully execute the recipes in this chapter:
  • Python 3.7+
  • Python packages:
  • pyalgotrading ($ pip install pyalgotrading)
  • quandl ($pip install quandl) this is optional and only needed for the last recipe
The latest Jupyter Notebook for this chapter can be found on GitHub at https://github.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/tree/master/Chapter04.
The following code will help you set up the broker connection with Zerodha, which will be used by all the recipes in this chapter. Please make sure you have followed these steps before trying out any of the recipes provided.
The first thing you need to do to set connectivity with the broker is to gather the required API keys. The broker provides unique keys to each customer, typically as api-key and api-secret key pairs. These API keys are chargeable, usually on a monthly subscription basis. You need to get your copies of api-key and api-secret from the broker website before you start this chapter. You can refer to Appendix I for more details.
Execute the following steps:
  1. Import the necessary modules:
>>> from pyalgotrading.broker.broker_connection_zerodha import BrokerConnectionZerodha
  1. 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)
You will get the following URL:
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
If you are running this for the first time and kiteconnect is not installed, pyalgotrading will automatically install it for you. The final output of step 2 will be a link. Click on the link and log in with your Zerodha credentials. If the authentication is successful, you will see a link in your browser's address bar similar to https://127.0.0.1/?request_token=&action=login&status=success.
For example:
https://127.0.0.1/?request_token=H06I6Ydv95y23D2Dp7NbigFjKweGwRP7&action=login&status=success
  1. Copy the alphanumeric token and paste it into request_token:
>>> request_token = "<your-request-token>"
>>> broker_connection.set_access_token(request_token)
The broker_connection instance is now ready for performing API calls.
The pyalgotrading package supports multiple brokers and provides a connection object class per broker, with the same methods. It abstracts broker APIs behind a unified interface so that users don't need to worry about the underlying broker API calls and use all the recipes in this chapter as-is.

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

The historical data of a financial instrument is time-series data for the timestamps in the past. It can be fetched using the Broker API for a given duration. This ...

Inhaltsverzeichnis