Analyze Financial Data with Python Capstone project

Hi Everyone,

Here is my Analyze Financial Data with Python Capstone project. Attached are the repository to github for the project code and the presentation of the recommended optimized investment portfolio (pdf). After doing this analysis and running the Markowitz based quadratic programming optimization, I am think I might actually invest in this portfolio and see if it performs as predicted by the theory. (Of course, past performance does not guarantee future performance!).

If you have any comments or suggestions for improvements to this work, please feel free to reply here. Thanks!

https://github.com/Eximio-Mark/Optimized-Investment-Portfolio

https://github.com/Eximio-Mark/Optimized-Investment-Portfolio/blob/main/Your%20Portfolio%20by%20TCG.pdf

Nice work!
Indexing the stocks was a nice feature that improved clarity.
You included multiple value metrics which was a very nice addition.
Not sure if your 25th slide was the last. Not able to continue after this slide which is a pity as this last slide was the most interesting to me!

Way above and beyond.
Michael

Hi Michael,

Thanks for the kind words. I am glad you liked it.

I made some changes to the functions for random portfolios and optimized portfolios. The old function for random portfolios did not create a good spread of possible weights. The portfolios generated by the old function are bunched up around the mean. The way the function works actually eliminates any extreme weightings to one or two components of a portfolio, probably unintentionally. I used a different method that spread the distribution of weightings across all of the possibilities, included the extremes.

With regard to the optimized portfolio function, the old version did not produce output with the actual weightings of the various portfolio options along the efficient frontier. I made some changes in order to get that output. Those weightings are needed to build a real investment portfolio!

Regarding the presentation, yes, page 25 is the last page. The majority of the stocks in the portfolio were historically high risk / high return. As a result, the entire efficient frontier of portfolios is somewhat shifted to higher risk portfolios. I wanted to quickly demonstrate to the reader that some lower risk portfolios could be produced by allocating some assets to bonds. Of course, this could also be somewhat accomplished by changing the stocks in the portfolio - fewer highly volatile stocks and more low risk options. But stock-only portfolios will always be shifted more towards risk while mixing in bonds can provide portfolio options all the way down to very low risk.

Hi, Did you make the jupyter notebook yourself or is it from the course?

You start out with a fresh, empty Jupyter notebook. You build it up from a blank sheet yourself. It’s easier to do than it might appear at first.

You can also use the examples of the project of other students to help guide you.

Note: If you use the random portfolios and optimization functions I made, be careful. I made some changes to them to get more complete results. They behave differently than the functions provided by Codecademy.

Thanks for the help.

Hey Eximio,

I was really impressed with this. I come from the programming side more than the financial side of things. What resources did you use to have such a comprehensive setup for your project. For example your Assessment of the client case, the general investment criteria and how did you pick your initial universe of stocks. Total beginner here would love to hear or gain knowledge on the resources you used?!

Hi d_vox,

For the client case, the most basic criteria are the client’s age and appetite for risk. In general, you’d assume younger people should take on more risk as they have a longer time horizon to realize returns, to wait out long periods of market under performance, and even to make new money again when they lose some in the market. The important point is that higher risk should equate to higher returns. Combine that with a long time horizon and the investment portfolio can grow substantially. Older people do not have those attributes so should favor lower risk investments and portfolios.

In finance, the measure of risk that is typically used is volatility. Which simply means how much a stock changes from period to period (the course uses daily change, but you could look at a stock’s monthly change when you have many years of data). That’s where variance and standard deviation come in. They are basic measures of volatility and, therefore, risk. By this measure, the least risky security would be a treasury bond while the most risky would be an individual stock with a lot of volatility. Generally, investors expect higher returns from high risk stocks.

Another almost axiomatic concept in finance is that a diversified portfolio reduces risk relative to return. That requires a lot of words to explain. If you have not encountered that idea before, you can find some really good explanations with a Google search. Even better, ask ChatGPT to explain it.

Regarding selecting stocks, I manage some fairly large portfolios, so I’m looking at individual stocks, market data, and economic data regularly. To be honest, I got the stock ideas from what looks interesting to me personally. I also sort of deliberately chose some stocks that would be well known to most people and had some sex appeal, combined with some “boring” options… I already pretty much knew the risk vs return picture of those stocks, so I could select a mixed bag. I have access to reams of data from my brokerage. If you have a brokerage account, you can probably get this sort of data. If not, Yahoo Finance has pretty much everything you’d need.

Since some time has gone by since I performed this project, you can see that there was definitely no magic in the choices! Some have had nice returns since November 2023. Nvidia has done great. Amazon and Google have performed nicely. The S&P 500 over all has had a nice run. But Tesla and Boeing have been hammered lately!

Perhaps a good approach for you would be to look at the S&P500 sector leaders and choose those with the lowest PEG ratios. PEG ratios are not a perfect measure - there are no perfect measures - but it’s a good place to start. Then throw in one or two high flyers.

Be aware that the functions return_portfolios and optimal_porfilios that were made by Codecademy are heavily biased towards higher risk stocks (high volatility … meaning highly standard deviation). Those functions will result in most of the weightings going towards the stocks with the highest expected returns. I didn’t have several hours to completely re-build them, but I made some changes so that they provide a wider spread of portfolio weightings. Even my adjusted versions of those functions are still somewhat biased.

I hope that helps! Good luck with the project. It’s a good learning experience.

I appreciate you taking the time to talk about this! Ill read and digest. Is your financial acumen from your day job or did you study something/ had training before working at your brokerage? I am looking to get into the field and leveraging my Computer Science degree to work more specifically in the finance sector. Any books/courses etc… to recommend. Again thank you for such a comprehensive answer!

I don’t believe in attempting to time the market.