Algorithmic/Quatitaive Trading Introduction

Algorithmic Trading Educational & Tutorial Videos
Algorithmic Trading Basics: Examples & Tutorial
What is algorithmic – also know as quantitative trading ? How does it differ from fundamental based trading? In this video we provide code example for a simple strategy that trades the S&P 500. Also discussed are the advantages and disadvantages to algorithmic/quant trading. This is a great algorithmic trading tutorial video for both beginners and experienced trades.
Transcript of Video:

The purpose of this video is to provide a primer on algorithmic trading. We’re going to be talking about how it differs from other trading styles, what are some of the advantages, what are some of the disadvantages, and then I’m going to provide a very simple example and provide the code, and then kind of walk through the results of that code.

Okay, I’d like to go over our disclaimer first. Quantitative Trading futures and options does involve substantial risk of loss. It’s not appropriate for all investors. Keep in mind the purpose of this presentation is really just to provide educational content. We are not registered with the CFTC as a Commodity Trading Advisor. We do not control client accounts. We are what’s called a third-party trading system developer. So we develop trading systems and then sell them to the public for use on their personal computer using the trade station platform or for auto-execution using one of our NFA-registered brokers.

As most of you are aware, there’s many different trading styles. You have technical analysis versus fundamental analysis. Algorithmic trading focuses on technical analysis, primarily. Fundamental analysis would be more in mind with looking at profit/loss statements of companies, economic reports, and then placing trades based on that data. Technical analysis is more mathematical in nature. It’s looking at price action, volume, things like that. The futures market versus equity versus currency markets, so that’s just the markets that are traded, right? So you have the futures market, which would be commodities, broad-based index futures. You have the equity markets, which would be stocks, ETFs, and then currency market, which would be currency pairs that you would trade. We focus on the futures market, in particular, on the 10-year note and the S&P E-minis. You also have different styles. That would be like swing trading versus day trading.

When it comes to algorithmic trading, we actually do both. We do swing trading and day trading. Day trading is you’re in and out the same day. It does have some advantages in that there’s less overnight risk or black swan event risk because you’re in and out the same day, and at least with our algorithms, we have stops in place, although keep in mind it is always possible that stops are missed, but we do have stops on all the algorithms that we trade. Swing trading would be holding for multiple days, and we do that as well. Typically, we will hold for one to two days, but one of our algorithms in particular can hold for up to a couple months, and that’s the 10-year note algorithm. So if you go kind of one layer deeper into technical trading, you have what’s called charting, where you’re drawing trendlines, and then you also have indicators. That would be moving averages, oscillators, price, volume, and so within technical trading, those are usually the different things that algorithmic traders, quant traders, look at. But keep in mind, technical trading is what a lot of people do, but they aren’t necessarily doing algorithmic trading. So there’s a difference. Someone that just does technical trading without the algorithmic side of it, they might do trendlines. They might just create a moving average on a chart and then kind of analyze it and use that along with other things to try to play straights. They’re not necessarily algorithmic traders, though. Algorithmic traders will use these things, but they also use the computer to execute it. They back-test. They do walk-forward testing. And so, but kind of at a high-level view, when you compare fundamental versus technical trading, technical traders, we use charting indicators, and then some technical traders will use algorithmic trading like we do. Okay, so we’ve kind of talked about technical analysis versus fundamental. I’m gonna go kind of a layer deeper into technical analysis. So, within technical analysis, you have what’s called quant or algorithmic trading, and we obviously are an algorithmic trading third-party developer company.

There are different kinds of quantitative trading/algorithmic trading, though. There’s high-frequency trading. There’s statistical arbitrage, and then trend/mean reversion/momentum trading. When it comes to high-frequency trading, that is something that we do not do. What it does, though, in my opinion, it does improve market liquidity, but there are some negatives to it. In fact, most agree that it’s generally a negative term today, mainly because large companies can benefit from small investors, and then there’s also issues with ghost liquidity. But it does provide a purpose, which is improved market liquidity.

Statistical arbitrage is another kind of algorithmic trading technique where people simultaneously purchase and sell an asset to profit from a difference in the price. A real simple example would be if a stock is trading on the New York Stock Exchange at 20 and it’s also trading at the same time on the London Exchange at 20.05, then they could buy at 20 and then sell at 20.05 immediately for a five-cent profit. That’s what arbitrage trading is.

What we do within algorithmic trading is more in line with trend or mean reversion or momentum trading. Essentially what we do is we use computers that are programmed to follow a defined set of instructions. They place directional trades in order to generate profits. So, within algorithmic trading, that’s what we do. So we are kind of a trend/mean reversion/momentum. We write algorithms. We back-test them. We do the walk forward, and then those algorithms are used to automatically place trades for us. And then, as third-party developers, again, not registered with the CFTC as commodity trading advisers, we sell the license to use those algorithms that trade in the futures market, and people can either use them on a personal computer with TradeStation, or they can have them auto-executed with a broker. Again, just wanna emphasize, we do not control the accounts. So people that use the auto-execution brokers, they interact with the broker to open the account, to fund it. We don’t touch their money. And then they decide to use our algorithms in their account, and then, again, we license the use of them.

