Algorithmic Short Selling with Python
Refine your algorithmic trading edge, consistently generate investment ideas, and build a robust long/short product
Laurent Bernut, Michael Covel
- 376 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Algorithmic Short Selling with Python
Refine your algorithmic trading edge, consistently generate investment ideas, and build a robust long/short product
Laurent Bernut, Michael Covel
About This Book
Leverage Python source code to revolutionize your short selling strategy and to consistently make profits in bull, bear, and sideways marketsKey Features⢠Understand techniques such as trend following, mean reversion, position sizing, and risk management in a short-selling context⢠Implement Python source code to explore and develop your own investment strategy⢠Test your trading strategies to limit risk and increase profitsBook DescriptionIf you are in the long/short business, learning how to sell short is not a choice. Short selling is the key to raising assets under management. This book will help you demystify and hone the short selling craft, providing Python source code to construct a robust long/short portfolio. It discusses fundamental and advanced trading concepts from the perspective of a veteran short seller. This book will take you on a journey from an idea ("buy bullish stocks, sell bearish ones") to becoming part of the elite club of long/short hedge fund algorithmic traders. You'll explore key concepts such as trading psychology, trading edge, regime definition, signal processing, position sizing, risk management, and asset allocation, one obstacle at a time. Along the way, you'll will discover simple methods to consistently generate investment ideas, and consider variables that impact returns, volatility, and overall attractiveness of returns. By the end of this book, you'll not only become familiar with some of the most sophisticated concepts in capital markets, but also have Python source code to construct a long/short product that investors are bound to find attractive.What you will learn⢠Develop the mindset required to win the infinite, complex, random game called the stock market⢠Demystify short selling in order to generate alpa in bull, bear, and sideways markets⢠Generate ideas consistently on both sides of the portfolio⢠Implement Python source code to engineer a statistically robust trading edge⢠Develop superior risk management habits⢠Build a long/short product that investors will find appealingWho this book is forThis is a book by a practitioner for practitioners. It is designed to benefit a wide range of people, including long/short market participants, quantitative participants, proprietary traders, commodity trading advisors, retail investors (pro retailers, students, and retail quants), and long-only investors.At least 2 years of active trading experience, intermediate-level experience of the Python programming language, and basic mathematical literacy (basic statistics and algebra) are expected.
Frequently asked questions
Information
5
Regime Definition
- Importing libraries
- Creating a charting function
- Breakout/breakdown
- Moving averages
- Higher highs/higher lows
- Floor/ceiling
- Methodology comparison
- Let the market regime dictate the best strategy
Importing libraries
pandas
, numpy
, yfinance
, and matplotlib
libraries. We will also be working with find_peaks
from the ScientificPython library. # Import Libraries import pandas as pd import numpy as np import yfinance as yf %matplotlib inline import matplotlib.pyplot as plt from scipy.signal import find_peaks
Creating a charting function
graph_regime_combo
. The parameters will gradually make sense as we unveil each method.rg
variable, or not. If floor/ceiling is present, then it supersedes everything else. If not, the other two methods (breakout and moving average crossover) are printed. The ax1.fill_between
method identifies the boundaries. Read all of them to understand the conditions. The rest is uneventful:#### Graph Regimes #### def graph_regime_combo(ticker,df,_c,rg,lo,hi,slo,shi,clg,flr,rg_ch, ma_st,ma_mt,ma_lt,lt_lo,lt_hi,st_lo,st_hi): ''' https://www.color-hex.com/color-names.html ticker,df,_c: _c is closing price rg: regime -1/0/1 using floor/ceiling method lo,hi: small, noisy highs/lows slo,shi: swing lows/highs clg,flr: ceiling/floor rg_ch: regime change base ma_st,ma_mt,ma_lt: moving averages ST/MT/LT lt_lo,lt_hi: range breakout High/Low LT st_lo,st_hi: range breakout High/Low ST ''' fig = plt.figure(figsize=(20,8)) ax1 = plt.subplot2grid((1,1), (0,0)) date = df.index close = df[_c] ax1.plot_date(df.index, close,'-', color='k', label=ticker.upper()) try: if pd.notnull(rg): base = df[rg_ch] regime = df[rg] #### removed for brevity: check GitHub repo for full code #### for label in ax1.xaxis.get_ticklabels(): label.set_rotation(45) ax1.grid(True) ax1.xaxis.label.set_color('k') ax1.yaxis.label.set_color('k') plt.xlabel('Date') plt.ylabel(str.upper(ticker) + ' Price') plt.title(str.upper(ticker)) plt.legend() #### Graph Regimes Combo ####
Breakout/breakdown
"Kites rise highest against the windânot with it."â Winston Churchill