Skip to content

M1ndSmith/AI-driven-financial-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Flask Financial Analysis API

πŸ“Œ Project Overview

This is a Flask-based Financial Analysis API that allows users to:

  • Extract stock ticker symbols from natural language queries.
  • Fetch financial data for a stock using Yahoo Finance.
  • Analyze stock data using AI-driven financial analysis.

πŸ— Project Structure

/flask_financial_api
│── /app
β”‚   │── /api
β”‚   β”‚   │── __init__.py
β”‚   β”‚   │── routes.py
β”‚   │── /models
β”‚   β”‚   │── __init__.py
β”‚   β”‚   │── stock.py
β”‚   │── /services
β”‚   β”‚   │── __init__.py
β”‚   β”‚   │── symbol_extractor.py
β”‚   β”‚   │── data_fetcher.py
β”‚   β”‚   │── stock_analysis.py
β”‚   │── /utils
β”‚   β”‚   │── __init__.py
β”‚   β”‚   │── logger.py
β”‚   │── /config
β”‚   β”‚   │── __init__.py
β”‚   β”‚   │── settings.py
β”‚   │── /middleware
β”‚   β”‚   │── __init__.py
β”‚   β”‚   │── error_handler.py
β”‚   │── __init__.py
β”‚   │── extensions.py
│── /migrations
│── /tests
β”‚   │── __init__.py
β”‚   │── test_routes.py
│── /instance
│── .env
│── requirements.txt
│── gunicorn_config.py
│── wsgi.py
│── README.md

πŸš€ Getting Started

πŸ”Ή Prerequisites

  • Python 3.12+
  • Anaconda (if using Conda environments)

πŸ”Ή Setup

1. Clone the Repository

git clone https://github.com/yourusername/flask_financial_api.git
cd flask_financial_api

2. Create a Virtual Environment

conda create -n financial_api_env python=3.12
conda activate financial_api_env

Or using venv:

python -m venv venv
source venv/bin/activate  # macOS/Linux
venv\Scripts\activate  # Windows

3. Install Dependencies

pip install -r requirements.txt

4. Set Up Database

flask db init
flask db migrate -m "Initial migration"
flask db upgrade

5. Run the Server

flask run

By default, the API runs at: http://127.0.0.1:5000

For public access:

flask run --host=0.0.0.0 --port=5000

πŸ“‘ API Endpoints

1️⃣ Extract Stock Symbol

POST /api/extract-symbol

Request:

{
    "query": "symbol for microsoft"
}

Response:

{
  "symbol":"The stock ticker symbol for Microsoft is:\n\nMSFT"
}

2️⃣ Fetch Financial Data

POST /api/fetch-financials

Request:

{
    "ticker": "AAPL"
}

Response:

{
 "file":"MSFT.json",
  "message":"Financial data successfully saved at MSFT.json"   
}

3️⃣ Analyze Stock Data

POST /api/analyze-stock

Request:

{
    "file_path": "AAPL.json",
    "query": "Analyze this stock"
}

Response:

{
    "analysis": "The stock shows strong profitability....... I would recommend that the trader hold the stock..."

}

πŸ§ͺ Running Tests

pytest tests/

Expected output:

================================================= 3 passed in 13.74s ==================================================

πŸš€ Deployment

1️⃣ Deploy with Waitress (Windows Production Server)

! you can use gunicorn for linux

pip install waitress
waitress-serve --listen=0.0.0.0:5000 wsgi:app

|

πŸ“Œ License

This project is open-source and available under the MIT License.

❀️ Contributing

  • Fork the repository
  • Create a new branch (git checkout -b feature-branch)
  • Commit your changes (git commit -m 'Add new feature')
  • Push to the branch (git push origin feature-branch)
  • Create a pull request πŸš€

About

A Flask-based API that enables users to retrieve financial data, perform AI-driven analysis, and receive stock trading recommendations based on financial quantitave data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages