Python for Market Data, lesson 6
Ranks across stocks
Comparing every stock on the same day: the cross-section.
You can build a wide table of returns: dates down, stocks across.
Part 1. Rank the day
Eight simulated stocks over ten days, with each one's return over the past month. Rank them, and watch which way the ranks run.
Ranking across a row asks the useful question: on this day, which stocks did best compared with the others? Ranking down a column asks how a stock's month compares with its own other months, including months that hadn't happened yet on that day.
Cross-section
All the stocks on one date. A cross-sectional rank orders them against each other on that date: rank(axis=1) on a wide table, or a groupby("date") and rank() on a long one.
Your turn
mom is a wide table, dates down and stocks across. What does mom.rank() rank, with no axis?
axis=0, so each stock is ranked against its own other days, future days included. For a cross-section you need axis=1.Part 2. Read it in plain words
Keep going with Pro
You've done the first part. Pro opens the rest of this lesson, and every other one.
- Read it in plain words
- Worked: long the best, short the worst, by sector
- The same thing, for real
Python for Market Data overviewSpotted a mistake? Tell us.