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:
No comments:
Post a Comment