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 workflow does
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 example is for
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.
Expected analysis outcomes
These are the results the AI workflow is expected to generate.
- 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
Tools and libraries used
Main Python packages and tooling used to run this AI data analysis task.
- yfinance
- pandas
- numpy
- matplotlib
- seaborn
Prompt sequence
This is the exact list of prompts used in this workflow. The same prompt sequence is sent to each model so outputs and scores can be compared fairly.
- 1load AAPL stock prices for the last 2 years using yfinance
- 2add 20-day and 50-day moving averages and plot
- 3calculate daily returns and plot their distribution
- 4compute 30-day rolling volatility and annualised Sharpe ratio
Model Comparison
We compared several LLM models on the same analysis task. The table below shows their scores side by side. You can also open each model run to check the full conversation and notebook results.
| Model Source | Score | Task | Execution | Output | Reasoning | Reliability | Run |
|---|---|---|---|---|---|---|---|
| gemma4:31b | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open gemma4:31b conversation |
| gpt-5.4 | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open gpt-5.4 conversation |
| gpt-oss:120b | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open gpt-oss:120b conversation |
| glm-5.1 | 9/10 | 2/2 | 2/2 | 3/3 | 1/2 | 1/1 | Open glm-5.1 conversation |
| qwen3.5:397b | 7/10 | 2/2 | 1/2 | 3/3 | 1/2 | 0/1 | Open qwen3.5:397b conversation |
| qwen3-coder-next | 6/10 | 2/2 | 1/2 | 2/3 | 1/2 | 0/1 | Open qwen3-coder-next conversation |
How scoring works
Each run is graded on five dimensions:
- Task Completion (0-2): how fully the workflow answered the requested analysis task and completed required steps.
- Execution Correctness (0-2): whether generated code is correct, consistent, and likely runnable without major fixes.
- Output Quality (0-3): how well tables, charts, and results match the expected analytical outcomes.
- Reasoning Quality (0-2): clarity and correctness of interpretation, explanation, and conclusions.
- Reliability (0-1): robustness of the run, including low hallucination risk and stable behavior.
The final score is the sum of these dimensions, so total score = 0-10. Higher values indicate more complete, correct, and reliable notebook results for this workflow.
AI Analysis with qwen3-coder-next
This run uses AI with a step-by-step list of prompts to perform the analysis task Apple Stock Price Analysis in Python. Below, you can review the full conversation generated with qwen3-coder-next. After the conversation, we show detailed score cards for this run.
Score cards for qwen3-coder-next for Apple Stock Price Analysis in Python
Total score: 6/10
Task Completion: 2/2
ExcellentAll major requested steps were attempted: data loading, moving averages, daily returns, volatility, and Sharpe ratio. The notebook also produced the expected plots and summary statistics.
Execution Correctness: 1/2
Needs workThe code appears mostly runnable, but it relies on a MultiIndex structure from yfinance and mixes column access patterns. The notebook itself notes display/misalignment issues, so correctness is not fully clean.
Output Quality: 2/3
GoodThe outputs include the OHLCV data, moving-average plot, return histogram, descriptive stats, and rolling volatility/Sharpe values. However, the expected OHLCV shape is slightly off at 501 rows rather than about 504.
Reasoning Quality: 1/2
Needs workThe reasoning is partly correct but inconsistent: it first flags a possible data-structure issue, then later claims the calculations are correct despite the same ambiguity. The final interpretation is plausible but not fully reliable.
Reliability: 0/1
Needs workThe workflow is somewhat fragile because it depends on ambiguous MultiIndex handling and contains contradictory commentary about whether the Sharpe/volatility outputs are correct.
Try MLJAR Studio
Run the same type of AI-powered data analysis on your own datasets with conversational notebooks in MLJAR Studio.
Explore More AI Analysis Examples
Discover additional workflows across categories. Each example includes prompts, conversation outputs, and model-level scoring so you can compare approaches and results.