Join the Quant Scientist Newsletter

Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...

Join 11,500+ Quant Scientists learning one article at a time

Join 11,500+ Quant Scientists learning one article at a time

Portfolio Optimization with Riskflolio Lib

Optimizing Nancy Pelosi's Stock Portfolio in Python (1400% Return Over 6 Years)

May 05, 20246 min read

Python is crazy for finance! In this QS Newsletter (get the code), we are showing how to optimize Nancy Pelosi's investment picks for a 1400% return over 6 years (that's a 33% compound annual growth rate). Today, you learn:

Disclaimer:

The information and educational material provided by Quant Science, LLC are for educational purposes only and should not be considered as financial advice or recommendations to purchase, hold, or sell any securities or other financial instruments. Before you proceed, please review our full disclaimer here.

Factor Analysis with Alphalens

Join the Quant Scientist Newsletter (and Get the Code)

Want exclusive access to our FULL codebase for this Quant Science tutorial plus dozens more? The code is in the QS015 Folder. Join here:

Quant Scientist Newsletter - Get the Code

NEW: Free 5-Day Algorithmic Trading Course

5 Day Algorithmic Trading Course

Are you interested in learning Algorithmic Trading with Python? Do you want to learn how to execute trades automatically, how to find edge, backtest trading strategies, analyze risk, then take your winning trades from Paper Account to Production (Live Trading)?

If the answer is Yes, then we have a NEW Free 5-Day Algorithmic Trading.  

👉 Click here to join our free 5-Day Algorithmic Trading Course.

Who is Nancy Pelosi (and Why are We Analyzing Her Portfolio)?

On February 8th, the twitter handle, @PelosiTracker_, reported that elements of Nancy Pelosi's portfolio were up big. Nancy Pelosi's estimated net worth is $114,662,521 in 2018. The most interesting part. Her annual salary is $193,400 a year.

Custom HTML/CSS/JAVASCRIPT

This has led many recent investors to label Nancy the modern-day GOAT of investing. Much of her net worth is attributed to Venture Capital (her husband, Paul Pelosi, who runs Financial Leasing Services, Inc, a San Francisco-based real estate and venture capital investment firm).

More recently, Nancy Pelosi's trading activity has come into the spotlight for being an early mover on stock of Nvidia (NVDA) and several other high profile companies that have experienced extraordinary growth.

Nancy Pelosi came under scrutiny because of her role as Speaker of the House in which she has the ability to influence laws that govern many of the companies that she is actively investing in.

Nevertheless, Pelosi has shown a tremendous track record in her stock picks in recent years. So today, we're analyzing her investment universe. And more specifically we'll optimize her portfolio to determine the weights that maximize Sharpe.

What is Portfolio Optimization?

Portfolio optimization is a mathematical method used to select the best allocation of assets in an investment portfolio, given certain objectives and constraints. This process seeks to optimize an objective function, typically maximizing returns, minimizing risk, or finding a balance between the two under certain constraints such as budget, risk tolerance, and regulatory requirements.

Efficient Frontier

Efficient Frontier

The Efficient Frontier is a concept from Modern Portfolio Theory, introduced by Harry Markowitz in the 1950s. It represents a set of portfolios that offer the highest expected return for a given level of risk or the lowest risk for a given level of expected return. This set forms a curve on a graph plotting expected return (y-axis) against portfolio risk (standard deviation of returns, on the x-axis).

  • Upper Boundary: The portfolios on the efficient frontier are not outperformed by any other portfolios in terms of risk-return balance. They are considered optimal because no other portfolios offer higher returns for the same risk or lower risk for the same returns.

  • Portfolio Selection: An investor chooses a portfolio along the frontier based on their risk tolerance. Those who tolerate more risk might choose a portfolio further to the right (higher risk and higher expected return), while risk-averse investors might select a portfolio towards the left (lower risk and lower expected return).

  • Visualization: The curve helps investors visualize and choose among the various trade-offs between risk and return.

Portfolio Optimization in Python: Riskfolio

