You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.5 KiB
Python
100 lines
3.5 KiB
Python
"""
|
|
Simple test to verify real SEC data is working
|
|
"""
|
|
|
|
import requests
|
|
import yfinance_plus as yf
|
|
from datetime import datetime
|
|
|
|
API_URL = "http://localhost:18001/api/v1"
|
|
|
|
def test_apple_real_data():
|
|
"""Test AAPL with a fresh date range"""
|
|
print("=== Testing AAPL Real SEC Data ===")
|
|
|
|
# Use a different date range to avoid conflicts
|
|
response = requests.post(
|
|
f"{API_URL}/financial/data",
|
|
json={
|
|
"ticker": "AAPL",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-12-31",
|
|
"period_type": "all",
|
|
"include_metrics": True,
|
|
"force_refresh": False # Don't force refresh initially
|
|
}
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print(f"✅ Success! Got {len(data['financial_data'])} periods")
|
|
|
|
# Check data quality
|
|
for i, fd in enumerate(data['financial_data']):
|
|
print(f"\nPeriod {i+1}: {fd['period_date']}")
|
|
print(f" Revenue: ${fd.get('revenue', 0):,.0f}")
|
|
print(f" EPS: ${fd.get('eps', 0):.2f}")
|
|
print(f" Shares Outstanding: {fd.get('shares_outstanding', 0):,.0f}")
|
|
print(f" Market Cap: ${fd.get('market_cap', 0):,.0f}")
|
|
print(f" P/E Ratio: {fd.get('pe_ratio', 0):.2f}")
|
|
print(f" Data Source: {fd.get('data_source', 'Unknown')}")
|
|
print(f" Is Estimated: {fd.get('is_estimated', 'Unknown')}")
|
|
|
|
# Check if we got real data
|
|
if not fd.get('is_estimated', True):
|
|
print(" ✅ REAL DATA!")
|
|
else:
|
|
print(" ⚠️ Estimated data")
|
|
|
|
return True
|
|
else:
|
|
print(f"❌ Error: {response.status_code}")
|
|
print(response.text)
|
|
return False
|
|
|
|
def compare_with_yfinance():
|
|
"""Compare with yfinance_plus for the same period"""
|
|
print("\n=== Comparing with YFinance_plus ===")
|
|
|
|
try:
|
|
stock = yf.Ticker("AAPL")
|
|
quarterly_income = stock.quarterly_income_stmt
|
|
|
|
if not quarterly_income.empty:
|
|
print("\nYFinance_plus Data:")
|
|
for i, quarter in enumerate(quarterly_income.columns[:4]): # Show 4 quarters
|
|
revenue = quarterly_income.loc['Total Revenue', quarter] if 'Total Revenue' in quarterly_income.index else 0
|
|
net_income = quarterly_income.loc['Net Income', quarter] if 'Net Income' in quarterly_income.index else 0
|
|
eps = quarterly_income.loc['Diluted EPS', quarter] if 'Diluted EPS' in quarterly_income.index else 0
|
|
|
|
print(f"\n Quarter {i+1}: {quarter}")
|
|
print(f" Revenue: ${revenue:,.0f}")
|
|
print(f" Net Income: ${net_income:,.0f}")
|
|
print(f" EPS: ${eps:.2f}")
|
|
|
|
# Show company info
|
|
info = stock.info
|
|
print(f"\nYFinance_plus Company Info:")
|
|
print(f" Shares Outstanding: {info.get('sharesOutstanding', 0):,.0f}")
|
|
print(f" Market Cap: ${info.get('marketCap', 0):,.0f}")
|
|
print(f" Current Price: ${info.get('currentPrice', 0):.2f}")
|
|
|
|
except Exception as e:
|
|
print(f"Error getting yfinance_plus data: {e}")
|
|
|
|
def main():
|
|
print("Testing Real SEC Financial Data Implementation")
|
|
print("=" * 60)
|
|
|
|
# Test Stock Oracle
|
|
success = test_apple_real_data()
|
|
|
|
if success:
|
|
# Compare with yfinance_plus
|
|
compare_with_yfinance()
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Test completed!")
|
|
|
|
if __name__ == "__main__":
|
|
main() |