Skip to content

Commit e84371a

Browse files
committed
Added codes to python files
1 parent 75eb2c2 commit e84371a

8 files changed

Lines changed: 165 additions & 0 deletions

File tree

.github/workflows/ci_cd.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: '3.11'
18+
- name: Install dependencies
19+
run: |
20+
pip install uv
21+
uv pip install -e .[dev]
22+
- name: Run tests
23+
run: pytest
24+
25+
deploy:
26+
needs: test
27+
runs-on: ubuntu-latest
28+
if: github.ref == 'refs/heads/main'
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Build and push Docker image
32+
env:
33+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
34+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
35+
run: |
36+
docker build -t your-docker-repo/stock-valuation-app:latest .
37+
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
38+
docker push your-docker-repo/stock-valuation-app:latest

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY pyproject.toml uv.lock ./
6+
RUN pip install uv && uv pip install -e .
7+
8+
COPY src ./src
9+
10+
CMD ["uvicorn", "stock_valuation_app:app", "--host", "0.0.0.0", "--port", "8000"]

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3'
2+
services:
3+
web:
4+
build: .
5+
ports:
6+
- "8000:8000"
7+
environment:
8+
- FMP_API_KEY=your_api_key_here

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies = [
1515
"polars>=1.12.0",
1616
"pyarrow>=18.0.0",
1717
"pydantic>=2.9.2",
18+
"pyyaml>=6.0.2",
1819
]
1920

2021
[project.scripts]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import httpx
2+
from pydantic import BaseModel
3+
4+
5+
class FinancialData(BaseModel):
6+
revenue: float
7+
netIncome: float
8+
freeCashFlow: float
9+
dividendsPaid: float
10+
11+
12+
class FMPClient:
13+
def __init__(self, api_key: str):
14+
self.base_url = "https://financialmodelingprep.com/api/v3"
15+
self.api_key = api_key
16+
17+
async def get_financial_data(
18+
self, symbol: str, limit: int = 10
19+
) -> list[FinancialData]:
20+
url = f"{self.base_url}/income-statement/{symbol}?limit={limit}&apikey={self.api_key}"
21+
async with httpx.AsyncClient() as client:
22+
response = await client.get(url)
23+
response.raise_for_status()
24+
data = response.json()
25+
return [FinancialData(**item) for item in data]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pydantic import BaseModel, Field
2+
from typing import Optional, List
3+
4+
5+
class FinancialData(BaseModel):
6+
revenue: float
7+
net_income: float
8+
free_cash_flow: float
9+
dividends_paid: float
10+
date: str
11+
12+
13+
class GrowthRates(BaseModel):
14+
revenue: dict[str, float]
15+
net_income: dict[str, float]
16+
free_cash_flow: dict[str, float]
17+
dividends_paid: dict[str, float]
18+
19+
20+
class StockValuation(BaseModel):
21+
symbol: str
22+
current_price: float
23+
pe_ratio: float
24+
dividend_yield: Optional[float] = None
25+
growth_rates: GrowthRates
26+
is_quality_dividend_growth_stock: bool
27+
is_undervalued: bool
28+
29+
30+
class Stock(BaseModel):
31+
symbol: str
32+
company_name: str
33+
sector: Optional[str] = None
34+
industry: Optional[str] = None
35+
financial_data: List[FinancialData]
36+
valuation: Optional[StockValuation] = None
37+
38+
class Config:
39+
schema_extra = {
40+
"example": {
41+
"symbol": "AAPL",
42+
"company_name": "Apple Inc.",
43+
"sector": "Technology",
44+
"industry": "Consumer Electronics",
45+
"financial_data": [
46+
{
47+
"revenue": 365817000000,
48+
"net_income": 94680000000,
49+
"free_cash_flow": 90215000000,
50+
"dividends_paid": 14467000000,
51+
"date": "2022-09-30",
52+
}
53+
],
54+
}
55+
}

uv.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)