Riskfolio-Lib

To use the Efficient Frontier in practical investment decisions, investors can use portfolio optimization software or tools, such as Riskfolio-Lib in Python, which help in determining the weights of assets in a portfolio. By inputting historical returns data and constraints, investors can calculate and plot the efficient frontier to see their options for asset allocation.

Full Tutorial: Optimizing Nancy Pelosi's Investment Portfolio for a 1400% 6-year return

Ok, let's dive in and see what you can optimize Nancy Pelosi's Investment Portfolio in Python. First, make sure to sign up for our Newsletter to get all of the code you see today.

Step 1: Download Stock Data from Yfinance

Next, run this code from the "QS016-nancy-pelosi-portfolio" Folder:

Code setup alphalens

This code downloads data for the top 8 stocks that are in Nancy Pelosi's portfolio according to this article.

Step 2: Create the Riskfolio Portfolio Object

Next, we'll create a Riskfolio Portfolio Object from the returns data. Run this code:

Portfolio Object

Step 3: Create the Max Sharpe Portfolio

Next, we will make the default portfolio that maximizes the Sharpe Ratio. Run this code:

Max Sharpe Portfolio

Here's the 4 charts that are output.

  1. Portfolio Composition: 48.8% NVDA, 21.9% PANW, 19.6% TSLA, 9.7% MSFT, and Others are 0%

  2. Compounded Historical Returns: 1400% over 6 years

  3. Historical Drawdowns: -57.6% Max Drawdown

  4. Risk Table: 50% Average Return, 33.7% compound annual growth rate (CAGR), 40% standard deviation, -57.6% Max Drawdown

Portfolio Output

Conclusion: Optimizing Nancy Pelosi's Portfolio

Python is wild for finance. We've used Riskfolio to come up with a passive investing strategy that could yield significant future returns. Note that with max drawdown exceed -57%, this portfolio is not for the faint of heart. But at 33.7% CAGR (and 1400% total return), it's shown to be a significant wealth generator in the past. Keep in mind, the past is not indicative of the future, so who knows what will happen.

Are you interested in learning active investing strategies that use algorithms to maximize returns responsibly, help you manage risk, and grow your investments? We implement 3 core trading strategies including portfolio, momentum, and spread trades that have worked in our favor in the past and continue to produce results for our students.

Learn with 200+ of us that are learning to apply python to algorithmic trading to grow investments.

Leo was up 11.5% in just 13 trading days.

Leo up 13pct

Alex was waiting 9 years for a course like this:

testimonial

Ready to make Algorithmic Trading Strategies that actually work?

There's nothing worse than going at this alone--

Learning Python is tough.

❌ Learning Trading is tough.

Learning Math & Stats is tough.

It's no wonder why it's easy to feel lost, make bad decisions, and lose money.

Want help?

Python for Algorithmic Trading Course

👉 Join 8,200+ future Quant Scientists on our Python for Algorithmic Trading Course Waitlist: https://learn.quantscience.io/python-algorithmic-trading-course-waitlist

button course waitlist

investingstockspythonalgorithmic tradingsoftwareriskfolio
Matt is a Data Science expert with over 18 years working in business and 10+ years as a Data Scientist, Consultant, and Trainer. Matt has built Business Science, a successful educational platform with similar goals to Quant Science, but focused on developing Data Scientists in business, marketing, and finance disciplines.

Matt Dancho

Matt is a Data Science expert with over 18 years working in business and 10+ years as a Data Scientist, Consultant, and Trainer. Matt has built Business Science, a successful educational platform with similar goals to Quant Science, but focused on developing Data Scientists in business, marketing, and finance disciplines.

Back to Blog

Start Your Journey To Becoming A Quant Today!

Join the Quant Scientist Newsletter

Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...

Join 11,500+ Quant Scientists learning one article at a time

Join 11,500+ Quant Scientists learning one article at a time

© 2024 Quant Science - All Rights Reserved

Cohort 6 launches Wednesday, October 2nd at 10AM EST