Excel Interface: Ftsalgotrading - XLSM
Excel Interface: Ftsalgotrading - XLSM
The FTS Real Time System lets you create trading strategies, as follows:
This lets you monitor multiple markets and create virtually any type of strategy you like,
including:
Contingent orders
Basket trading
Pairs trading and other statistical arbitrage strategies
Dynamic trading strategies
Optimal trade execution strategies
Inter-market trading
Tracking
The operation is very simple, and requires just a little understanding of Excel macros and VBA
programming. The examples below get you started, but we describe extremely simple trading
strategies so we can focus on the mechanics.
You can download the Excel workbook with the examples by clicking on:
FTSAlgoTrading.xlsm
Example 1
As a simple illustration, consider the following “constant mix” strategy in the FTS 1000 Stock
case:
It’s self-explanatory, except for the second row: note that the macro type is a
“Function.”
An Excel macro can be a Function or a Sub. To obtain trade orders from a macro, you
must write a function. In example 2, we will show you how to and why you may also
want to use a sub.
You can have multiple macros. We will illustrate this in example 2.
The number of tickers is read from this sheet; in this case, there are 3 tickers. The
order of the tickers is important. Tickers are processed in the macro in the same
order as in this sheet
Dim returnString() As String ‘this is what you send back to the FTS Real Time Client
ReDim returnString(n) ‘ one trade order for each ticker; it could be blank
That’s all it takes. Save the workbook, but leave it open in Excel. We saved ours with the name
FTSAgloTrading.xlsm. The “xlsm” specifies a macro-enabled workbook.
3. Launch the FTS Real Time Client, and log in after selecting the FTS 1000 Stock Case (you
must have a trading account set up for this case). At the top, you will see the Algorithmic
Trading button:
Notes:
The worksheet is read in when you select the worksheet. This defined the number
of tickers, the order of the tickers, the macro names, and so on.
If you make changes to the worksheet after you have selected the worksheet, you
have to click Find Workbooks again and re-select the worksheet.
Click Go Live Now. The macro will be implemented. Here is what happened to us:
The macro was run at 4:32:30 PM, and we received the following trade confirmations:
Now, every 60 seconds, the FTS Real Time Client would run the macro again and trade if
necessary as calculated by the trading algorithm.
That’s it.
Example 2:
Let’s modify the example a little bit: suppose that we don’t necessarily want an equal amount
invested in each, but instead, we want different amounts, and we want to specify the amounts
in a worksheet. This will illustrate how you use data stored a worksheet in your trading
algorithm. While our example is simple, the method illustrates you can use any data, such as
historical data, in your strategy.
The yellow parts show you the new information: we have a sub called ReadAmounts. This will
also be called every 60 seconds, but it will be called before the function NonConstantMix. In
the sub, we will read the level of each investment; that information is in the sheet
NonConstantMixData:
The levels are specified: 5000 in IBM, 10000 in CSCO, 15000 in INTC. Note that this data could
be anything that you want.
Option Explicit
Dim dollarAmount(3) As Single
Sub ReadAmounts()
dollarAmount(1) = Worksheets("NonConstantMixData").Cells(1, 2).Value ' cell B1
dollarAmount(2) = Worksheets("NonConstantMixData").Cells(2, 2).Value ' cell B2
dollarAmount(3) = Worksheets("NonConstantMixData").Cells(3, 2).Value ' cell B3
Worksheets("NonConstantMixData").Cells(4, 2).Value = Now
End Sub
In the module, we have declared a global variable called dollarAmount(3). Sub ReadAmounts
reads in these numbers from the worksheet NonConstantMixData. It also writes out the time
at which the sub was called.
Note: you can change these levels at any time by typing in new numbers; since the
amounts are read in every 60 seconds, the next run of the macro will be based on the
new amounts.
You could also have external data, like historical data or news or whatever you need and
read it in. You could even have a web query that is run that download data from web
sites and read in that data.
This note illustrates how you change parameters in a worksheet.
Function NonConstantMix is similar to the previous one, so we won’t describe it further. Note,
however, the line:
returnString(0) = "strategy checked"
near the bottom. Whatever you put into returnString(0) is displayed on the screen after the
macro is run.
Details about how you must define the function that create sthe trade orders are in the
appendix. You must follow the exact call sequence.
Extensions
Now, you know how to do 3 things:
1. How to create trade orders by creating a function called by the FTS Real Time Client with the
specified arguments
2. How to use data stored in the workbook by using a sub and storing the data in global variables
that can then be used by the function.
3. How to run multiple sub’s and functions in sequence
The two examples show you the basic steps: how to call functions, how to read data, and so on. Our
strategies were simple so we could focus on showing you the basics, but you can probably figure out
that you can create fairly complex strategies.
Example strategies
Contingent orders: an order is executed only if one or more conditions are satisfied. Ultimately,
any trading strategy results in a contingent order!
o For example, you are interested in buying stock 1 or stock 2 but not both. So you
specify a limit price on each in your function, and issue a buy order for the first stock
when the limit price is reached.
Rebalancing: like our constant mix example. Another example is re-allocating money across two
different stock markets based on exchange rate movements.
Dynamic trading strategies and hedging: buy or sell options or futures depending on stock price
movements.
Basket trading: buy a group of securities all at once when some conditions are met.
…….
Function trade(bids() As Single, asks() As Single, last() As Single, volume() As Single, qty() As
Single, serverTime As Date) As String()