Okay, now I’m going to show you an example and show you the code so you can see kind of what these algorithm trading programs look like. This is a very simple example, but what you’re looking at here is a chart of the S&P 500 E-minis. This is the election day where you got this big spike down, and then the rally since then. But if you look at this chart, you might say, well, maybe if you bought on a red candle on a down day and then sold on the next green day, the next positive day, maybe that’s an idea that we could look at. So, again, this is a very simple example, but I’m going to show you now the code for something like that. Okay, so here’s the code for that example. So, and I copied it straight out of the TradeStation development environment. But first, you know, you have a few inputs. You have a stop, a target. You have a variable, myfill, which we don’t actually use that. And then this is kind of the code that matters or that has the entry. So, if the close of the current candle is less than the open of the current candle, then we just wanna buy the next bar at the market. And if we’re in a position to have a green candle, then we wanna get out. So here’s the code for that. If the close is bigger than the open and our market position is bigger than zero, then we’re gonna sell this bar, which we’ll sell at the close. And then we just wanna set a dollar target and a stop so the target is whatever’s set on the input, which, in this case, is $500, and then the stop is whatever the stop is, which is 200. So again, all this is doing is getting in when you have a red candle and then getting out when you have either a green candle or the target or the stop is hit. So, on the chart, which, if I zoom out, you’ll see it goes all the way back to, I believe, May 2003, but again, this is the daily chart of the S&P 500. So now what we can do is we can add the strategy to the chart. And I actually have it added, so I just need to enable it. And what you see is that on the chart, all the trades populate based on what we programmed. And so, you know, here’s that first one we were looking at where we said, if we had a red candle and then got out on the green one, then maybe it would be profitable. But because we have a target, what actually happened is we got in right here on the next candle, and then we got out on the spike that happens. So that’s where we got out on this trade, but then we had another red candle, so we got in, got out when our target was hit, and then even on this day, we would have gotten in on the 17th and gotten out when our target was hit. Here’s another example where it would have worked. We have a red candle so we got in, hit our target, but then here’s an example where it would not have worked. It would have, because of this red candle, it would have gotten in right here, and then our $200 stop would have been hit that day. So, as you can see, all the trades are applied to the chart, which allows us to kind of look at what the final result of this trading strategy would be. So now I’ve zoomed all the way out, just to show you how it populates. What TradeStation will do is it’ll give you these performance reports based on the strategy, and that’s how you analyze how that strategy would have done. So we modeled in commission, slippage already, but it gives you kind of the net profit or the total profit trading one contract since, I believe it’s May 2003, but let me look here and double-check. So, April 2003 ’til the 18th of November 2016. It would have lost $8,651 dollars. So this obviously is not a good strategy. It would have had 1500 trades. The win rate is 33%. It gives you the average trades. The draw down would have been, wow, actually $30,000. So, this is actually obviously a horrible strategy, but just a very simple one that I wanted to code up to show you what they look like. So one thing I haven’t done is showed you how you can then also optimize these strategies. So if this was a strategy that we thought was promising, then you could format it and you could change the stops. You might say, well, okay, a $200 stop doesn’t work. What if we make the stop $500, and we make the target $1,000? And then you can kind of see how that strategy would have done. So now it repopulated it with the new inputs. You can see, like, this trade that got stopped out on the other one, now it would have hit the target, because our stop is bigger. So let’s just see how this one does now. And so it’s recalculating. You can see, it does actually look a little bit better. It looks like this strategy is actually profitable in the end, but it’s still a horrible strategy because, you know, it would have worked in ’03, ’04, ’05, all the way through ’07, really, although a pretty big draw down here. And then from ’07 until 2012, it would have lost money than it would have made.

