Skip to content

Time-series stock analysis using yfinance, Pandas, and Matplotlib, including SMA indicators and real-time data retrieval.

Notifications You must be signed in to change notification settings

Mood07/Python-Stock-Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

💹 Stock Price Analysis – Python (Pandas + yfinance + Matplotlib)

A clean and modular Python time‑series analysis project for fetching stock market data, calculating moving averages, and generating professional financial charts.
This project is designed for Data Science / Finance portfolios and follows industry‑standard practices: virtual environments, requirements management, and clean architecture.


🚀 Project Overview

This application:

  • Fetches real‑time historical stock prices using yfinance
  • Calculates 50-day and 200-day Simple Moving Averages (SMA)
  • Plots price + SMAs using Matplotlib
  • Demonstrates time‑series analysis fundamentals
  • Uses a clean folder structure suitable for GitHub portfolios

Unlike many beginner projects, this version does not store raw data or images inside the repository
(to keep the repo clean and lightweight).
Instead, data is fetched dynamically each time the script runs.


📡 Data Source

Stock market data is fetched in real time from:

Yahoo Finance API (via yfinance library)
https://pypi.org/project/yfinance/

No API key is required.


🧱 Project Structure

stock-analysis/
│
├── README.md
├── requirements.txt
└── src/
    └── main.py

If you choose to save data or charts locally, the script will automatically create:

data/
assets/visuals/

These folders are optional and not included by default to keep the repo clean.


🧩 Virtual Environment Setup (Recommended)

1) Create venv

python -m venv .venv

2) Activate venv

Windows:

.venv\Scripts\activate

macOS / Linux:

source .venv/bin/activate

3) Deactivate venv

When you finish working on the project:

deactivate

📦 Install Dependencies

Inside your activated venv:

pip install -r requirements.txt

To generate a fresh requirements.txt file:

pip freeze > requirements.txt

▶️ Running the Project

Inside the project directory:

python src/main.py

You will be prompted for a stock ticker symbol:

Examples:

AAPL
MSFT
TSLA
NVDA
SPY

The script will:

  • Fetch 1 year of historical price data
  • Calculate SMA 50 & SMA 200
  • Display a Matplotlib chart
  • (Optional) Save CSV + chart locally

🧠 Key Features

  • Real-time time‑series financial analysis
  • REST-like data retrieval via yfinance
  • Rolling window signal generation (SMA indicators)
  • Matplotlib financial visualizations
  • Path‑safe architecture suitable for GitHub
  • Fully venv‑isolated workflow
  • Zero hardcoded paths

🧰 Tech Stack

  • Python 3.x
  • Pandas
  • Matplotlib
  • yfinance

👨‍💻 Author

Berke Arda Türk

Data Science & AI Enthusiast | Computer Science (B.ASc)
🌐 Portfolio Website💼 LinkedIn🐙 GitHub

About

Time-series stock analysis using yfinance, Pandas, and Matplotlib, including SMA indicators and real-time data retrieval.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages