
Yesterday, I shared how merge_asof() comes in handy when merging Time Series data.
So I did an exercise to practice what I learned. I was given three banks' datasets: JPM (JP Morgan), Wells (Wells Fargo) & BAC (Bank of America).
These three banks recorded their stock prices at different times due to delay caused by network issues, so their timestamps don’t match exactly.
I needed to compare how the prices change across the three banks over time. To do that, I had to first align their times using merge_asof().
What this does is that, it takes a timestamp from JPM, checks to see which timestamp in Wells is closest to it, and then stores the value.
I proceed to repeat the same for BAC, and I end up with a lineup of the three banks' logs, where each row has prices taken at almost the same moment.
.diff() helps calculate the price changes across the three banks. I plotted these changes to show how each bank's stock price changes over time:
Blue line represents JPM
Orange line represents Wells
Green line represents Bank of America
From the plot, we can see that:
JPM is more volatile
Wells and BAC move more steadily
But all three banks show similar rise and fall patterns overall
It suggests their price movements are correlated because all big US banks react to similar market forces.
For my non-data science audience, you might be asking, kini gbogbo eleyi TL mi?(What's all this on my timeline?).
In fact, bold of me to assume you got to this point, but if you did I owe you a clearer explanation. So here you go:👇
When recording stock prices, different banks often log data at slightly different times.
To compare them properly, I matched each timestamp with the closest available time from another bank.
Once the timestamps were aligned, I calculated how much each stock price changed over time.
Finally, I plotted the price movements of JP Morgan, Wells Fargo, and Bank of America.
Guess what I found...
JPM (blue) is more volatile, swings higher, up and down.
Wells (orange) has smoother and smaller changes.
BAC (green) is very similar to Wells but slightly less volatile.
The curves for Wells and BAC look similar and smoother. That’s normal, they’re both traditional retail/consumer banks. They respond to:
✔ Interest rate changes
✔ Federal Reserve decisions
✔ Loan demand
These factors affect them in the same direction, so their returns often move similarly.
JPM had the most dramatic ups and downs. Why? Because JPMorgan has:
✔ A massive investment banking division
✔ Trading operations
✔ Global exposure
✔ Riskier revenue streams
Investment banking stocks naturally move more sharply.
This exercise helped me understand how real-time financial datasets are merged, aligned, and analyzed without leaking future information. I also learned how stock returns reveal volatility, how staged merging prevents data conflicts, and why different banks move differently in the market.
This is the End.
-SP
Top comments (0)