High-frequency trading simulation with Stream Analytics
5 stars based on
Advanced analytics might include online machine learning training and scoring, as well as stateful process simulation. This article describes how to perform linear regression in an Azure Stream Analytics job that does continuous training and scoring in a high-frequency trading scenario. IEX offers free real-time bid and ask quotes by using socket. A simple console program can be written to receive real-time quotes and push to Azure Event Hubs as a data source.
The following code is a skeleton of the program. The code omits error handling for brevity. ServiceBus NuGet packages in your project. For the purpose of demonstration, we use a linear model described by Darryl Shen in his paper. The paper identifies high variable prediction applied to options trading correlation between VOI and future price movement.
It builds a linear model between the past 5 VOI values and the price change in the next high variable prediction applied to options trading ticks. The model is trained by using previous day's data with linear regression. The trained model is then used to make price change predictions on quotes in the current trading day in real time.
When a large enough price change is predicted, a trade is executed. Depending on the threshold setting, thousands of trades can be expected for a single stock during a trading day. First, the inputs are cleaned up. It's always a good practice to cast input fields to the expected data types, so there is no unexpected behavior in manipulation or comparison of the fields.
Next, we use the LAG function to get values from the last tick. Given the quote frequency, it's safe to assume that you can find the previous tick by looking back one hour.
We can then compute VOI value. We filter out the null values if the previous tick doesn't exist, just in case. Now, we use LAG again to create a sequence with 2 consecutive VOI values, followed by 10 consecutive mid-price values. We then reshape the data into inputs for a two-variable linear model. Again, we filter out the events where we don't have all the data. To use the previous day's model for current event's scoring, we want to join the quotes with the model.
Then we use LAG to pair the events with previous day's model, so we can get exactly one match. Because of the weekend, we have to look back three days. If we used a straightforward JOINwe would get three models for every quote event. A trade value of 10 is buy. A trade value of is sell. After we have the trading signals, we want to test how effective the trading strategy is, without trading for real. We achieve this test by using a UDA, with a hopping window, hopping every one minute.
We never hold or short 10 shares of a stock in this simulation. We can implement a realistic high-frequency trading model with a moderately complex query in Azure Stream Analytics. We have to simplify the model from five input variables to two, because of the lack of a built-in linear regression function.
Let us know any feedback you have to make it easier to implement queries for advanced analytics scenarios. Our new feedback system is built on GitHub Issues. For more information on this change, please read our blog post. High-frequency trading High variable prediction applied to options trading logical flow of high-frequency trading is about: Getting real-time quotes from a security exchange.
Building a predictive model around the quotes, so we can anticipate the price movement. Placing buy or sell orders to make money from the successful prediction of the price movements.
As a result, we need: A real-time quote feed. A predictive model that can operate on the real-time quotes. A trading simulation that demonstrates the profit or loss of the trading algorithm. Real-time quote feed IEX offers free real-time bid and ask quotes by using socket. Send new EventData Encoding.
What type of feedback would you like to provide? High variable prediction applied to options trading product feedback Sign in to give documentation feedback Give documentation feedback Our new feedback system is built on GitHub Issues.