68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
from ETF_Portal.services.data_service import DataService
|
|
import logging
|
|
import json
|
|
|
|
# Set up logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def test_data_fetching():
|
|
# Initialize service
|
|
service = DataService()
|
|
|
|
# Test portfolio
|
|
portfolio = ['MSTY', 'FEPI', 'JEPI', 'VTI', 'VOO']
|
|
|
|
for ticker in portfolio:
|
|
print(f"\nTesting {ticker}:")
|
|
print("=" * 50)
|
|
|
|
try:
|
|
# Get ETF data
|
|
data = service.get_etf_data(ticker)
|
|
|
|
# Print data source
|
|
if data.get('is_estimated'):
|
|
print("\nData Source: High Yield Estimates")
|
|
elif 'info' in data and data['info']:
|
|
print("\nData Source: FMP API")
|
|
else:
|
|
print("\nData Source: yfinance")
|
|
|
|
# Print data structure
|
|
print("\nData Structure:")
|
|
for key, value in data.items():
|
|
if isinstance(value, dict):
|
|
print(f"{key}: {len(value)} items")
|
|
if key == 'info' and value:
|
|
print(" Sample info fields:")
|
|
for k, v in list(value.items())[:5]:
|
|
print(f" {k}: {v}")
|
|
else:
|
|
print(f"{key}: {value}")
|
|
|
|
# Print key metrics
|
|
print("\nKey Metrics:")
|
|
print(f"Volatility: {data.get('volatility', 'N/A')}")
|
|
print(f"Max Drawdown: {data.get('max_drawdown', 'N/A')}")
|
|
print(f"Sharpe Ratio: {data.get('sharpe_ratio', 'N/A')}")
|
|
print(f"Sortino Ratio: {data.get('sortino_ratio', 'N/A')}")
|
|
print(f"Dividend Trend: {data.get('dividend_trend', 'N/A')}")
|
|
print(f"ETF Age: {data.get('age_years', 'N/A')} years")
|
|
print(f"Is New ETF: {data.get('is_new', 'N/A')}")
|
|
print(f"Is Estimated: {data.get('is_estimated', 'N/A')}")
|
|
|
|
# Save raw data for inspection
|
|
with open(f"{ticker}_data.json", 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
print(f"\nRaw data saved to {ticker}_data.json")
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error testing {ticker}: {str(e)}")
|
|
raise
|
|
|
|
if __name__ == "__main__":
|
|
test_data_fetching() |