So it’s just not a good strategy. But again, you can see the profit factor’s a little bit better. It would have actually been profitable, but the profit factor is way too low. So 1.04, it’s just the ratio of profit to loss. And the point of doing this is just to show you how the algorithm can give you information that would have taken you, you know, months to figure out if you didn’t kind of write this code. It also gives you the trade list, and by the way, the strategies that we offer with algorithmictrading.net, we do have all the performance reports for them. The only ones that we don’t have the reports for are the options strategies, and that’s because options are a little bit different. But we have a tool that allows us to kind of back-test and see how strategies would do if they were trading options. But of course, you know, those tools are less than perfect, because they use models for how much premium we would collect when we sell the options. But anyway, all this is to say is that with all the strategies, except the options ones, we do have the performance reports on the website. I’ve showed you kind of just a real simple example of what the code looks like for a strategy. Again, this one has just a few lines of code. Strategies can be as simple as this or as complicated as tens of thousands of lines of code with various data structures. So they can really be as big as a developer wants them to be. This one is pretty simple, just to show you kind of how it looks. All right, now that I’ve showed you what algorithmic trading is, quant trading is, how it differs from fundamental trading, what some code actually looks like, how you can analyze an algorithm using TradeStation, now I’d like to talk about some of the advantages of algorithmic trading, and then I’ll go into the disadvantages. So the advantages are, there is a reduced chance of human error. When a technical trader’s doing an analysis, they might do the same thing I did, but they would look at this chart, again, without the strategy applied, ’cause they wouldn’t have it, and they would kind of write down, okay, we would have bought here, and then we would have sold here, and they would create an Excel spreadsheet, but there’s always the chance of human error. They might have missed… They might have thought, okay, well, I would have bought here, and then the next green candle was over here. It’s just a mistake they might have made. I mean, really, the next green candle was this one, which would have been a loss. It’s just an example of the kind of human errors that can be avoided with algorithmic trading. It also gives you the ability to back-test trading ideas very quickly, the ability to walk forward trading ideas, which I haven’t talked about. I will in another video. But it basically lets you analyze an algorithm on in-sample and out-of-sample data to give you a better idea of how that algorithm might perform trading live. Algorithmic trading gives you faster order entry, because once the trade is entered, it automatically gets sent to the broker. There’s a reduced chance of emotional error.

This is probably the biggest one for me, because when a technical trader trades, they always have to battle their emotions. They might decide that they have a good algorithm or a good technical trading idea, but when it comes down to it, it might be hard for them to place it. So algorithmic trading reduces it. It doesn’t eliminate it, but it does reduce it because if you let the algorithm run, it’ll just place the trades. It doesn’t totally remove it, though, ’cause you can always override the trades, but it does reduce them. With algorithmic trading, we always recommend people let the algorithms run and not override them, but because we’re not commodity trading advisors, we don’t control your account. You do own the account. It’s your account. You can turn off certain algorithms. You can change the contracts that are traded. So you do have ultimate control of the account. But it does reduce the chances of emotional errors, ’cause it’s a little bit easier to just let it run. It also allows you to test multiple ideas, to do cross-optimizations, and to build portfolios. So those are the key advantages, in my opinion, of algorithmic trading, versus technical trading or even fundamental trading. Some of the disadvantages, though, is it can build a sense of overconfidence. It can also be subject to over optimization. So, again, another thing I’ll talk about in another video, but when you write the algorithm and you optimize it, ideally, there would be no optimization. So it would just be an algorithm that is based on purely technical indicators or price and price action that are using really just common sense initial values. However, optimization is a tool that is helpful, but once you start using it, it becomes pretty clear how it can be easy to over optimize something. So that’s something that algorithmic traders have to be very aware of. Another disadvantage is that algorithmic trading in general does not take into account geopolitical events or other kind of more fundamental trading techniques. A good example would be the election. Just a straight technical trader might have said, well, the election’s coming. I know there’s gonna be volatility, so I’m gonna sit out election day.

Algorithmic trading, generally speaking, will just run in all market conditions. So I mean, you could always program the algorithm to say on key economic days, like the first Friday of the month with the jobs report, or election day, you know, to not take the trades, but just kind of generally speaking, an algorithm will just run and not take into account key political, geopolitical events or key economic announcements. The argument that algorithmic traders would make and that I would also make is that when you do the back-testing and the analysis, there’s all kinds of geopolitical events all throughout the analysis that’s being done. So they would argue that it does take that into account, just not on a discreet, day-to-day level. But I did list that as a disadvantage just because I think most would consider it to be a negative with algorithmic trading. So, that’s kind of all I had for this presentation. So I’ve talked about just in general what quantitative trading is versus fundamental and even versus just regular technical trading. I showed you an example of an algorithm that is very simple, just to show you kind of the power of algorithmic trading. We talked about the advantages of it, the disadvantages, and that’s really all I had for this video. I hope you enjoyed it. I hope it was helpful. A lot of it’s real basic information that you can find online. Hopefully the example though is something that you would have to dig a little bit deeper to find, you know, those kind of things. And hopefully that’s helpful. I know a lot of our visitors to the website have no idea what algorithmic trading is, and so this is a very basic view of what it is along with the example. But I hope you have a great day and look forward to talking to you again in some other videos. If you have any questions at all, feel free to email us, call us. All of our contact information is on the website, and we look forward to answering any questions you have. Have a great day. Bye.

[addtoany]


