Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with Forex Trading Using Python

You're reading from  Getting Started with Forex Trading Using Python

Product type Book
Published in Mar 2023
Publisher Packt
ISBN-13 9781804616857
Pages 384 pages
Edition 1st Edition
Languages
Author (1):
Alex Krishtop Alex Krishtop
Profile icon Alex Krishtop

Table of Contents (21) Chapters

Preface Part 1: Introduction to FX Trading Strategy Development
Chapter 1: Developing Trading Strategies – Why They Are Different Chapter 2: Using Python for Trading Strategies Chapter 3: FX Market Overview from a Developer's Standpoint Part 2: General Architecture of a Trading Application and A Detailed Study of Its Components
Chapter 4: Trading Application: What’s Inside? Chapter 5: Retrieving and Handling Market Data with Python Chapter 6: Basics of Fundamental Analysis and Its Possible Use in FX Trading Chapter 7: Technical Analysis and Its Implementation in Python Chapter 8: Data Visualization in FX Trading with Python Part 3: Orders, Trading Strategies, and Their Performance
Chapter 9: Trading Strategies and Their Core Elements Chapter 10: Types of Orders and Their Simulation in Python Chapter 11: Backtesting and Theoretical Performance Part 4: Strategies, Performance Analysis, and Vistas
Chapter 12: Sample Strategy – Trend-Following Chapter 13: To Trade or Not to Trade – Performance Analysis Chapter 14: Where to Go Now? Index Other Books You May Enjoy

Trading strategies – it’s all about how you manage risk

Let’s start from the beginning by giving definitions. I know it sounds like an academic textbook, but I promise that it’s going to get more and more interesting very quickly.

According to the definition provided by Cambridge Dictionary, trade is "the activity of buying and selling, or exchanging, goods and/or services between people or countries.” This means that if I exchange my money for meat or vegetables, then I am at a grocery market. If I exchange my money for obligations to buy or sell live cattle or wheat in the future, then I am in a derivatives market. And if I exchange my money for another type of money, I am in the foreign exchange, forex or FX market.

What I buy and sell in a particular market is called an asset. If I buy or sell something that can be delivered (wheat, gold, stocks, or even money) it’s called the underlying. If I buy or sell an obligation or the right to buy or sell the underlying at a certain price in the future, then it’s called a derivative.

Underlying and derivatives are traded at trading venues – previously, physical locations such as exchanges, but today, more electronic networks where traders, liquidity providers, market makers, and other market participants match their orders.

If I went to a grocery market to sell potatoes, then I am on the sell side. If I came to buy potatoes, I am on the buy side. In financial markets, buy-side market participants are mostly referred to as price takers (because they can only take prices offered by the sell side), and sell-side market participants are referred to as price givers.

Not all trading venues welcome everyone as a direct participant. Most of them work via a network of brokers – entities that accept orders from their clients and route them to one or more trading venues, possibly internally netting client positions and sometimes even acting as the counterparty for their clients.

In Chapter 3, FX Market Overview from a Developer’s Standpoint, we will consider all these entities in more detail to see why we should pay particular attention to their behavior and how to actually use them to make our trading strategies more robust.

Let’s proceed with a very quick look into the essence of a trading strategy and see the main risks that are natural to the systematic or algo trading business.

Trading strategies – how we make money in financial markets

A trading strategy is a set of rules that tells me when to buy and when to sell the asset if I am on the buy side, or when and how much to offer to the market if I am on the sell side. But in any case, the ultimate goal of a trading strategy is to make money.

If I am on the buy side, I can make money only in the following two ways:

  • I buy low and I sell high, or vice versa (earning on the price difference)
  • I buy and receive dividends

The former is called active trading, and the latter is normally called investing, or getting passive income. In this book, we will consider only active trading.

There are two major classes of active trading strategies on the buy side. The first one is called directional trading and in essence, it’s when we buy, wait, and sell. If we manage to sell at a price greater than the price at which we bought, we make money.

The second class of buy-side trading strategies is arbitrage. Such a strategy identifies moments when the same asset is priced differently at different trading venues (so-called real or pure arbitrage), or when there is a tradable difference between the price of the underlying and a derivative, different derivatives, or even more complex setups that consist of multiple instruments (so-called statistical arbitrage or stat arb).

Sounds a bit overwhelming? Don’t worry, we will now consider each case in more detail.

Trading app – what can be simpler?

At this point, if you have sufficient experience in application development and a reasonable knowledge of markets, you might exclaim the following:

Why do we need all this? It is so easy to build a trading application: you only need to get market data, calculate entry and exit orders, and send them to the broker!

So, the suggested general architecture of a trading application from that standpoint may look as simple as this:

Figure 1.1 – Initial architecture of a trading application

Figure 1.1 – Initial architecture of a trading application

However, as we will see very soon, this is an overly simplified view and it lacks at least one key feature that makes developing trading strategies different from developing other applications: it doesn’t include risk management.

So, what about that risk?

Before discussing ways to make money in trading, let’s first pay closer attention to avoiding losses – at least because according to all statistics, more than 70% of active traders, unfortunately, lose money.

Before we proceed, let me note that the following classification of risks does not fully correspond to official legal and academic classifications. This informal classification is used here for the sake of simplicity, to sort out rather complex matters quickly and with an acceptable degree of comfort.

All risks in active trading can be generally put into three major categories, as follows:

  • Operational risks are those associated with how you place trades and depend on your own business procedures as well as third parties, such as brokers, trading venues, and regulators.
  • Systemic risks are those pertaining to the very market itself and the logic of a trading strategy.
  • Transactional risks are those that make the execution of orders different from expectations; this is the main reason why many strategies that work on paper are unable to make money in reality.

Now that we are a bit more familiar with the idea of a trading strategy and know that the main problem any systematic trader should solve is risk mitigation, let’s dive a little deeper into risks specific to the algo trading business.

You have been reading a chapter from
Getting Started with Forex Trading Using Python
Published in: Mar 2023 Publisher: Packt ISBN-13: 9781804616857
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}