Start your terminal to use beginner mode.
Scenario
A CSV file contains daily stock price data for multiple companies that needs statistical analysis using rolling window calculations across different time periods.
Task
Write a Python script at /home/interview/calculate_rolling.py using pandas that reads /home/interview/stock_data.csv, calculates rolling statistics (mean, sum, standard deviation) for the close_price column using three different window sizes (7-day, 14-day, 30-day), rounds all calculated values to 2 decimal places, and saves the result to /home/interview/rolling_stats.csv.
Note: The dataset contains multiple stock tickers. Calculate rolling statistics separately for each ticker.
Example
Input (stock_data.csv):
date,ticker,close_price
2025-01-01,AAPL,180.50
2025-01-01,GOOGL,142.30
2025-01-02,AAPL,182.10
2025-01-02,GOOGL,143.20
...
Expected output (rolling_stats.csv):
date,ticker,close_price,rolling_mean_7d,rolling_sum_7d,rolling_std_7d,rolling_mean_14d,rolling_sum_14d,rolling_std_14d,rolling_mean_30d,rolling_sum_30d,rolling_std_30d
2025-01-01,AAPL,180.50,,,,,,,,,,
...
2025-01-07,AAPL,185.20,182.45,1277.15,2.34,,,,,,,
...
2025-01-14,AAPL,188.50,186.30,1304.10,2.51,184.20,2578.80,3.12,,,,
...
Terminal requires a larger screen
Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.
Linux Terminal Environment
Write and execute your solution in the terminal below.
HashiCorp
TCS
X
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
Meta
OpenAI
Hulu
Uber
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Capital One
Splunk
Intel
SAP
Tesla
GitHub
JaneStreet
Bloomberg
Salesforce
Elastic
CGI
UBS
GitLab
Ubisoft
Slack
Nintendo
EY
Kayak
Lyft
Airbnb
Walmart
Revolut
Visa
Okta
Instacart
Mastercard