5
An Easy Shortcut You can just open a file of comma separated values using Excel, then save it as a normal Excel workbook But lets suppose we have a workbook set up with macros to analyze stock data, so we want to load this data into our existing workbook

6
Using the Data tab You can use the Get External Data menu items in the Data tab to load data into Excel

7
The Dialog using the From Text option Text file extensions

8
Excel Will Assist You… After you choose your file, Excel uses a Wizard to help you load your data correctly For example, it lets you pick a delimiter (comma, tab, or others) It lets you omit columns you dont want

9
Heres the result

10
Using a Macro to Read Data What if we want a macro to read the data into the spreadsheet? VBA has a suite of functions to deal with this scenario. [Chapter 27 of Walkenbach has more information and examples] We used a variation on the methods weve already learned to read from a file, so you can see some other options We leave the leftmost columns blank for some calculated values to be put in later This macro takes a while to run because the data file is long

11
Reversing the Data The data come from Yahoo with the most recent first. We want earliest first so we can do some historical analysis more conveniently We wrote a macro to reverse the data by calling an Excel function. This also gives you an example of using Excel functions in your VBA code

12
Stock Price Technical Analysis Technical analysis is a way to study stock prices without knowing anything about the company The theory is that the price movements themselves will help you predict future prices We neither endorse nor condemn this effort, but there is a big technical analysis industry out there Our example shows you some basic technical analysis

13
Moving Averages One big staple of technical analysis is the moving average. The idea is that by averaging over several or more days, we smooth out some of the random variations We start with a one-day average of the high, low, and close, then make a three day moving average of that quantity This just means that the value for a day is the average of that day and the prior two days (since we are computing on the close, we can include the current day)

14
Close vs Moving Average Our theory is that if the market closes over yesterdays three-day average, and it closed under yesterday, then its going up Likewise, if the close switches from over to under, the price is going down If you run all the macros and look through the historical data, you will see that this is a reasonably good predictor, though it does get a number of false signals

15
Your Assignment Your assignment is to introduce a multi-day average similar to our three day average, and find the cross days for it. The idea is that maybe a longer period will eliminate some of the false signals You will need to move the data over two more columns to the right to make room for the two new columns. Add new headings and put in buttons to do the new computations

16
Above and Beyond A fun thing to do is to write some code that goes through the historical data and the cross days, and uses the signals to buy and sell. In other words, buy every day the up signal appears, and sell short every day the down signal appears. Add up the profits and losses as you go. See if the rule makes money, and compare it to the 5-day rule. WE ARE NOT SUGGESTING THAT YOU ACTUALLY USE THIS METHOD FOR TRADING!!! Real technical analysts use much more sophisticated indicators, and it helps to know some fundamentals about the stock as well