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

Compartir libro
  1. 542 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Python Algorithmic Trading Cookbook

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

Pushpak Dagade

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Python Algorithmic Trading Cookbook un PDF/ePUB en línea?
Sí, puedes acceder a Python Algorithmic Trading Cookbook de Pushpak Dagade en formato PDF o ePUB, así como a otros libros populares de Informatica y Applicazioni desktop. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2020
ISBN
9781838982515
Edición
1
Categoría
Informatica
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 ...

Índice