## Portfolio Selection and Optimization

Posted by **Mario Valadez Trevino**

Updated: Oct 31, 2019

*Overview*

*Overview*

Portfolio is a term used to describe a selection of assets like stocks, currency, bonds, cash, etc. A portfolio's holdings should reflect the owner’s requirements and needs (such as risk tolerance/aversion and expected return). Those requirements depend on the reason for and the time horizon of the investment.

Portfolio selection and stock analysis can be extremely complicated if the main intention is to capitalize on minute-to-minute stock price changes. But if you want to evaluate different portfolio alternatives based on different degrees of risk and return, there are easy ways to do it.

*The Main Variables and Sharpe Ratio*

*The Main Variables and Sharpe Ratio*

The 2 main variables that help us evaluate a portfolio are the variance (volatility) and the expected return.

This simply tells us how much the price of a particular asset changes. It would never tell us if an asset is good or bad, just its day to day variation.__Volatility (standard deviation)__:This can indicate if one asset is better than another one, but the main problem is that past performance can’t guarantee future behavior, so it is basically just a reference for evaluation.__Return__:

* *__Sharpe Ratio:__* *Sharpe ratio (named for William F. Sharpe), is an indicator that lets us measure both variables at the same time. This ratio basically tells us how much more return a particular set of assets gives us above a risk-free rate (such as a 10 year treasury bond) and then adjusts it by volatility so that they can all be compared in the same terms. It is basically the same process as normalizing the day-to-day variation compared to the risk-free rate.

*How Graphing and Simulation Can Help us Find the Best Portfolio*

*How Graphing and Simulation Can Help us Find the Best Portfolio*

Simulation and graphing are very powerful tools for finding the best portfolio. In a ‘volatility vs return’ graph we can find the combination of assets that maximizes the return for a particular type of volatility.

If we simulate different portfolio weight combinations we can understand the main idea of the Sharpe ratio concept and how it can be compared to a portfolio that minimizes risk.

The two main points to consider as a reference in the graph are:

**Minimum Variance Portfolio:**This combination of assets will minimize the risk. It won’t necessarily give us a good return, but is a good reference for evaluating other combinations. If you don’t have very little tolerance for risk, this might be the best choice.**Max Sharpe Ratio:**This point in the graph is basically the asset combination that gives us a better rate of return compared to its volatility.

This graphic method is particularly good if you are choosing from a few assets. However, if you try to make a graph out of more assets, it becomes less informative.

*Prefiltering Stocks Based on Particular Needs*

*Prefiltering Stocks Based on Particular Needs*

How can you optimize a portfolio if you have plenty of options? Based on your specific needs you can prefilter the assets in a way that you know you will only be getting the ‘good’ options.

How do I optimize a portfolio if I have plenty of options? Based on your specific needs you can prefilter the assets in a way that you know you will only be getting the ‘good’ options.

So why evaluate a particular asset with a negative return or an asset that gives you really low return and has plenty of volatility? This is when prefiltering proves beneficial.

Definitively the portfolio with the lowest volatility will never have the same result as the other two but they will most likely provide less variation. In the last graph we can see that even though the best return stock combination will more likely provide a better average return, it also carries more risk. If your time horizon for the investment is short term, you will want to avoid that. In the middle graph we can see that the best Sharpe ratio stock strikes a perfect balance between both.

*Takeaway 1: Basic indicators can filter unnecessary assets that we won’t have the capacity to analyze.*

*Optimization of the Best Portfolio*

As we saw, graphing and simulation works great for a limited amount of assets. If we prefilter those assets, we might be able to get a very good solution but it won’t necessarily be the best one.

A more efficient way to find the best option is to use optimization.In optimization, we just try to solve for the best weights combination that will maximize the Sharpe ratio or minimize the volatility.

*Takeaway 2: Optimization can help us better determine an asset portfolio when the list of assets being compared is too big.*

When optimizing more than 500 assets (S&P 500) we see that we can reach a better solution. This solution is intended as a guide since you will end up with a 50 asset portfolio and you probably just want to keep the top 5 so that the management can be simplified

*Conclusions*

*Conclusions*

Graphing and simulation are great tools for interpreting how different weights of assets can change a portfolio's expected outcome. When the portfolio starts getting more complicated because due to the increasing number of options, then optimization is a better tool. Definitively, if the number of assets is very large and it takes too long to come up with the best solution during optimization, then you can apply some prefiltering to the assets since you already know some of them won’t even move your solution significantly.

*About the Data*

*About the Data*

