Calculate your stock portfolio performance in excel
Track your stock investments in excel and use a web query to import current stock prices from yahoo.
- Setup excel sheet
- Concatenate stock symbols
- Import current stock share prices using a web query
- Refresh web query to update stock prices
Download excel tutorial file: Track your stock portfolio.xls.
Setup excel sheet
Here is a picture of my excel sheet:
Formula in G2:
=D2*E2+F2 + ENTER
copied down as far as needed.
Formula in J2:
=INDEX(Sheet2!$C$3:$C$124, MATCH(Sheet1!B2, Sheet2!$A$3:$A$124, 0)) + ENTER
copied down as far as needed.
Formula in K2:
=J2-G2 + ENTER
copied down as far as needed.
Concatenate stock symbols
We need to concatenate ticker symbols in column B to be able to use them in a web query. I am using this simple user defined function that I have created in a previous post. I am using this udf in cell A1 on sheet2.
Formula in A1 on sheet2:
=ConcComma(Sheet1!B2:B6) + Enter
VBA
Function ConcComma(Substrings As Range)
Dim CELL As Range
For Each CELL In Substrings.Cells
ConcComma = ConcComma & CELL.Value & ","
Next CELL
ConcComma = Left(ConcComma, Len(ConcComma) - 1)
End Function
How to Create Custom User Defined Excel Functions
Import current stock share prices using a web query
- Select Sheet2
- Select cell A3
- Click "Data" tab.
- Click "From Web"

- In the address field type:http://finance.yahoo.com/q/cq?d=v1&s=["Quote","Quote"]
- Click yellow arrow to select the whole table.
- Click Import
- Select where you want to place the imported table (cell A3 on sheet2)
- Enter parameter value "Quote"
- Click "Select cell" symbol
- Click cell A1 on sheet2
- Enable "Use this value/reference for future refreshes"
- Click OK.
Refresh web query to update stock prices
- Click "Data" tab.
- Click "Refresh All"
Download excel sample file for this tutorial.
Remember to enable macros.
Track your stock portfolio.xls
(Excel 97-2003 Workbook *.xls)









September 20th, 2011 at 6:19 pm
This tool works great, until I start inserting more items in row 54 and beyond on sheet 1...then I get an error in Excel noting "bad parameter type. MS Excel is expecting a different kind of value than what was provided." This happens when I update the formula in sheet 2, cell A1 (concatenate) to include anything beneath row 53 in sheet 1. How can I remedy this?
Thanks, Robert
September 21st, 2011 at 9:32 am
Robert,
I think the connection string (the concatenated string in cell A1, sheet2) can´t exceed 255 characters.
I did not know this when I created this post. I´ll see if I can find a solution.
October 13th, 2011 at 3:24 pm
Hi,
can you please assist us to Import stock data BSE india web site as like yahoo what have did on the above
Many Thanks,
Vijay
October 24th, 2011 at 5:36 pm
Hey Oscar, hey all,
I wanted to let you know that I just finished a project in college around machine learning and stock trading. While it wasn't too successful, I did build a pretty good pipeline for bulk downloading historical stock quotes and quantitative data. I've made it available at http://www.free-stock-data.com and you can use it to download data to your Excel sheets. It's probably a better route if you need long-term or verbose data, and you can download an entire portfolio at once.
Cheers!
December 9th, 2011 at 4:51 am
Nice work. How would one use excel to create a graph of end of day portfolio valuation over time? For example, enter your portfolio in the spreadsheet you created and then chart the portfolio end of day value from its inception?
March 1st, 2012 at 8:44 am
Hi Oscar,
I downloaded and used the sample that you've provided. Worked fine till I started getting the same error that Robert has mentioned. I tried saving the file as ".xlsm" in Excel 2k7, but the problem still persists.
You mentioned that you were trying to find a solution. Were you successful?
Pls let us know.
Rgds
March 1st, 2012 at 8:58 am
Also, is there a possibility of tracking the SELL orders and then tracking the profit/loss?
March 6th, 2012 at 2:11 pm
Sujesh,
Try this file:
Stock-portfolio-v2.xls
May 11th, 2012 at 5:04 am
Hi Oscar,
Your latest file: stock-portfolio-v2.xls appears to work for much larger number of stocks. Can you explain how you did it?
Also, it appears to take a long time to download. Have you intentionally added delays to avoid Yahoo blocking you out?
Thanks.
- Abs
May 14th, 2012 at 2:34 pm
Abs Raw,
Your latest file: stock-portfolio-v2.xls appears to work for much larger number of stocks. Can you explain how you did it?
I used the user defined function in this blog post:
Excel udf: Import historical stock prices from yahoo
Also, it appears to take a long time to download. Have you intentionally added delays to avoid Yahoo blocking you out?
No, there are no delays. I am guessing it takes longer to download quotes from yahoo.