From the course: Algorithmic Trading and Finance Models with Python, R, and Stata Essential Training (2019)

An algorithm example

- [Instructor] All right, now let's take a look at how we'd actually use market-making data to put together a real algorithm. Now, in this particular case based on previous data that we've collected and algorithmic trading strategy that our intelligent humans have come up with and tested, we've determined that a natural price, a price that the stock should gravitate to over time, based on our trading data set, is based on the following formula. The last price the stock traded at minus some sort of relative change in an index times the standard deviation of the stock. Now we can quibble with that formula, but we're simply going to assume that that's a given we've tested and it's a valid formula. So how would we implement this and actually put this mechanically into practice? Well, to visualize it, let's do it in Excel. I'm in the 01_03_Begin Excel file. And what I'm going to do is go through and compute my natural price based on the last price the stock traded at. At 9:45, the previous trade is at 9:30 in our hypothetical example. That last price is $13.69. We want to subtract off of that the relative change in our index, which is $14.40 minus $14.13 all multiplied by the standard deviation for our particular stock. And I'm going to anchor that standard deviation. And this tells us that our natural price is $13.56. And we can drag and drop this down the whole column to get our remaining natural prices. Now we'd want to go through and determine a buy/no buy signal. To do that, we'd simply use an if statement, in Excel. Now, in our particular case, if the stock is below its natural price, well that means it's intrinsically undervalued compared to where we would expect it to be. So I'm going to compare that natural price to the intrinsic value and if the natural price, essentially our fundamental value, is above the actual price then we want to buy otherwise we do not. And we can go through and apply this again down the entire column. What we see is a clear buy/sell indicator throughout the day. Now obviously from an algorithm point of view, we're certainly not going to do this in Excel. That's not the point. Instead, this gives you a sense for what you need to be able to do in order to develop an algorithm. Come up with a strategy, go through and take and apply that strategy to data to determine a particular buy/sell price, in this case our natural price. And then create a buy/no buy type rule that allows us to go through and make actionable trading decisions. At this point, you should be prepared to go through and follow these steps for any rules or strategies you develop.

Contents