Hi, everyone! Before we get started, I've got two administrative announcements:
- Pandas 3 will be coming out soon, and as we saw last week, it includes a number of changes. I'm recording videos about the Pandas 3 upgrade on YouTube; you can see them on my Pandas 3 playlist, here: https://www.youtube.com/watch?v=TCSjgvtO714&list=PLbFHh-ZjYFwFWHVT0qeg9Jz1TBD0TlJJT
- Like many other online creators and instructors, I've written an end-of-year summary of what I did this year, and what plans I have for 2026. You can read it at: https://lerner.co.il/2025/12/23/reuvens-2025-in-review/
And now...
Over the last few years, I've heard more and more about "prediction markets," online platforms that allow you to make predictions about the future. You can predict who will win an election, or on the value of a particular currency (or cryptocurrency) at a particular time, on whether Netflix will successfully buy Warner-Discovery, or on any number of other events in our world.
But in practice? Many commentators say that Kalshi has effectively become an online gambling platform, and they make a pretty convincing argument. Moreover, I've heard that it has become an online sports gambling platform. Sports gambling, as we saw in BW 100, back in January of this year, is extremely popular, especially among young people. Online sports betting companies are making enormous profits, in no small part because they exclude anyone who actually manages to make money.
Kalshi isn't officially a gambling platform, and certainly not a sports gambling platform, but I read that many people see it that way — including the state of Nevada, which has gone to court to stop Kalshi from allowing its residents from entering into sports markets (https://finance.yahoo.com/news/kalshi-risk-nevada-enforcement-court-173246378.html). Nevada has long allowed for sports betting, but also has strict rules over who runs such platforms, and is trying to stop Kalshi from joining.
Kyla Scanlon argues that the spread of gambling reflects other issues in modern society, and specifically mentions Kalshi in one of her latest essays, at https://kyla.substack.com/p/everyone-is-gambling-and-no-one-is .
I'm sure that Kalshi has a different take on things. Just yesterday, in fact, they announced Kalshi Research, which will look at prediction markets as a new and different way to predict trends (https://research.kalshi.com/).
This week, I thought it would be interesting to look at Kalshi: What sorts of questions are people trying to ask? Is it really being used for sports betting? And do we see the number of predictions on Kalshi growing over time?
Data and five questions
The good news is that Kalshi offers an API to retrieve information about just about any part of the system. The better news is that if you're looking to get information about their events and markets, rather than your personal predictions, then the API is totally open and free to use. And even better than that? There's a package on PyPI (https://pypi.org/project/kalshi-python/) that packages the Kalshi API into an easy-to-use format.
The bad news? That PyPI project crashed on me pretty consistently, apparently because of a validation error. The Kalshi server is returning values that are considered invalid by the client program.
I thus, with some help from Claude, pieced together a program that retrieves Kalshi event and market information using the Python requests module, and then rewrites things into a Pandas data frame. It took me a while to get this to work, and it would be unfair to ask you to do this — so I'm providing the Python program here:
FYI, it took about 15 minutes for this program to run on my computer.
In case you aren't a Kalshi guru, here are a few basics that you should know:
- Kalshi has defined a number of events. An event can be an election, a sports game, or a financial market.
- Within each event, Kalshi has defined a number of markets. Each market is a particular prediction with a yes/no outcome. For example:
- For the 2024 election event, a market would be that Trump will beat Biden.
- For the 2024 election event, a market would be that Trump will beat Biden by 10 percentage points nationally.
- For the 2024 election event, a market would be that Trump will beat Biden in at least three swing states.
- For the 2025 baseball World Series event, a market could be that the LA Dodgers will get in.
- For the 2025 baseball World Series event, a market could be that the LA Dodgers will play the Toronto Blue Jays.
- For the 2025 baseball World Series event, a market could be that the LA Dodgers will beat the Toronto Blue Jays.
- For the 2025 baseball World Series event, a market could be that the LA Dodgers will beat the Toronto Blue Jays by 3 runs.
- You can buy a contract for a particular market. That indicates you think that the answer will be "yes" to the market's question. The contract's price is between 1 cent and 99 cents. If you want to BUY, you pay the yes_ask price (what sellers are asking). If you want to SELL, you receive the yes_bid price (what buyers are offering).
- If lots of people want a particular contract, then the price will go up, to a maximum of 99 cents. If very few people want a contract, then the price will go down, to a minimum of 1 cent.
- If you buy a contract for 48 cents and you're right, you get $1 back (profit: 52 cents).
- If you buy a contract for 48 cents and you're wrong, you get $0 (loss: 48 cents).
- If you own a contract and want to sell it before the event resolves, you sell at the
yes_bidprice (what buyers are offering).
Learning goals for this week include: Working with APIs, dates and times, grouping, and plotting.
Paid subscribers, including members of my LernerPython.com membership program, get the data files provided to them, as well as all of the questions and answers each week, downloadable notebooks, and participation in monthly office hours.
Here are my five questions for this week. I'll be back tomorrow with solutions and full explanations:
- The program that I've provided asks Kalshi for all of the events in its database, and all of the markets associated with each event. Convert the
open_timeandclose_timecolumns in that data frame todatetimevalues with a UTC time zone and 1-second granularity. - Which 10 events had the greatest number of markets? Which 10 events had the greatest number of contracts bought and sold (the
volumecolumn)? Why would you see a difference between the result of this query and the previous one? Create a bar plot showing the volume of contracts, per month. Do we see any growth in Kalshi since it launched? Does the fact that Kalshi won court cases in September and October of 2024 seem to have had an effect?