In this article we will be looking at how you can use Excel with your HTMW account to keep track of your account’s performance.
Using Excel To Track Your Stock Portfolio – Getting Some Data
Before we can do anything with Excel, we need to get some numbers! The information you use in excel is called “Data”. Some of it we will need to write down, some can be copied and pasted, and some we can download directly as an excel file.
Getting Your Historical Portfolio Values
To get your old portfolio values, you can copy and paste them out of the HTMW website..
First, you will need to get your historical portfolio values from the HTMW website. You can find these on the “Graph My Portfolio” page.
This will open up a small window showing what your portfolio value was for every day of the contest. Highlight the information you want, then right click and “Copy”.
Next, open up a new blank spreadsheet and click cell A1. You can then right-click and “Paste” the data in. The column headings should be included too.
If the column headings are not included, right-click the first row and select “Insert Row”. This will add a new row to the top of the spreadsheet where you can type in the column names.
Now “Save” your file somewhere you can easily find it later, you’ve got some data!
Getting Historical Prices For Stocks (Copy And Pasting Data In To A Spreadsheet)
For this example, we want to get the historical prices for a stock so we can look at how the price has been moving over time. First, a new blank spreadsheet in Excel.
Next, click the “Historical” tab at the top right of the quote:
Next, change the “Start” and “End” dates to the time you want to look at. For this example, we will use the same dates that we saved for our portfolio values, January 11 through January 15, 2016.
Once you load the historical prices, highlight everything from “Date” to the last number under “Adj. Close” (it should look like this):
Now copy the data, select cell A1 in your blank excel spreadsheet, and paste.
Congratulations, we have now imported some data into excel! Notice that your column headings are already detected – this will be important later.
From there, there are few things we would like to change.
Changing The Order Of Your Data
First, this data is in the opposite order as our portfolio values. To get it in the same order, we want to sort this table by date, from oldest to newest. At the top menu, click on “Data“, then click “Sort“:
You can now choose what we want to sort by, and how to sort it. If you click the drop-down menu under “Sort By”, excel lists all the column headings it detects (select “Date“). Next, under “Order”, we want “Oldest to Newest“:
Now your data should be in the same order as your portfolio values from earlier.
Changing Column Width
Next, you’ll notice that “Volume” appears just as “########”. This is not because there is an error, the number is just too big to fit in the width of our cell. To fix this, we can increase and decrease the widths of our cells by dragging the boundaries between the rows and columns:
Tip: if you double click these borders, the cell to the left will automatically adjust its width to fit the data in it.
If you want to automatically adjust all your cells at once, at the top menu click “Format”, and “Auto Fit Column Width”:
Once you’ve adjusted your volume column, everything should be visible!
Removing Columns You Don’t Need
I think that we will only want to use the Adj. Close price in the calculations we will be doing later (the “Adj. Close” price is the closing price adjusted for any splits or dividends that happened since that day). This means I want to keep the “Date” and “Adj. Close” columns, but delete the rest.
If you try to just select the data and delete it, you’ll end up with a big empty space:
Instead, click on “B” and drag all the way to “H” to select the full columns:
Now right-click and click “Delete”, and the entire rows will disappear. Now the Adj. Close will be your new column B, with no more empty space. You now have your historical price data, so save this excel file so we can come back to it later.
Getting Your Transaction History And Open Positions (Copying data from another spreadsheet)
If you want a copy of your open positions or transaction history in Excel, you can download it directly from HowTheMarketWorks.
First, go to your Contests page and find the contest you want the information for. Then click “Download Details”.
This will download a spreadsheet showing your transaction history, open positions, and your current cash balance with portfolio value. You might get a warning when opening the file, this is normal.
The spreadsheet should look similar to the one above. The top red square is your transaction history, the bottom red square is your Open Positions.
To actually use this data, you will need to open a new blank spreadsheet and copy these boxes (just like we did above).
First, let’s copy our transaction history. Select the information in the box above, then paste it in to your blank sheet:
Before we can use this data, notice that there are some “Merged Cells” – places where the data is spread across two cells. This is the case with the Ticker, Commission, and Total Amount cells. We need to “unmerge” these cells to make our data usable.
To do this, select all your data, then on the main menu bar click on “Merge and Center“. Under this, click “Unmerge Cells”
Now that we have our data all in their own cells, we can start deleting the rows and columns we don’t need. For example, rows 2 and 3 have our beginning cash, which we don’t need in our transaction history. Columns E and H are now blank, so we can get rid of those too. Once you delete the rows and columns you don’t need, you can also autofit the row width to make the “date” visible.
You can now save this sheet and close it.
Getting your open positions will be very similar, but we need to enter the Column Headings in Row 1 ourselves. Open a new blank spreadsheet, and paste in the second box from the file you downloaded from HowTheMarketWorks. It should look something like this:
Just like with the Transaction History, first unmerge all your cells, then delete the blank columns:
Now we need to add our column headers. To do this, we need to insert a new row.
First, click “1” to select the entire first row. Next, click “Insert”
Now everything should move down, and your first row should be blank. Enter these as your column headers:
“Quantity” “Symbol” “Price” “Total Cost“
It should look like this when finished:
And thats it! Now save your spreadsheet for later.
Using Excel To Track Your Stock Portfolio – Graphing
Now that we have some data, let’s make some graphs with it! We will go over how to make line graphs of your daily portfolio value and your portfolio percentage change, plus a bar chart showing your open positions. This is usually the most fun part of using excel to track your stock portfolio.
Line Graph – Your Daily Portfolio Value
First, we want to make a line graph showing our daily portfolio value. First, open your spreadsheet that has your daily portfolio values:
Next, highlight your data, and click “Insert” on the top tab:
Here, under the “Charts” section, click on the one with lines, and choose the first “2d Line Chart“:
And that is it! Your new chart is ready for display. You can even copy the chart and paste it in to Microsoft Word to make it part of a document, or paste it into an image editor to save it as an image.
Line Graph – Portfolio Percentage Changes
Next, we want to make a graph showing how much our portfolio has changed every day. To do this, first we need to actually calculate it.
Doing calculations in Excel
In the next column we will calculate our daily portfolio percentage change. First, in the next column, add the header “% Change”
Now we need to make our calculation. To calculate the percentage change each day, we want to take the difference between the most recent day’s value minus the day before, then divide that by the value of the day before:
Percentage Change = (Day 2’s Value – Day 1’s Value) / Day 1’s Value
To do this, in cell C3 we can do some operations to make the calculation for percentage change. To enter a formula, start by typing “=”. You can use the same symbols you use when writing on paper to write your formulas, but instead of writing each number, you can just select the cells.
To calculate the percentage change we saw between day 1 and day 2, use the formula above in the C3 cell. It should look like this:
Now click on the bottom right corner of that cell and drag it to your last row with data, Excel will automatically copy the formula for each cell:
You now have your percentages! If you want them to display as percentages instead of whole numbers, click on “C” to select the entire column, then click the small percentage sign in the tools at the top of the page:
Making Your Graph With Only Certain Columns
Now we want to make a graph showing how our portfolio was changing each day, but if we try to do the same thing as before (selecting all the data and inserting a “Line Chart”, the graph doesn’t tell us very much:
This is because it is trying to show both the total portfolio value and the percentage change at the same time, but they are on a completely different scale!
To correct this, we need to change what data is showing. Right click on your graph and click “Select Data”:
This is how we decide what data is showing in the graph. Items on the left side will make our lines, items on the right will make up the items that appear on the X axis (in this case, our Dates).
Uncheck “Portfolio Value”, then click OK to update your graph:
This is closer, but now we want to move the dates back to the bottom of the graph (here they are along the “0” point of the Y axis).
To do this, right-click on the dates and select “Format Axis”:
A new menu will appear on the right side of the screen. Here, click “Labels”, then set the Label Position to “Low”.
Congratulations, your graph is now finished! You can now easily see which days your portfolio was doing great, and which days you made your losses.
Bar Chart – Seeing Your Open Positions
Next we would like to make a bar chart showing how much of our current open positions is in each stock, ETF, or Mutual Fund.
First, open your spreadsheet with your Open Positions. It should look something like this:
Since we want to make a bar chart, we can only have two columns of data. We want one column showing the symbol, and a second column showing how much it is worth. The “Total Cost” column is the current market value of these stocks, so that is the one we want to keep. However, we don’t want to delete the quantity and price, since we might want it later. Instead, select the columns you don’t want, and right-click their letter (A and C in this case). Then, select “Hide”:
Now the columns that we don’t want in our chart are hidden. We can always get them back later by going to “Format” -> “Visiblity” -> “Unhide Columns”. Now select your data and insert a “Bar Chart” instead of a “Line Chart”:
Before you’re finished, your chart will say “Total Cost”. You can change this by clicking on “Total Cost” and editing to say whatever you would like (like “Portfolio Allocation”):
This graph is now finished, but you can also try changing the Chart Type to try to get a Pie Chart. First, right click your graph and select “Change Chart Type”:
Next, find the “Pie” charts, and pick whichever chart you like the best.
Last, now we don’t know which piece of the pie represents which stock. To add this information, click your pie chart, then at the top of the page click “Design”. Then select any of the options to change how your pie chart looks.
Congratulations, you’ve converted your bar chart into a pie chart! This one should look almost the same as the one you have on the right side of your Open Positions page.
Using Excel To Track Your Stock Portfolio – Calculating The Profit And Loss Of Your Trades
The most important reason you would want to use excel to track your stock portfolio is trying to calculate your profit and loss from each trade. To do this, open the spreadsheet with your transaction history. It should look something like this:
Tip: If you have not bought and then sold a stock, you can’t calculate how much profit you’ve made on the trade.
First, we want to change how the data is sorted so we can group all the trades of the same symbol together. Use the “Sort” tool to sort first by “Ticker”, next by “Date” (oldest to newest).
For DWTI and SPY, we haven’t ever “closed” our positions (selling a stock you bought, or covering a stock you short), so we cannot calculate a profit or loss. For now, hide those rows.
Now we’re ready to calculate! Lets start with the trade for S. This one is easy because the shares I sold equal the shares I bought. This means if we just add the “Total Amount”, it will tell us the exact profit or loss we made on the trade.
This does not work for UWTI, because I sold a different number of shares than I bought. This means that I need to first calculate the total cost of the shares I sold, then I can use that to determine my profit.
First: multiply your purchase price times the number of shares you sold:
Second: add this number to the “Total Amount” from when you sold your shares.
Now you have your profit or loss for this trade. Note: this is the method for if you bought more shares than you sold – if you bought shares at different prices, then sell them later, you’ll need to calculate your Average Cost to use in your calculation.