setup_smart_system.pyโข5.3 kB
# setup_smart_system.py - Setup script for smart trading system
import subprocess
import sys
from pathlib import Path
def install_package(package):
"""Install a package using pip."""
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
return True
except subprocess.CalledProcessError:
return False
def check_package(package_name, import_name=None):
"""Check if a package is installed and importable."""
if import_name is None:
import_name = package_name
try:
__import__(import_name)
return True
except ImportError:
return False
def main():
"""Setup the smart trading system."""
print("๐ SMART TRADING SYSTEM SETUP")
print("=" * 50)
# Required packages
required_packages = [
("yfinance", "yfinance"),
("pandas", "pandas"),
("numpy", "numpy"),
("scikit-learn", "sklearn"),
("matplotlib", "matplotlib"),
("seaborn", "seaborn"),
("arch", "arch"), # For ARIMA-GARCH
("statsmodels", "statsmodels") # For enhanced ARIMA
]
print("๐ฆ Checking dependencies...")
missing_packages = []
for package, import_name in required_packages:
if check_package(package, import_name):
print(f" โ
{package}")
else:
print(f" โ {package} - missing")
missing_packages.append(package)
if missing_packages:
print(f"\n๐ง Installing missing packages: {', '.join(missing_packages)}")
for package in missing_packages:
print(f" Installing {package}...")
if install_package(package):
print(f" โ
{package} installed successfully")
else:
print(f" โ Failed to install {package}")
else:
print("\nโ
All dependencies are already installed!")
# Check file structure
print(f"\n๐ Checking file structure...")
required_dirs = [
"models",
"config",
"results",
"results/smart_trading"
]
for dir_path in required_dirs:
path = Path(dir_path)
if path.exists():
print(f" โ
{dir_path}/")
else:
path.mkdir(parents=True, exist_ok=True)
print(f" ๐ Created {dir_path}/")
# Check config file
config_file = Path("config/trading_config.json")
if config_file.exists():
print(f" โ
config/trading_config.json")
else:
print(f" โ ๏ธ config/trading_config.json not found")
print(f" Create this file with your portfolio configuration")
# Test imports
print(f"\n๐งช Testing critical imports...")
try:
import yfinance as yf
print(" โ
yfinance")
import pandas as pd
print(" โ
pandas")
import numpy as np
print(" โ
numpy")
from sklearn.ensemble import RandomForestRegressor
print(" โ
scikit-learn")
try:
import arch
print(" โ
arch (ARIMA-GARCH available)")
garch_available = True
except ImportError:
print(" โ ๏ธ arch (ARIMA-GARCH not available)")
garch_available = False
try:
import statsmodels
print(" โ
statsmodels")
except ImportError:
print(" โ ๏ธ statsmodels (enhanced ARIMA not available)")
except ImportError as e:
print(f" โ Import test failed: {e}")
return False
# Test basic functionality
print(f"\n๐ฌ Testing basic functionality...")
try:
# Test data download
print(" Testing data download...")
data = yf.download("AAPL", period="5d", progress=False)
if not data.empty:
print(" โ
Data download works")
else:
print(" โ Data download failed")
except Exception as e:
print(f" โ Data download test failed: {e}")
# Final status
print(f"\n๐ฏ SETUP SUMMARY:")
print("=" * 50)
if garch_available:
print("โ
Full ARIMA-GARCH functionality available")
print("๐ง Smart model selection: ARIMA + ARIMA-GARCH")
else:
print("โ ๏ธ Limited functionality - ARIMA only")
print("๐ก Install 'arch' package for full ARIMA-GARCH support")
print(f"\n๐ READY TO USE:")
print(" python enhanced_main.py # Show portfolios")
print(" python enhanced_main.py lenny_golub # Smart analysis")
print(" python enhanced_main.py all # Analyze all stocks")
if not config_file.exists():
print(f"\nโ ๏ธ NEXT STEP: Create config/trading_config.json with your portfolios")
sample_config = {
"tickers": {
"example_portfolio": ["AAPL", "MSFT", "GOOGL"],
"lenny_golub": ["COIN", "GBTC", "HOOD", "MSTR", "PYPL"]
}
}
print(" Sample config:")
import json
print(json.dumps(sample_config, indent=2))
if __name__ == "__main__":
main()