These are projects posted by the students of Dr. Gove Allen at Brigham Young University. These students have taken one semester-long course on VBA and generally have had no prior programming experience

Thursday, December 10, 2015

High-Frequency Stock Trading Algorithm Simulator

Active stock traders often find themselves in need of high-frequency trading algorithms that are tailored to the behavior of specific stocks. In order to meet this need, the VBA-based solution presented here allows users to “test-drive” custom algorithms on any publicly traded stock, bond, or index fund. The program has two parts: (1) Refresh Stock Data, and (2) Algorithm Simulator.

Refresh Stock Data. First, the program allows users to input a ticker symbol in the appropriate cell and query the web for the most recent two weeks of historical stock data. This is accomplished via the “Refresh Stock Data” button on the Algorithm ribbon. Historical data is queried and parsed in the background, then presented for the user on the “Data” worksheet. The following data fields are presented:
-          Stock price (minute-by-minute granularity)
-          Minute of the day (e.g., 7:30:00 AM)
-          Relative trading day (e.g., -2 represents data from two days ago)
-          Daily percent change (the percent change from the opening price on that specific trading day)
Algorithm Simulator. The second part of the program allows the user to define and test an algorithm on the two weeks of historical data. This functionality is accessed through the “Algorithm Simulator” button on the Algorithm ribbon. The simulator first presents a user form, prompting the input into three fields:
-          Principle (i.e., how much do you want to simulate investing?)
-          Buy Parameter (the algorithm will invest the principle when the stock has risen by a certain percentage)
-          Sell Parameter (the algorithm will sell its shares when the stock has risen beyond the buy parameter to a certain percentage)
The program then runs the algorithm on the historical data. The algorithm is a momentum based algorithm that functions according to the following rules:




Immediately after the algorithm has run, the user is presented with a message box detailing the performance of their algorithm in absolute dollar terms and percentage terms. This allows the user to see what their returns would have been had they been running their algorithm on the actual market.
Lastly, the user is presented with a user form showing a graph of their algorithm-simulated principle versus the stock’s historical performance (normalized to the amount of the original principle). For example:




The user is then free to re-run the algorithm again with updated parameters in hopes of finding an algorithm even better suited to the specific stock (or a new stock). Each time that the user runs a specific algorithm, the inputted values become the default values the next time the simulator is run.




  • http://files.gove.net/shares/files/15f/bcoburn1/Algorithm_Simulator.pdf


  • http://files.gove.net/shares/files/15f/bcoburn1/Algorithm.xlsm

  • No comments:

    Post a Comment

    Blog Archive