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 gemma4:31b
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 gemma4:31b. After the conversation, we show detailed score cards for this run.
Score cards for gemma4:31b for Apple Stock Price Analysis in Python
Total score: 10/10
Task Completion: 2/2
ExcellentAll major requested steps were completed: data loading, moving averages, daily returns distribution, rolling volatility, and Sharpe ratio.
Execution Correctness: 2/2
ExcellentThe code shown is syntactically coherent and the outputs indicate it ran successfully, including printed statistics and generated plots.
Output Quality: 3/3
ExcellentOutputs match the expected outcomes semantically: OHLCV data loaded, MA crossover plot shown, return histogram produced, and rolling volatility with Sharpe ratio printed.
Reasoning Quality: 2/2
ExcellentThe workflow reasoning is clear and appropriately sequences loading, feature engineering, visualization, and risk metrics.
Reliability: 1/1
ExcellentThe workflow is consistent and robust enough for the task, with no evident hallucinations or unsafe behavior.
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.