-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ananyag309/main
Added Stock App
- Loading branch information
Showing
5 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
## **STOCK APP** | ||
|
||
### 🎯 **Goal** | ||
|
||
Python Project - This App show stock details of the entered ticker. | ||
- Compnay Profile | ||
- Income Statement Details | ||
- EPS Chart | ||
- Company Current Quotes | ||
|
||
Modules Used: | ||
- Financial Modelling Perp API | ||
- requests | ||
- Flask | ||
|
||
|
||
### 🧾 **Description** | ||
|
||
This project allows users to fetch detailed stock-related information using the Financial Modeling Prep API. The app returns essential financial data of a company based on the ticker entered by the user. Data includes the company's profile, income statements, EPS trends, and real-time stock quotes. | ||
|
||
### 🧮 **What I had done!** | ||
|
||
1. Created a Flask-based web app to collect the stock ticker from the user. | ||
2. Used the Financial Modeling Prep API to fetch the stock details. | ||
3. Processed the API data and displayed it in a user-friendly format. | ||
4. Created an EPS chart visualization using the stock data. | ||
5. Added company profile and income statement details to the app for easy analysis. | ||
6. Integrated real-time stock quotes into the app for instant updates. | ||
|
||
### 🚀 **Models Implemented** | ||
|
||
No machine learning models were implemented in this app. The stock data is purely fetched from the Financial Modeling Prep API and visualized as-is. The EPS trend is displayed in a chart for easier interpretation. | ||
|
||
### 📢 **Conclusion** | ||
|
||
`The app successfully displays comprehensive financial data for any entered stock ticker. This includes a company's profile, income statement, real-time quotes, and an EPS trend chart to analyze the company's financial health. It serves as a basic stock data retrieval and visualization tool for quick reference.` | ||
|
||
### ✒️ **Your Signature** | ||
|
||
|
||
`Ananya Gupta` | ||
[GitHub Profile](https://github.com/ananyag309) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | ||
|
||
<title>StockPage | {% block title %} {% endblock title %} </title> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-light bg-light"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand" | ||
href='{{ url_for('home_page')}}'> | ||
StockPage | ||
</a> | ||
<form class="d-flex" method='POST' action='{{url_for('search')}}'> | ||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" name='searchticker'> | ||
<button class="btn btn-outline-success" type="submit">Search</button> | ||
</form> | ||
</div> | ||
</nav> | ||
|
||
|
||
|
||
|
||
<div class="container mt-5"> | ||
{% block content %} | ||
|
||
{% endblock content %} | ||
</div> | ||
|
||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<h5 class="text-center mt-5">Financials</h5> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
|
||
<th scope="col">As of </th> | ||
<th scope="col">Revenue </th> | ||
<th scope="col">Grosss profit </th> | ||
<th scope="col">NET income </th> | ||
<th scope="col">EPS </th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
|
||
{% for f in financials %} | ||
<tr> | ||
<td scope="row"> {{ f["date"] }} </td> | ||
<td scope="row">{{ f['revenue'] }} </td> | ||
<td scope="row">{{ f['grossProfit'] }} </td> | ||
<td scope="row">{{ f['netIncome'] }} </td> | ||
<td scope="row">{{ f['eps'] }} </td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
|
||
</table> | ||
|
||
<div class="row"> | ||
<img src="https://quickchart.io/chart?width=500&height=200&c={{epsChart}}" alt="chart"> | ||
|
||
</div> | ||
|
||
<div class="row mt-5 mb-5"> | ||
<h5 class="'mb-2 text-center"> Today's Quotes</h5> | ||
{% for item in quotes %} | ||
|
||
<p> <b>Open</b>: {{item['open']}} | | ||
<b>Close</b>: {{item['previousClose']}}</p> | ||
<p><b>Price change(%)</b>: {{item['changesPercentage']}} | <b>Price Change($)</b>: {{item['change']}}</p> | ||
<p> | ||
<b>Today's Low</b>: {{item['dayLow']}} | | ||
<b>Today's High</b>: {{item['dayHigh']}} | ||
</p> | ||
<p> | ||
<b>Year's Low</b>: {{item['yearLow']}} | | ||
<b>Year's High</b>: {{item['yearHigh']}} | ||
</p> | ||
<p> | ||
<b>Price Average(50 days)</b>: {{item['priceAvg50']}} | | ||
<b>Total Volume</b>: {{item['volume']}} | ||
</p> | ||
<p> | ||
<b>Price to Earnings</b>: {{item['pe']}} | | ||
<b>Shares outstanding</b>:{{item['sharesOutstanding']}} | ||
</p> | ||
|
||
{% endfor %} | ||
<hr> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %} Home {% endblock title %} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
{% block content %} | ||
|
||
|
||
<div class="row"> | ||
<div class="col-sm text-center"> | ||
<h3 class="'mb-3">Welcome to my Stock Page</h3> | ||
<h5 class='mb-5'>A Quick way to find stock details.</h5> | ||
</div> | ||
|
||
|
||
<div class='row mt-5'> | ||
<form class="d-flex" method='POST' action='{{url_for('search')}}'> | ||
<input class="form-control me-2 " type="search" placeholder="Search" aria-label="Search" name='searchticker'> | ||
|
||
<button class="btn btn-outline-success" type="submit">Search</button> | ||
</form> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
|
||
{% endblock content %} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from flask import Flask, redirect, render_template, url_for, request | ||
import requests | ||
|
||
app = Flask(__name__) | ||
|
||
API_key = '***************************' | ||
api_url ="https://financialmodelingprep.com/api/v3/quote-short/{ticker}" | ||
|
||
def fetch_price(ticker): | ||
data = requests.get(api_url.format(ticker=ticker.upper()), params = {'apikey': API_key}).json() | ||
for p in data: | ||
return p['price'] | ||
|
||
|
||
def fetch_volume(ticker): | ||
data = requests.get(api_url.format(ticker=ticker.upper()), params = {'apikey': API_key}).json() | ||
for p in data: | ||
return p['volume'] | ||
|
||
|
||
|
||
def fetch_income_stat(ticker): | ||
api_url = 'https://financialmodelingprep.com/api/v3/income-statement/{ticker}?period=quarter?limit=8' | ||
financials = requests.get(api_url.format(ticker=ticker.upper()), params={'apikey':API_key}).json() | ||
financials.sort(key=lambda quarter: quarter['date']) | ||
return financials | ||
|
||
|
||
def financial_chart(ticker): | ||
data = fetch_income_stat(ticker) | ||
chart_data= [float(q['eps']) for q in data if q['eps']] | ||
chart_process= {"type": 'line', | ||
'data':{ | ||
'labels':[q['date'] for q in data if q['eps']], | ||
'datasets':[{'label':'EPS','data':chart_data}] | ||
} | ||
} | ||
return chart_process | ||
|
||
|
||
def profile(ticker): | ||
company_profile = requests.get(f"https://financialmodelingprep.com/api/v3/profile/{ticker}?apikey={API_key}").json() | ||
return company_profile | ||
|
||
|
||
|
||
def todayQuote(ticker): | ||
quotes = requests.get(f"https://financialmodelingprep.com/api/v3/quote/{ticker.upper()}?apikey={API_key}").json() | ||
try: | ||
return quotes | ||
except Exception: | ||
return ("Quotes not avialble right now!") | ||
|
||
|
||
@app.route("/stock/<ticker>") | ||
def fetch_ticker(ticker): | ||
price = fetch_price(ticker) | ||
volume = fetch_volume(ticker) | ||
financials = fetch_income_stat(ticker) | ||
epsChart= financial_chart(ticker) | ||
companyprofile = profile(ticker) | ||
quotes = todayQuote(ticker) | ||
return render_template("stockpage.html", price=price, volume=volume, financials=financials, epsChart=epsChart, profile=companyprofile, quotes=quotes, ticker=ticker) | ||
|
||
|
||
|
||
@app.route("/search", methods=['POST']) | ||
def search(): | ||
return redirect(url_for('fetch_ticker', ticker=request.form['searchticker'])) | ||
|
||
|
||
|
||
|
||
@app.route("/") | ||
def home_page(): | ||
return render_template("index.html") | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, threaded=True) |