Get startedGet started for free

Industry exposures with Pyfolio

You saw in the first video of this chapter how to use a groupby function to create the active weights per industry. The drawback is that it takes a snapshot in time. Since portfolio weights change, you can imagine that the industry exposures change over time as well. However, the calculation to determine industry exposures on each day for your portfolio, can become quite tedious and complex.

Luckily, you can use Pyfolio's tear sheet for this. The tear sheet shows you exposures over time, and summarizes overall top stock picks in your portfolio. Available is data on your portfolio returns under returns, and your daily positions in dollar value per stock, under positions. Go ahead and inspect positions and returns in the console.

This exercise is part of the course

Introduction to Portfolio Analysis in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define the sector mappings
sect_map = {'COST': 'Consumer Goods',
            'INTC': 'Technology', 
            'CERN': 'Healthcare', 
            'GPS': 'Technology',
            'MMM': 'Construction', 
            'DELL': '____', 
            'AMD': 'Technology'}
Edit and Run Code