Time Series
Apple Stock Price Analysis in Python
Load Apple stock price data, compute moving averages, calculate daily returns, visualize volatility, and compute the Sharpe ratio.
What
This AI Data Analyst workflow pulls the last two years of AAPL OHLCV data using yfinance and organizes it into a pandas time-series DataFrame. It generates 20-day and 50-day moving averages, plots price with the moving-average overlays, and highlights crossover behavior visually. It computes daily returns, visualizes the return distribution, then calculates 30-day rolling volatility and an annualised Sharpe ratio.
Who
This is for analysts and students who want a reproducible Python notebook for basic equity time-series analysis on Apple stock. It helps users learn how to compute and interpret moving averages, returns, volatility, and risk-adjusted performance from market data.
Tools
- yfinance
- pandas
- numpy
- matplotlib
- seaborn
Outcomes
- AAPL OHLCV DataFrame for ~2 years of trading days
- Price chart with MA20 and MA50 overlays and visible crossovers
- Daily returns series and histogram of returns
- 30-day rolling volatility plot
- Printed annualised Sharpe ratio
Quality Score
7/10
Last scored: Apr 7, 2026
Task Completion: 1/2
Needs workLoaded ~2 years of AAPL OHLCV data, computed MA20/MA50, plotted price+MAs, computed daily returns and plotted their distribution. Did not compute or plot 30-day rolling volatility and did not compute/print the annualised Sharpe ratio (only asked a clarifying question).
Execution Correctness: 2/2
ExcellentProvided code blocks are syntactically correct and handle yfinance MultiIndex columns; moving averages and returns calculations are appropriate and likely runnable. No evident breaking errors in the shown code.
Output Quality: 2/3
GoodOutputs include a MultiIndex OHLCV preview and two figures (price with MA20/MA50 and returns histogram with KDE), matching most expected visuals. Missing the rolling volatility chart and the Sharpe ratio output, and the dataframe shape is 501x6 rather than the expected ~504x6 (still plausible for a 2y window).
Reasoning Quality: 1/2
Needs workReasoning about MultiIndex handling and return computation is correct, but the narrative includes speculative interpretation of plots without evidence and stops short of completing the final requested metrics.
Reliability: 1/1
ExcellentWorkflow is reasonably robust (checks MultiIndex, uses dropna for returns) and avoids hallucinated code execution. However, it relies on yfinance availability and leaves the final step incomplete.