Blog: Building an Automated Trading System From the Comfort of Your Own Home
Building a practical trading system that does the heavy lifting for you.
Disclaimer: Nothing herein is financial advice, or even a recommendation to trade real money. Many platforms exist for simulated trading (paper trading) which can be used for building and developing the strategies discussed. Please use common sense.
Automated Trading, sometimes referred to as algorithmic trading, is becoming more and more popular. Nowadays, it is becoming more and more feasible to set up an algorithmic trading system from the comfort of your home. Up until recently, this was unimaginable.
Automated trading accounts for nearly two-thirds of today’s volume in financial markets. The majority of this is performed by high-frequency trading. In this article we are not proposing an at-home solution for high-frequency trading; this probably is not feasible for most. We are talking about building a strategy and having that strategy automatically work for you.
Imagine you’re an engineer, analyst, or in some other quantitative role as a day job. You certainly possess the skills necessary to develop good strategies. But do you have the time to put these strategies into play, day in and day out? Probably not. That’s where the automated trading system comes into play.
In this article, we will discuss a framework for building the automated system. And then, in following articles, we will build that system, piece-by-piece in Python.
To build an automated trading system (ATS), one must first have a strategy or basket of strategies for stock selection. We’re trying to automate a trader’s thinking. If you can match or outperform index funds year-over-year you are doing something right. You do not need out of this world returns to be a great trader or investor.
Sourcing trading strategies is not the most difficult thing in the world. Of course, your own strategy developed from the ground up that performs well and produces reliable returns is preferable. But oftentimes, some of the best strategies exist in the public sphere. Of course, this runs the risk of washing out returns as the strategy goes mainstream. But oftentimes, solid strategies fly right under the radar.
Here are some websites I frequent that I love to learn from and generate ideas for testing:
- https://seekingalpha.com/ (will certainly have to dig through the mud to find worthwhile strategies, but they’re here, just need to get past some of the less quantitative opinions)
- https://www.hbs.edu/faculty/Pages/browse.aspx?sort=topic — great source for reading various research from professors, browse to desired topic and you can oftentimes find papers that study asset pricing relative to various economic factors
The biggest thing I’ve learned with generating ideas, especially from the first two sites listed, collaboration is so so important. When you have ideas, it is so valuable to discuss those ideas with other intelligent, right-minded individuals. Grounded thinkers can usually point out holes or missing parts of your argument that must first be justified before putting your idea into practice. At these sites listed, you can find all sorts of ideas and approaches that can serve as a baseline for how you develop your strategies.
Understanding the technologies necessary for building your system is obviously a vital first step. At the baseline, you must identify the programming languages, libraries, and tools you will leverage to make your system come together. You need to identify where you will be gathering your data from. You need to identify how you are going to process that data. And you need to understand how you will leverage the technology to put trades into action.
Arguably the hardest part of this architecture is the data source. Fortunately, more and more data sources are being made available every year that are democratizing financial data for non-industry people.
Many algorithmic folks prefer languages like C++ for their high performance and suitability for data-intensive tasks. Personally, I prefer Python because it is what I am comfortable with, and I am not trading on the millisecond time frames that make languages like C++ necessary; although I understand the arguments for it and certainly understand there’s a reason job descriptions at firms like Citadel and Renaissance primarily include C++ (Python is creeping into many of these job descriptions as well).
The trading platform is completely dependent upon your needs. Certain platforms are preferable depending on fee structure, available assets, customer service, and many other factors. Most brokers will have some API for their simulated trading platform that will allow you to send and simulate trades from your language of choice.
It is definitely worth having a section on risk management. It is no doubt that understanding and managing the risk of your strategies is vital. Sure, maybe your strategy had huge returns this year. But was that due to a sound strategy, or was it just lucky returns, garnered by taking on a massive risk profile. There are many discussed industry standards around understanding risk, the most basic of which is standard deviation.
Standard deviation measures the variance between each stock price in a set time period versus the mean stock price over that same period.
Beta provides a measure of the risk of a single asset relative to the entire market. The wider market has a beta of 1. Anything greater than one indicates higher volatility than the market; less than 1 indicates lower volatility than the market. A beta of 1 indicates the asset moves in-step with the wider market.
Value at Risk (VaR) simply measures the probability of loss of an investment provided normal market conditions. For example, if a given portfolio has a one-month 25% VaR of $100,000, this means there is a 25% chance the portfolio will lose 25% of its value in a one-month timeframe. Portfolio managers will want to adjust their portfolio to a VaR that is suitable. For example, someone near retirement would not want a high VaR as they need that money in retirement. Someone with higher risk tolerance may not mind the higher probability of loss, provided this also allows for higher probability of high returns.
Sharpe ratio is a widely used measure, developed by Nobel prize recipient William Sharpe. It measures the performance of an asset, adjusting for its risk. An automated trading system may seek to optimize certain metrics, and Sharpe Ratio is a popular one, for good reason.
It looks a bit heavy, but it’s really quite simple. Sharpe ratio can simply be measured as the expected value of the difference of the asset return minus the risk free rate, all divided by the standard deviation. The risk free rate is the theoretical return rate which requires 0 risk. This is usually defined as the 10-yr treasury rate (~2.7% at time of writing). A sharpe ratio of 1 is generally defined as acceptable, 2 being above average, and 3 being exceptionally good.
You may not want to wait for the markets in order to test your strategies. This is where backtesting comes in. Backtesting is the concept of testing your ideas on historical data. Historical performance certainly doesn’t guarantee future returns, but it can go a long way towards growing confidence in your strategy. With backtesting, you simply apply your strategy at a certain date, and test how that strategy would perform into the future.
Variance always plays a role, and we must be careful to not grow a biased view during our backtesting. Make sure to test your idea on as many applicable stocks and situations as possible. Then, when your satisfied with the results, see how your strategy matches up on live returns by simulating trades in real time, using your automated system.
We discussed the basic outline for an automated trading system. In future articles, we’ll dive deeper into the individual components. The first topic of discussion will be connecting your program to an API for simulating trades and managing a simulated portfolio.
For example, if a portfolio of stocks has a one-day 5% VaR of $1 million, that means that there is a 0.05 probability…en.wikipedia.org
In finance, the Sharpe ratio (also known as the Sharpe index, the Sharpe measure, and the reward-to-variability ratio)…en.wikipedia.org