Algorithmic Short Selling with Python

Book description

Leverage Python source code to revolutionize your short selling strategy and to consistently make profits in bull, bear, and sideways markets

Key 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 profits

Book Description

If 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 appealing

Who this book is for

This 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.

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Get in touch
    5. Share your thoughts
  2. The Stock Market Game
    1. Is the stock market art or science?
    2. How do you win this complex, infinite, random game?
      1. How do you win an infinite game?
      2. How do you beat complexity?
      3. How do you beat randomness?
    3. Playing the short selling game
    4. Summary
  3. 10 Classic Myths About Short Selling
    1. Myth #1: Short sellers destroy pensions
    2. Myth #2: Short sellers destroy companies
    3. Myth #3: Short sellers destroy value
    4. Myth #4: Short sellers are evil speculators
    5. Myth #5: Short selling has unlimited loss potential but limited profit potential
    6. Myth #6: Short selling increases risk
    7. Myth #7: Short selling increases market volatility
    8. Myth #8: Short selling collapses share prices
    9. Myth #9: Short selling is unnecessary during bull markets
    10. Myth #10: The myth of the "structural short"
    11. Summary
  4. Take a Walk on the Wild Short Side
    1. The long side world according to GARP
    2. Structural shorts: the unicorns of the financial services industry
    3. Overcoming learned helplessness
    4. Money "is" made between events that "should" happen
    5. The unique challenges of the short side
      1. Market dynamics: short selling is not a stock-picking contest, but a position-sizing exercise
      2. Scarcity mentality
      3. Asymmetry of information
        1. Stock options and transparency
        2. Sell-side analysts are the guardians of the financial galaxy
    6. Summary
  5. Long/Short Methodologies: Absolute and Relative
    1. Importing libraries
    2. Long/Short 1.0: the absolute method
      1. Ineffective at decreasing correlation with the benchmark
      2. Ineffective at reducing volatility
      3. Little, if any, historical downside protection
      4. Lesser investment vehicle
      5. Laggard indicator
    3. Long/Short 2.0: the relative weakness method
      1. Consistent supply of fresh ideas on both sides
      2. Focus on sector rotation
      3. Provides a low-correlation product
      4. Provides a low-volatility product
      5. Reduces the cost of borrow fees
      6. Provides scalability
      7. Non-confrontational
      8. Currency adjustment becomes an advantage
      9. Other market participants cannot guess your levels
      10. You will look like an investment genius
    4. Summary
  6. Regime Definition
    1. Importing libraries
    2. Creating a charting function
    3. Breakout/breakdown
    4. Moving average crossover
    5. Higher highs/higher lows
    6. The floor/ceiling method
      1. Swing detection
        1. Historical swings and high/low alternation
        2. Establishing trend exhaustion
        3. Putting it all together: regime detection
      2. Regime definition
    7. Methodology comparison
      1. Timing the optimal entry point after the bottom or the peak
      2. Seeing through the fundamental news flow
      3. Recognizing turning points
    8. Let the market regime dictate the best strategy
    9. Summary
  7. The Trading Edge is a Number, and Here is the Formula
    1. Importing libraries
    2. The trading edge formula
      1. Technological edge
      2. Information edge
      3. Statistical edge
    3. A trading edge is not a story
      1. Signal module: entries and exits
        1. Entries: stock picking is vastly overrated
        2. Exits: the transmutation of paper profits into real money
    4. Regardless of the asset class, there are only two strategies
      1. Trend following
      2. Mean reversion
    5. Summary
  8. Improve Your Trading Edge
    1. Blending trading styles
    2. The psychology of the stop loss
      1. Step 1: Accountability
      2. Step 2: Rewire your association with losses
      3. Step 3: When to set a stop loss
      4. Step 4: Pre-mortem: the vaccine against overconfidence
      5. Step 5: Executing stop losses: forgiving ourselves for mistakes
      6. Step 6: What the Zeigarnik effect can teach us about executing stop losses
    3. The science of the stop loss
      1. Stop losses are a logical signal-to-noise issue
      2. Stop losses are a statistical issue
      3. Stop losses are a budgetary issue
    4. Techniques to improve your trading edge
      1. Technique 1: The game of two halves: how to cut losers, ride winners, and maintain conviction while improving your trading edge
      2. Technique 2: Mitigate losses with a trailing stop
      3. Technique 3: the game of two-thirds: time exit and how to trim freeloaders
      4. Technique 4: The profit side: reduce risk and compound returns by taking small profits
      5. Technique 5: Elongate the right tail
      6. Technique 6: Re-entry: Ride your winners by laddering your positions
        1. Final exit: the right tail
        2. Re-entry after a final exit
    5. How to tilt your trading edge if your dominant style is mean reversion
      1. Losses
      2. Profits
      3. Partial exit
      4. Exits
    6. Summary
  9. Position Sizing: Money is Made in the Money Management Module
    1. Importing libraries
    2. The four horsemen of apocalyptic position sizing
      1. Horseman 1: Liquidity is the currency of bear markets
      2. Horseman 2: Averaging down
      3. Horseman 3: High conviction
      4. Horseman 4: Equal weight
    3. Position sizing is the link between emotional and financial capital
    4. A position size your brain can trade
      1. Establishing risk bands
      2. Equity curve oscillator – avoiding the binary effect of classic equity curve trading
    5. Comparing position-sizing algorithms
    6. Refining your risk budget
      1. Risk amortization
      2. False positives
      3. Order prioritization and trade rejection
      4. Game theory in position sizing
    7. Summary
  10. Risk is a Number
    1. Importing libraries
    2. Interpreting risk
    3. Sharpe ratio: the right mathematical answer to the wrong question
    4. Building a combined risk metric
      1. The Grit Index
      2. Common Sense Ratio
      3. Van Tharp's SQN
    5. Robustness score
    6. Summary
  11. Refining the Investment Universe
    1. Avoiding short selling pitfalls
      1. Liquidity and market impact
      2. Crowded shorts
      3. The fertile ground of high dividend yield
      4. Share buybacks
      5. Fundamental analysis
    2. What do investors really want?
      1. Lessons from the 2007 quants debacle
      2. The Green Hornet complex of the long/short industry
      3. Lessons from Bernie Madoff
    3. Summary
  12. The Long/Short Toolbox
    1. Importing libraries
    2. Gross exposure
      1. Portfolio heat
        1. Portfolio heat bands
        2. Tactical deployment
        3. Step-by-step portfolio heat and exposure management
    3. Net exposure
    4. Net beta
      1. Three reasons why selling futures is the junk food of short-selling
        1. Selling futures is a bet on market cap
        2. Selling futures is a bet on beta
        3. Selling futures is an expensive form of laziness
    5. Concentration
      1. Human limitation
      2. Hedges are not tokens
      3. The paradox of low-volatility returns: structural negative net concentration
      4. Practical tips about concentration
        1. Average number of names
        2. Ratio of big to small bets
        3. Keep your powder dry
    6. Other exposures
      1. Sector exposure
      2. Exchange exposure
      3. Factor exposures
    7. Design your own mandate
      1. Step 1: Strategy formalization
        1. The signal module
        2. The money management module
      2. Step 2: Investment objectives
      3. Step 4: Design your own mandate: product, market, fit
      4. Step 5: Record keeping
        1. Entry
        2. Exits
        3. Position sizing
        4. Journaling
      5. Step 5: Refine your mandate
    8. Summary
  13. Signals and Execution
    1. Importing libraries
    2. Timing is money: the importance of timing orders
    3. Order prioritization
      1. Relative prices and absolute execution
      2. Order types
    4. Exits
      1. Stop loss
      2. Pre-mortem
      3. The Zeigarnik effect
      4. Profitable exits
    5. Entry
      1. Rollover: the aikido of bear market rallies
      2. Moving averages
      3. Retracements
      4. Retest
      5. Putting it all together
    6. Summary
  14. Portfolio Management System
    1. Importing libraries
    2. Symptoms of poor portfolio management systems
      1. Ineffective capital allocation
      2. Undermonitored risk detection
      3. High volatility
      4. High correlation
      5. Poor exposure management
    3. Your portfolio management system is your Iron Man suit
      1. Clarity: bypass the left brain
      2. Relevance: the Iron Man auto radio effect
      3. Simplicity: complexity is a form of laziness
      4. Flexibility: information does not translate into decision
    4. Automating the boring stuff
    5. Building a robust portfolio management system
    6. Summary
  15. Appendix: Stock Screening
    1. Import libraries
    2. Define functions
    3. Control panel
    4. Data download and processing
    5. Heatmaps
    6. Individual process
  16. Other Books You May Enjoy
  17. Index

Product information

  • Title: Algorithmic Short Selling with Python
  • Author(s): Laurent Bernut
  • Release date: September 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781801815192