FAQ: Mean-Variance Portfolio Optimization - Review

This community-built FAQ covers the “Review” exercise from the lesson “Mean-Variance Portfolio Optimization”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Analyze Financial Data with Python

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hey! Just downloaded the rf.py code to contribute to my capstone project. I’m having some issues with organising and downloading the proper packages to make it work.

This is a screen shot of the problems section of my VSC.


Looks like you need to install NumPy. If you’re using Python 3 (recommended), enter the following command into your Terminal. If you’re using Python 2, change ‘pip3’ to ‘pip’

pip3 install numpy

return_portfolios and optimal_portfolio are custom functions made by Codecademy. They can be found in the lessons. They’re in a separate script inside the lessons. See the tabs at the top of the editor. You’ll need to copy those functions into a file in the same directory as your own script, and then import the functions as you would a normal module. I put them in a file called calc.py, so then:

from calc import return_portfolios, optimal_portfolio

As opt and blas: the Codecademy custom functions depend on a Python library called CVXOPT: Download — CVXOPT It’s not available on pip sadly. You have to download and install it separately.

I’m in a similar situation to you, wanting to use this to build my capstone project. I’m thinking of using the PyPortfolioOpt. It has some things to do with Efficient Frontiers: Efficient Frontier Optimisation — PyPortfolioOpt 1.3.1 documentation

Hey thank ya1

I ran through it again and all seems well. The issue will be importing and massaging the data to work with the functions!

opt and blas seem like very useful tools, above my level, but still interesting.