Using Excel to Track Your Stock Portfolio

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 (Typing Numbers In The Spreadsheet)

To get your old portfolio values, you will need to look them up one by one and type them in to excel.

First, open a new spreadsheet, and in cell A1 type “Date”, and in cell B1 type “Portfolio Value”. These are called the “Column Headings”. You can even make them bold so they stand out more. Your spreadsheet should look like this:

portfolio excel 1

Next, type the date you want to look at in each column under “Date”, from oldest to newest.

portfolio dates

Tip: If you want to use every day, after typing in the first date you can click and hold the bottom right corner of the cell, then drag down and Excel will automatically fill in the next cells.

Now go to the Rankings page on HowTheMarketWorks. Here you can look up your portfolio value from the end of each day. Here are the different parts of the page:

HTMW Image 1

1. This button brings you to the class rankings page you see right above here. You can find it under the “My Portfolio” menu option.

2. This little grey box is where you can choose which of your contest portfolios you’re looking at. Always make sure that you have the right contest chosen in that box. Everyone has a practice portfolio plus whatever contests they joined, so even if you don’t use the practice portfolio you might accidentally be using that one if you’re not careful!

3. This is your current portfolio value. If you wanted to, you could check this every day after 4:30 pm EST and copy that number down. If you do that then you won’t need to worry about #4 and #5!

4. This is the date box where you set what day’s portfolio value you want to see. In the example picture, the date is November 20 2015. If I wanted to see my portfolio value two days earlier then I would just change the date to November 18 and hit the “GO” button.

5. This is where you can see everyone’s portfolio values for the day you chose in #4.The “Current Value” section is what you’re looking for. Find your username on the left side and then see what your current portfolio value was for the day you picked and copy it down. The % Gain/Loss section is your portfolio’s total gain or loss since the first day of your contest. This number is a quick and easy way to see how well you’re doing in your contest.

Repeat steps 4 and 5 for each day that you need to get your portfolio value for and copy each value and it’s date into your excel sheet like so:

portfolio 3

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.

We will use Sprint stock (symbol: S). Go to the quotes page and search for S:

sprint quote

Next, click the “Historical” tab at the top right of the quote:

sprint historical

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):

sprint highlight

Now copy the data, select cell A1 in your blank excel spreadsheet, and paste.

sprint excel

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“:

sprint 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“:

sprint sort by

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:

excel expand

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”:

autofit 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:

sprint empty

Instead, click on “B” and drag all the way to “H” to select the full columns:

sprint empty 2

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 Account Balances”.

account balances download

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.

accountbalances

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).

Transaction History

First, let’s copy our transaction history. Select the information in the box above, then paste it in to your blank sheet:

trans history

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

unmerge

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.

formatted trans history

You can now save this sheet and close it.

Open Positions

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:

op merged

Just like with the Transaction History, first unmerge all your cells, then delete the blank columns:

op cleared

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

op 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:

op final

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:

portfolio 3

Next, highlight your data, and click “Insert” on the top tab:

graph 1 insert

Here, under the “Charts” section, click on the one with lines, and choose the first “2d Line Chart“:

graph 1 choose

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.

graph 1

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”

graph 2 column

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:

graph 2 calculation

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:

graph 2 calc 2

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:

graph 2 percent

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:

graph 2 error

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”:

graph 2 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:

graph 2 almost
Tip: Since we don’t have any data for January 11th here, we can also uncheck that on the right side to not show that date.

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”:

graph 2 format

A new menu will appear on the right side of the screen. Here, click “Labels”, then set the Label Position to “Low”.

graph 2 finished

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:

op final

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”:

graph 3 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”:

graph 3 almost

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”):

graph 3 finish

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”:

graph 3 pie 1

Next, find the “Pie” charts, and pick whichever chart you like the best.

graph 2 pie 2

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.

graph 2 pie 3

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:

profit 1

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).

trans calc 2

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.

trans calc 3

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.

trans calc 4
You can see the calculation we used at the top

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:

trans calc 5

Second: add this number to the “Total Amount” from when you sold your shares.

trans calc 6

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.

Pop Quiz!

If reading this article was an Assignment, get all 3 of these questions right to get credit!

Click "Next Question" to start the quiz!

1 of 3) How can you find your historical portfolio value?
2 of 3) What kind of graph is best for seeing your portfolio value over time?
3 of 3) Where can you change how a chart's colors and legend appears?

We have received your answers, click "Submit" below to get your score!