AlgorithmicTrading.net provides trading algorithms based on a computerized system, which is also available for use on a personal computer. All customers receive the same signals within any given algorithm package. All advice is impersonal and not tailored to any specific individual's unique situation. AlgorithmicTrading.net, and its principles, are not required to register with the NFA as a CTA and are publicly claiming this exemption. Information posted online or distributed through email has NOT been reviewed by any government agencies — this includes but is not limited to back-tested reports, statements and any other marketing materials. Carefully consider this prior to purchasing our algorithms. For more information on the exemption we are claiming, please visit the NFA website: http://www.nfa.futures.org/nfa-registration/cta/index.html. If you are in need of professional advice unique to your situation, please consult with a licensed broker/CTA.

DISCLAIMER: Commodity Futures Trading Commission Futures trading has large potential rewards, but also large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures markets. Don't trade with money you can't afford to lose. This is neither a solicitation nor an offer to Buy/Sell futures. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this website or on any reports. The past performance of any trading system or methodology is not necessarily indicative of future results.

Unless otherwise noted, all returns posted on this site and in our videos is considered Hypothetical Performance. HYPOTHETICAL PERFORMANCE RESULTS HAVE MANY INHERENT LIMITATIONS, SOME OF WHICH ARE DESCRIBED BELOW. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFITS OR LOSSES SIMILAR TO THOSE SHOWN. IN FACT, THERE ARE FREQUENTLY SHARP DIFFERENCES BETWEEN HYPOTHETICAL PERFORMANCE RESULTS AND THE ACTUAL RESULTS SUBSEQUENTLY ACHIEVED BY ANY PARTICULAR TRADING PROGRAM. ONE OF THE LIMITATIONS OF HYPOTHETICAL PERFORMANCE RESULTS IS THAT THEY ARE GENERALLY PREPARED WITH THE BENEFIT OF HINDSIGHT. IN ADDITION, HYPOTHETICAL TRADING DOES NOT INVOLVE FINANCIAL RISK, AND NO HYPOTHETICAL TRADING RECORD CAN COMPLETELY ACCOUNT FOR THE IMPACT OF FINANCIAL RISK IN ACTUAL TRADING. FOR EXAMPLE, THE ABILITY TO WITHSTAND LOSSES OR ADHERE TO A PARTICULAR TRADING PROGRAM IN SPITE OF TRADING LOSSES ARE MATERIAL POINTS WHICH CAN ALSO ADVERSELY AFFECT ACTUAL TRADING RESULTS. THERE ARE NUMEROUS OTHER FACTORS RELATED TO THE MARKETS IN GENERAL OR TO THE IMPLEMENTATION OF ANY SPECIFIC TRADING PROGRAM WHICH CANNOT BE FULLY ACCOUNTED FOR IN THE PREPARATION OF HYPOTHETICAL PERFORMANCE RESULTS AND ALL OF WHICH CAN ADVERSELY AFFECT ACTUAL TRADING RESULTS.

With the exception of the statements posted from live accounts on Tradestation and/or Gain Capital, all results, graphs and claims made on this website and in any video blogs and/or newsletter emails are from the result of back-testing our algorithms during the dates indicated. These results are not from live accounts trading our algorithms. They are from hypothetical accounts which have limitations (see CFTC RULE 4.14 below and Hypothetical performance disclaimer above). Actual results do vary given that simulated results could under — or over — compensate the impact of certain market factors. Furthermore, our algorithms use back-testing to generate trade lists and reports which does have the benefit of hind-sight. While back-tested results might have spectacular returns, once slippage, commission and licensing fees are taken into account, actual returns will vary. Posted maximum draw downs are measured on a closing month to closing month basis. Furthermore, they are based on back-tested data (refer to limitations of back-testing below). Actual draw downs could exceed these levels when traded on live accounts.

CFTC RULE 4.41 - Hypothetical or simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under — or over — compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

Statements posted from our actual customers trading the algorithms (algos) include slippage and commission. Statements posted are not fully audited or verified and should be considered as customer testimonials. Individual results do vary. They are real statements from real people trading our algorithms on auto-pilot and as far as we know, do NOT include any discretionary trades. Tradelists posted on this site also include slippage and commission.

This strictly is for demonstration/educational purposes. AlgorithmicTrading.net does not make buy, sell or hold recommendations. Unique experiences and past performances do not guarantee future results. You should speak with your CTA or financial representative, broker dealer, or financial analyst to ensure that the software/strategy that you utilize is suitable for your investment profile before trading in a live brokerage account. All advice and/or suggestions given here are intended for running automated software in simulation mode only. Trading futures is not for everyone and does carry a high level of risk. AlgorithmicTrading.net, nor any of its principles, is NOT registered as an investment advisor. All advice given is impersonal and not tailored to any specific individual.

* Published percentage per month is based on back-tested results (see limitations on back-testing above) using the corresponding package. This includes reasonable slippage and commission. This does NOT include fees we charge for licensing the algorithms which varies based on account size. Refer to our license agreement for full risk disclosure.