Connecting ThinkOrSwim To Excel
Connecting ThinkOrSwim To Excel
You can’t beat a spreadsheet for turning big chunks of data into actionable information. Without some
experience in programming, however, it isn’t always the easiest way to manipulate real-time data.
Let’s write (get it?) that wrong! It is easy to have ThinkOrSwim (TOS) stream live data into Excel but it’s
not well-documented. (There’s a harder way, too, that’s not well-documented. You’ll get an overview of
both, you crazy kids, but we’ll focus on the easier.) So, let’s go through a few explanations, show you
how to connect the two programs and give a couple examples to get you on your way.
Why would you want to know how to do this stuff? Because you probably have a couple of ideas or
questions swimming around. If you’ve got imagination and take a little time to learn, you can create a
real-time model in Excel that proves (or disproves) your hypothesis or gives you answers.
If you don’t drink coffee and couldn’t care less about technical details, jump to the
next section and wait for us there.
DDE and RTD are two different mechanisms that allow Excel to talk with the outside world. Specifically,
DDE (Dynamic Data Exchange) is an older technology that links Microsoft products and RTD (Real-Time
Data) retrieves real-time data from a program that supports COM automation but there’s overlap for
what we’re trying to do.
(I know. You’re thinking, “Where can I read more about this exciting stuff?!?!” Slow down, Turbo; you
can visit http://msdn.microsoft.com/en-us/library/aa140061%28office.10%29.aspx after reading the rest
of this article.)
Which method is better? Well, as with all things technological, the answer is “it depends.” (This is when
most sane people throw up their arms in exasperation with most technology people. But stick with me.)
Both are kind of real-time. DDE refreshes an Excel cell when TOS updates its data; this is known as
“interrupt driven.” RTD is interrupt driven, too, but Excel isn’t interrupted by TOS changing data; the
interrupt comes from a clock timer, and the timer can be changed.
You can imagine that DDE may get updated faster than RTD because TOS data may change before the
clock timer goes off. Is that bad? Not really if you consider we’re talking about milliseconds.
1. RTD puts less of a load on the ThinkOrSwim servers, so you can see why they want to move from
DDE to RTD. (They support both mechanisms right now.)
2. DDE needs “explicit data,” which means you need to give it exactly what it wants. If you want
the last price of RUT in cell G2, you need to ask for the last price of RUT in cell G2. If you want
the last price of SPX, you have to completely change what you ask in cell G2.
RTD can use explicit data but it can also use “implicit data.” That means you can say, “Hey, G2,
give me the last price for the underlying that’s in cell B2.” Better, you can change B2 from RUT
to SPX anytime, without doing anything to cell G2, and G2 will return the last price of SPX.
Why is that good? Because Excel can make do different things with the live data that will soon
be streaming into your spreadsheet. For a non-programmer, RTD is easier to use than DDE.
What’s the conclusion? DDE may be technically faster but, for simplicity and user-level flexibility, RTD is
the way to go. We’re big easy fans so let’s get moving with RTD.
Step 2: After ThinkOrSwim is running, run Excel. (We use Excel 2016 for Windows but this works in Excel
2007, too. No guarantees for any other operating system or any other spreadsheet program.)
Step 3: To keep it all straight in our head, let’s create some headers. Make cells B2 and G2 in your
spreadsheet look like this:
Step 5: Ready for the magic of RTD? Paste the following into cell G2 (under LAST):
=RTD("TOS.RTD",,"LAST",B2)
Feel free to type it in yourself if you don’t want to copy & paste, but make sure you don’t forget
the 2 commas between "TOS.RTD" and "LAST"; don’t forget the double quotes; LAST must be
capitalized and remember to press the <Enter> key to accept the equation (and leave cell G2).
The number may not match because we’re looking at RUT on different days and times. Other than that
– CONGRATULATIONS! What you see is TOS is giving Excel live data, the last price paid for RUT.
Now change RUT to SPX in B2 to get the last price for SPX. It worked? You’re a superstar!
Good enough for now. Experiment a little, then save this workbook as LockeRTD. Next week we’ll build
on top of what you did today, make Excel do more work than you, and delve into derivatives.
(By the way, if you have about 30 seconds and would like to view ThinkOrSwim’s documentation on RTD,
click here.)
The last article covered some DDE versus RTD technobabble and left you with an example of how to use
RTD in Excel to get the last price of RUT from ThinkOrSwim (TOS). Not bad for a day’s work but let’s take
it to the next level.
Before we begin, bring up ThinkOrSwim and the LockeRTD Excel spreadsheet you saved last week and
make sure RUT (not SPX) is in cell B2, like this:
It’s well-known and documented but still annoying, and if you search the web you’ll find a wide range of
work-arounds. Here’s a fast and easy method we use every day:
(If TOS is running, you should now see the last price of RUT.)
Step 3: Open LockeRTD or any other spreadsheet you have that uses RTD
That’s it. Since the newly opened spreadsheet works, any successively loaded RTD spreadsheet will
work. You could even close that first spreadsheet and, as long as you keep at least one RTD spreadsheet
always running, load more RTD spreadsheets. (Typically we just minimize the Step 1 spreadsheet so we
can open and close others with impunity.)
Yes, it’s like last century when you had to warm up television tubes. Yes, it’s annoying. No, I don’t know
why it hasn’t yet been fixed.
But I’m sure the helpful Microsoft support staff would be more than happy to answer your question.
You may recall the following RTD command you entered in cell G2 from the last article:
=RTD("TOS.RTD",,"LAST",B2)
Breaking it down:
= is how we let Excel know that what follows is something it needs to do.
RTD is an Excel function that, for our purposes, opens up communications with ThinkOrSwim.
RTD can act upon information sent between parenthesis in a particular order:
1. "TOS.RTD" is sent as the 1st RTD parameter. It’s the quote-enclosed name of a
ThinkOrSwim function that’s loaded into memory when you run ThinkOrSwim. The
purpose of TOS.RTD is to respond to RTD requests with data from ThinkOrSwim
2. The 2nd RTD parameter is…nothing! See those two commas next to each other in our
equation? The commas separate parameters and when they’re consecutive, there’s
obviously nothing between them – so that’s how we let RTD know there’s no 2nd
parameter.
3. "LAST" is in the position of the 3rd RTD parameter. According to RTD Rules, everything
sent from the 3rd parameter on is called a “topic,” and everything from the 4th
parameter on is optional.
That’s nice but ThinkOrSwim always uses the 3rd and 4th parameters. "LAST" as the 3rd
parameter means we’re looking for the last price of…whatever we send as the 4th
parameter.
4. B2 is the 4th RTD parameter. Why use B2 instead of typing "RUT"? Because we’re telling
Excel to use the contents of cell B2 as the 4th parameter. Then we can just change the
contents of B2 from RUT to SPX for the last price of SPX, instead of modifying the
equation and potentially goofing it up.
Here’s a graphic of the conversation between the programs that may help:
From now on, all your RTD equations will look the same EXCEPT we’re about to get clever with the 3rd
and 4th parameters.
Go back into cell G2 and edit the formula, replacing "LAST" with G$1, so it looks like this:
=RTD("TOS.RTD",,G$1,UPPER(B2))
When you hit the <Enter> key, nothing will appear to happen but behind the scenes Excel is using the
contents of cell G1, LAST, as the 3rd parameter. You’ll see why this is important in a couple paragraphs.
Did you notice we’re now using the UPPER function? This Excel function converts whatever we typed in
B2 to uppercase. ThinkOrSwim needs to receive everything in uppercase so we’re going to let Excel
verify it gets sent in uppercase. This way it doesn’t matter if we type rut or RUT or any combination of
upper and lower case letters.
Did you notice that we didn’t use G1 but G$1? Excel uses the $ to pin down the 1 so if we copy and
paste cell G2 (our equation) into a different location, the G will change to the column we move it to but
the row will always be 1.
Try it now. Copy cell G2 and paste it to cell G3, then look at the equation:
=RTD("TOS.RTD",,G$1,UPPER(B3))
See? The G$1 stayed the same (because we’re still in column G and we pinned row 1) but B2 became B3.
Why? Because we didn’t put a $ in front of the 2 to keep it pinned to the 2 nd row.
Cell G2 =RTD("TOS.RTD",,G$1,UPPER($B2))
Cell G3 =RTD("TOS.RTD",,G$1,UPPER($B3))
And, just because, enter SPX into cell B3 so your spreadsheet looks something like this:
What happened?
The equation in cell G2 took LAST from cell G1 for the 3rd parameter, looked in its row to column B and
plucked RUT from B2 for the 4th parameter, then used RTD to throw all the parameters to ThinkOrSwim.
ThinkOrSwim caught the request, got the last price of RUT and threw it back as the answer to the
equation in cell G2.
Because instead of manually typing the equation multiple times, you can get the last price for a BUNCH
of symbols by copying cell G2 (or G3), pasting as far as you want down in column G, then simply entering
a symbol in column B. You copy & paste; Excel does the heavy lifting by modifying the formulas.
Step 1: Go to the Analyze tab in ThinkOrSwim and pick an option, any option. I’ll pick the APR16 1000
RUT Put:
Step 2: Hover the mouse over the Call option line and click the right mouse button. A sub-menu pops
up, then you’ll click on Copy .RUT160415P1000 (or whichever option you picked):
…as cell G2 displays the last price paid for your option.
Part 2 explained Excel’s RTD function and how it interacted with ThinkOrSwim (TOS). Excel’s UPPER
function was introduced, we indirectly referenced a symbol and a ThinkOrSwim directive, and you
learned a clever way to copy equations to new cells so Excel would modify just the parts you wanted
modified (pinning via the $). Oh, yeah, we got live option pricing fed into the spreadsheet, too.
If you thought that was a lot of fun, wait until you see what’s in store for today.
(Before we begin, bring up ThinkOrSwim and the LockeRTD Excel spreadsheet you saved last week.)
It should be obvious that the 4th parameter can be any symbol you can look up in ThinkOrSwim but
there’s much, much more than the LAST price that TOS can return for the 3rd parameter.
The 3rd parameter ThinkOrSwim receives is called a “Data Export Field,” as in “this is the data I wish to
export from ThinkOrSwim.” What are the Data Export Fields? This is the only explanation I could find:
To use RTD, bring up a watchlist on the Quotes sub-tab under the MarketWatch tab,
click on the Printer icon in the top right, and choose “Export to Excel”.
Because RTD is a function in Excel, you can take full advantage of the power of Excel
with functionality such as cell referencing.
To see all of the functions supported in exported data, click on the “Data Export Help”
option on the Printer menu.
https://tlc.thinkorswim.com/center/release/rel-04-26-2014.html#RTD
Ah, yes. The Printer icon. Of course. And that would be…where, exactly?
A lot changed since those words were written, including the removal of the Printer icon. Unfortunately,
that’s pretty much it for TOS documentation. Fortunately, you’re reading this article.
Look near the top right corner and you’ll see the box that’s circled in the picture. Click it with the left
mouse button, click Export, then click Help on data export:
For your dining and dancing pleasure, all the Data Export fields can be found
at the end of this article in the Bonus (?) section.
Just to keep you on your toes, even though the menu says Help on Data Export,
Make sure your spelling is correct, everything is CAPITALIZED, and don’t forget the underscore (_) in
PERCENT_CHANGE, NET_CHANGE and EXPIRATION_DAY.
2. Now we’re going to copy those cells. I press the <Ctrl-c> combination on my keyboard but you
can also click the right mouse button and select Copy from the sub-menu. Whichever you do,
you’ll see the G2:G3 selection highlighted by dashed lines instead of solid lines.
3. Go to cell E2 and click into it, then drag into E3. (The same way
you did in step 1.)
4. I paste what I copied by pressing the <Ctrl-v> combination on my keyboard but you can also click
the right mouse button, then select either Paste Options, Paste (circled in red) or Paste Options,
Formula (circled in blue) from the sub-menu:
5. Go to cell H2 and click into it, then drag into N3. (The same way you did in step 1 and step 3.)
6. Paste by using <Ctrl-v> on the keyboard or the Paste Options, Formula (circled in red, above)
from the sub-menu, and you’ll end up with something like this:
Option-specific information (such as EXPIRATION) isn’t really relevant for RUT, hence the reason you see
some inapplicable information in row 2 (which we’ll clean up in the next article), but everything in row 3
is usable and streaming live from ThinkOrSwim.
If you want to experiment with other symbols, select the entire row by clicking the 2 or 3 row number
(circled in green), which will highlight it. Copy it (using your favorite method), click on an empty row
number to select it (4 is good), and paste (using your favorite method).* Change the symbol in column B
and away you go!
1. Data Export Fields returning any result for options or non-options (quantity 86)
2. Data Export Fields returning any result for options (quantity 85)
3. Data Export Fields returning any result for any underlying other than options (quantity 86)
4. Data Export Fields which don’t return any result when used with RTD (quantity 327)
5. All Data Export Fields (quantity 432 but 19 are CUSTOM fields, which won’t be addressed in
this series of articles)
One question you may have is, “Why are there 327 Data Export Fields that don’t return anything?”
That’s a great question. They mostly look like Studies and Strategies for charting which, for some
reason, was dumped into Help on Data Export. If it doesn’t actually export data via RTD, then why is it
there? I don’t know but I’m sure the helpful ThinkOrSwim support staff would be more than happy to
answer your question.
One observation you may have is that a Data Export Field may return a result for an option but not
return a result (or return a bogus result) for something not an option (or vice versa). Why does DIV
return N/A for an option and DIV_FREQ return --? Shouldn’t they both return nothing or at least return
the same thing? Don’t worry – we’ll do some exception handling for spreadsheet modeling in the next
article.
Warning 1: Make sure you know the format of result you’re expecting! If you expect a delta to
be 55.32 and the result is .5532, panic may ensue.
Before panicking or fixing problems, determine if it’s real. Did it ever work and, if so, how?
Warning 2: Sometimes you’ll get a different result during Regular Trading Hours (RTH) and After
Market Close (AMC). As an example, TOS recently returned an option BID_SIZE of 127300.00%
After Market Close and a more understandable 889 during Regular Trading Hours.
Warning 3: It is possible Data Export Fields which don’t appear to work actually do work but
they’re not being used the right way (or they’ll work in future revisions). If you find any
documentation, let us know!
Final Thoughts:
1. These lists were verified using ThinkOrSwim version 1880.75 during Regular Trading Hours and
the results presented were captured live. Any other version of ThinkOrSwim may have a
different list of Data Export Fields and/or different results (including nothing when you expect
something) may present at any time.
3. In all tables below, the equation for the first cell returning a result is =RTD("TOS.RTD",,$A2,B$1).
All other cells use the same formula, adjusted for their respective row and column.
Data Export Fields returning any result for options or non-options (quantity 86)
Data Export Fields returning any result for options (quantity 85 but less than 50 are useful)
Data Export Fields returning any result for any underlying other than options (quantity 86)
Data Export Fields which don’t return any result when used with RTD (quantity 327)
* For those that have read this far, thank you. Did you notice how clever it was to modify the RTD
equation the way we did in Part 2 so we could simply copy & paste it all over the place in Part 3?
If you go back to Part 1, the very first sentence you read was:
You can’t beat a spreadsheet for turning big chunks of data into actionable information.
Over the course of this article, we’ve reviewed different mechanisms which allow ThinkOrSwim to
communicate with Excel, written equations that use RTD, learned a bit about how to manipulate data
with Excel, and uncovered a raft (maybe even a boatload) of live and streaming information we could be
getting in Excel via ThinkOrSwim.
So, really, the goal of “Connecting ThinkOrSwim to Excel” was accomplished in Part 3. Well done! Pats
on the back all around!
In this series conclusion, we’re going to clean up the LockeRTD spreadsheet, then turn a chunk of live,
streaming ThinkOrSwim data into actionable information.
(Before we begin, bring up ThinkOrSwim and the LockeRTD Excel spreadsheet you saved last week.)
Clean-Up
Except for the updated values, here’s how we last left LockeRTD:
It’s ok but check out all the inapplicable option information for RUT in row 2. If we’re going to simply
copy & paste the formulas, letting Excel do all the heavy lifting, let’s put a little intelligence into the
equation so it only displays options data if the symbol entered in column B is actually an option.
Yes, it’s faster and easier to make it look good by simply deleting the equations from H2 to N2 but that
reduces flexibility. What does that mean? It means you couldn’t just add a symbol into column B, willy-
nilly, and let Excel do the work. You’d have to copy the equations in columns H through N only when
you enter an option in column B, then delete them when you change the symbol from an option to a
stock.
Ugh. Too much work. So let’s think like a contortionist and insert some flexibility into this act.
Pop Quiz: What’s the big difference in the symbol that separates options from everything else?
If you said, “the dot at the first position of the symbol,” good thinking! That means if there’s a dot in the
leftmost position, we want the option data and if there’s not a dot in the leftmost position, we don’t
want RTD to do anything.
=RTD("TOS.RTD",,H$1,UPPER($B2))
To this:
The new part of the equation is in red, so you can see what was added.
Breaking it down:
IF is a logical function that will return the first value if the condition is true and the second value
if the condition is false. Since it’s a function, like RTD or UPPER, notice that what follows – the
parameters – is enclosed in parenthesis.
LEFT($B2,1) is the LEFT function. The LEFT function returns some number of leftmost characters
from the beginning of some text. In this case, we want LEFT to return 1 character starting at the
leftmost character of the contents in cell B2. (Remember, we used $B to “pin” the column to B.)
IF(LEFT($B2,1) = ".", is the LEFT function inside the IF function. What it means is we want to look
at the leftmost 1 character in cell B2 (it’s the R from RUT) and if it’s a dot (.), then do what
follows the 1st comma OTHERWISE do what follows the 2nd comma.
1. What follows the 1st comma is the RTD equation we’ve been using. You already know
how it works but, if you don’t remember, go back to Part 2.
2. What follows the 2nd comma is "". Those two double straight quotes (not curly “smart
quotes” because, of course, they’re different ASCII characters) next to each other are
interpreted as “nothing – do nothing at all.”
Bottom Line: The equation can be translated to “If the first character in cell B2 is a dot, it must be an
option so go get its EXPIRATION from ThinkOrSwim…otherwise, do nothing.”
After you modify the equation in H2 and press <Enter>, you should see:
H2 is blank, which is exactly what we wanted. Copy & paste H2 over H2 through N3 (following the
instructions in Part 3) and you’ll see:
Now copy row 3 to rows 4 and 5 (revisit Part 3, More Option Data if you don’t remember how) for the
next step.
I’m already using a RUT APRIL 1000 Put so we’ll add a 950 as the center and a 900 as the lower leg. I
could certainly return to TOS to copy & paste the option code into column B but, since the symbol for
1000 is already there, it’s easier to simply edit B4 and change the 1000 to 950, then change the 1000 to
900 in B5:
Add column headers and quantities so column C and D looks like this:
Enter this equation in cell D2 to find the total deltas for the quantity of individual options:
=IF(AND(LEFT($B2,1)=".",C2<>0),C2*J2*10, "")
Hey! That’s similar to what we did in H2 to N5, isn’t it? Let’s break it down:
The AND function will result in TRUE if all the parameters passed to it are true. In this case:
o LEFT($B2,1)= "." will return TRUE if the first character of the symbol (column B) is a dot
(in other words, column B is an option)
o C2<>0 will return TRUE if there’s a number other than 0 in column C (we named that
column Qty)
o If you follow this logic, the AND function will return FALSE in row 2 because RUT isn’t an
option and, incidentally, there isn’t a quantity in column C. It will, however, return TRUE
for the next 3 rows because they’re options and there is some number other than 0 for
quantity.
C2*J2*10 multiplies the quantity times the option delta, for the total number of deltas
ThinkOrSwim is holding for that option, then multiplies the result by 10 so deltas are consistent
with our other option modeling tools (like OptionVue or ONE).
"" is, of course, nothing (as in, “do nothing if it isn’t an option”)
The equation can be translated to, “If there’s an option in column B of this row, and there’s some
quantity, multiply the quantity times the current delta supplied by ThinkOrSwim times 10 (qty*delta*10)
…otherwise, do nothing.”
Let’s add the total number of deltas ThinkOrSwim has for the Butterfly by placing this equation into D6:
=SUM(D2:D5)
Add a top border to the cell to make it look nice (go to Excel’s Home | Font and look for Border):
Now it’s easy to see the current price for RUT and how it’s changed since the previous trading day. Ditto
for all our Butterfly options, plus other interesting stuff (like the greeks), including the total deltas our
Butterfly is holding (according to ThinkOrSwim).
Conclusion
Many trades in the Locke In Your Success programs depend on taking action based on the greeks, like
when delta is too much or ratios exceed their proscribed limit. You can use the powerful tools within
Excel (like conditionally formatting the delta sum to be red if it’s over 100) to alert you when the
ThinkOrSwim greeks are telling you it’s time to look at adjusting.
The example here was simple, summing Butterfly deltas, but imagine the possibilities:
Decide which pattern of adjustments most keep your greeks under control
In general, you can quickly summarize a mountain of live, streaming data so you’re able to prove or
disprove theories, and move faster while making better decisions. The possibilities are limited only by
your imagination.
You’ve started down the trail of how to turn big chunks of data into actionable information. Enjoy your
journey!
(If you’d like, you can download the completed LockeRTD Excel file from www.LockeInYourSuccess.com.
It has everything you did plus a little more.)