Cover Page....2
Table of Contents....3
Preface....4
Part 1: Introduction to FX Trading Strategy Development....13
Chapter 1: Developing Trading Strategies – Why They Are Different....14
Trading strategies – it’s all about how you manage risk....16
Automated trading – operational risk and regulatory limitations....19
Retrieving market data – quality and consistency as keys to success....21
Making actual trading decisions – trading logic and credit risk....25
Ordering – transactional risk....27
The general architecture of a trading application....28
Summary....28
Chapter 2: Using Python for Trading Strategies....30
Technical requirements....31
The advantages of using Python in trading strategy development....31
Modeling – forecasting the future doesn’t necessarily mean practical benefits....38
Paper trading and backtesting – an essential part of a systemic trader’s risk management....40
The disadvantages of using Python in trading strategy development....45
Live trading – where Python faces its limits....47
Summary....48
Chapter 3: FX Market Overview from a Developer's Standpoint....49
Trading venues – where money meets… other money....50
Trade mechanics – again, some terminology....62
Market makers – comfortable, sophisticated, expensive....65
Liquidity providers – the whales that support this planet....72
ECN – looks like a fair game, but is it?....76
Aggregation – in search of the best price....80
Trading the FX market – what and how....82
Why do I need all this?....89
Summary....90
Part 2: General Architecture of a Trading Application and A Detailed Study of Its Components....92
Chapter 4: Trading Application: What’s Inside?....93
Technical requirements....94
Have your app talk to the world – the gloomy world of communication protocols....94
Retrieving data – garbage in, garbage out....107
Trading logic – this is where a small mistake may cost a fortune....115
Risk management – your safety belt....117
Ordering – make sure you are understood correctly....118
Summary....119
Chapter 5: Retrieving and Handling Market Data with Python....120
Navigating through data....120
Data compression – keeping the amounts to a reasonable minimum....132
Working with saved and live data – keeping your app universal....145
Summary....157
Chapter 6: Basics of Fundamental Analysis and Its Possible Use in FX Trading....158
Fundamental analysis – intuitive but of little practical use....159
Economic news....159
Economic news from a fundamental analysis perspective....166
Political events....167
Industry-specific information....170
Summary....173
Chapter 7: Technical Analysis and Its Implementation in Python....175
Technical analysis – ideal for computing, but missing real market processes....176
Implementation of TA indicators in Python....205
Summary....216
Chapter 8: Data Visualization in FX Trading with Python....218
Technical requirements....218
The basics of charting with Python....219
Simple plots of market data....226
Visualizing static market data with pandas....235
Visualizing live market data....243
Adding objects to price charts....256
Summary....259
Part 3: Orders, Trading Strategies, and Their Performance....261
Chapter 9: Trading Strategies and Their Core Elements....262
Alpha and beta – widely used, widely confused....263
Options – stable income with unlimited risk....273
Alpha classics – trend-following, mean reversion, breakout, and momentum....276
Arbitrage – let’s earn from others’ mistakes....286
Statistical arbitrage....288
Event-driven trading strategies....291
Market-making – profiting on liquidity provision and associated risks....291
High frequency, low latency – where Python fails....292
Summary....293
Chapter 10: Types of Orders and Their Simulation in Python....295
Order ticket – what you send is what you get....296
Market orders – the way to get maximum control over transactional risk....299
Limit orders – guaranteed price, but not execution....303
Time in force – better control over execution....307
Stop orders – maximum uncontrolled risk....310
Compound orders....315
Summary....316
Chapter 11: Backtesting and Theoretical Performance....317
Trading app architecture – revised and improved....317
Multithreading – convenient but full of surprises....331
Trading application with live data feed....333
Backtesting – speeding up the research....346
Summary – where do we go now?....364
Part 4: Strategies, Performance Analysis, and Vistas....367
Chapter 12: Sample Strategy – Trend-Following....368
Trend-following revisited – trading setup....368
Choosing the market and preparing data....377
Trend-following strategy – implementation....384
Summary....387
Chapter 13: To Trade or Not to Trade – Performance Analysis....389
Trade analysis....390
Average trade and trading costs....390
Measuring performance – alpha and beta revisited....400
Net profit versus buy and hold....409
Drawdown....412
The power of leverage – how much do I need to trade it?....420
Summary....423
Chapter 14: Where to Go Now?....425
Implementing limit and stop orders....426
The correct way to calculate the number of trades....434
From trading ideas to implementation – another sample strategy using limit and stop orders....438
Money management and multiple entries....445
Strategy performance revisited – more metrics....448
More about the risks specific to algo trading....449
Classical technical trading setups....450
Optimization – the blessing and the curse of algo trading....452
Final words....454
Index....455
Why subscribe?....474
Other Books You May Enjoy....475
Packt is searching for authors like you....478
Share Your Thoughts....478
Download a free PDF copy of this book....478
Algorithm-based trading is a popular choice for Python programmers due to its apparent simplicity. However, very few traders get the results they want, partly because they aren't able to capture the complexity of the factors that influence the market. Getting Started with Forex Trading Using Python helps you understand the market and build an application that reaps desirable results.
The book is a comprehensive guide to everything that is market-related: data, orders, trading venues, and risk. From the programming side, you'll learn the general architecture of trading applications, systemic risk management, de-facto industry standards such as FIX protocol, and practical examples of using simple Python codes. You'll gain an understanding of how to connect to data sources and brokers, implement trading logic, and perform realistic tests. Throughout the book, you'll be encouraged to further study the intricacies of algo trading with the help of code snippets.
By the end of this book, you'll have a deep understanding of the fx market from the perspective of a professional trader. You'll learn to retrieve market data, clean it, filter it, compress it into various formats, apply trading logic, emulate the execution of orders, and test the trading app before trading live.
This book is for financial traders and python developers who are interested in forex trading. Academic researchers looking to focus on practical applications will find this book useful. This book can also help established fx market professionals who want to take the first steps in algo trading. Familiarity with Python and object-oriented programming within the scope of an online course or self-study is a must. Knowledge of network protocols and interfaces is a plus but not a prerequisite, as is specific knowledge about markets and trading.