Data was used from yahoo finance using an API. All the code can be found in the file ‘portfolio_optimization.py’ inside the ‘live_portfolio_scraper’ GitHub repository (https://github.com/mavaladezt/live_portfolio_scraper).

## Apply for the Upcoming NYC Data Science Bootcamp

The first step in becoming a data scientist is to complete your Data Science Bootcamp Application. Just click the button to apply. It's free and will only take you about 5 minutes.

### Mario Valadez Trevino

Mario Valadez Trevino is a NYC Data Science Fellow with a B.S. in Industrial Engineering with minor in Systems Engineering and an MBA. Mario has relevant experience in demand forecasting, production and transportation planning, warehouse management systems and...

View all articles### Subscribe Here

### Posts by Tag

- Meetup (101)
- data science (68)
- Community (60)
- R (48)
- Alumni (46)
- NYC (43)
- Data Science News and Sharing (41)
- nyc data science academy (38)
- python (32)
- alumni story (28)
- data (28)
- Featured (14)
- Machine Learning (14)
- data science bootcamp (14)
- Big Data (13)
- NYC Open Data (12)
- statistics (11)
- visualization (11)
- Hadoop (10)
- hiring partner events (10)
- D3.js (9)
- Data Scientist (9)
- NYCDSA (8)
- Web Scraping (8)
- Career (7)
- Data Scientist Jobs (6)
- Data Visualization (6)
- Hiring (6)
- Open Data (6)
- R Workshop (6)
- APIs (5)
- Alumni Spotlight (5)
- Best Bootcamp (5)
- Best Data Science 2019 (5)
- Best Data Science Bootcamp (5)
- Data Science Academy (5)
- Demo Day (5)
- Job Placement (5)
- NYCDSA Alumni (5)
- Tableau (5)
- alumni interview (5)
- API (4)
- Career Education (4)
- Deep Learning (4)
- Get Hired (4)
- Kaggle (4)
- NYC Data Science (4)
- Networking (4)
- Student Works (4)
- employer networking (4)
- prediction (4)
- Data Analyst (3)
- Job (3)
- Maps (3)
- New Courses (3)
- Python Workshop (3)
- R Shiny (3)
- Shiny (3)
- Top Data Science Bootcamp (3)
- bootcamp (3)
- recommendation (3)
- 2019 (2)
- Alumnus (2)
- Book-Signing (2)
- Bootcamp Alumni (2)
- Bootcamp Prep (2)
- Capstone (2)
- Career Day (2)
- Data Science Reviews (2)
- Data science jobs (2)
- Discount (2)
- Events (2)
- Full Stack Data Scientist (2)
- Hiring Partners (2)
- Industry Experts (2)
- Jobs (2)
- Online Bootcamp (2)
- Spark (2)
- Testimonial (2)
- citibike (2)
- clustering (2)
- jp morgan chase (2)
- pandas (2)
- python machine learning (2)
- remote data science bootcamp (2)
- #trainwithnycdsa (1)
- ACCET (1)
- AWS (1)
- Accreditation (1)
- Alex Baransky (1)
- Alumni Reviews (1)
- Application (1)
- Best Data Science Bootcamp 2020 (1)
- Best Data Science Bootcamp 2021 (1)
- Best Ranked (1)
- Book Launch (1)
- Bundles (1)
- California (1)
- Cancer Research (1)
- Coding (1)
- Complete Guide To Become A Data Scientist (1)
- Course Demo (1)
- Course Report (1)
- Finance (1)
- Financial Data Science (1)
- First Step to Become Data Scientist (1)
- How To Learn Data Science From Scratch (1)
- Instructor Interview (1)
- Jon Krohn (1)
- Lead Data Scienctist (1)
- Lead Data Scientist (1)
- Medical Research (1)
- Meet the team (1)
- Neural networks (1)
- Online (1)
- Part-time (1)
- Portfolio Development (1)
- Prework (1)
- Programming (1)
- PwC (1)
- R Programming (1)
- R language (1)
- Ranking (1)
- Remote (1)
- Selenium (1)
- Skills Needed (1)
- Special (1)
- Special Summer (1)
- Sports (1)
- Student Interview (1)
- Student Showcase (1)
- Switchup (1)
- TensorFlow (1)
- Weekend Course (1)
- What to expect (1)
- artist (1)
- bootcamp experience (1)
- data scientist career (1)
- dplyr (1)
- interview (1)
- linear regression (1)
- nlp (1)
- painter (1)
- python web scraping (1)
- python webscraping (1)
- regression (1)
- team (1)
- twitter (1)