Python Environment Setup
Complete installation guide for FIN510
1 Python Environment Setup for FIN510
This guide will help you set up a professional Python environment for financial data science.
1.1 Required Software
1.1.1 1. Anaconda Distribution (Recommended)
Download: https://www.anaconda.com/download
Anaconda includes Python, Jupyter Lab, and most scientific libraries pre-installed.
1.1.1.1 Installation Steps:
- Download Anaconda for your operating system
- Run the installer with default settings
- Verify installation by opening Anaconda Navigator
1.1.2 2. Alternative: Miniconda + Manual Setup
For advanced users who prefer minimal installation:
# Install miniconda
# Then install required packages
conda install pandas numpy matplotlib seaborn plotly
conda install scikit-learn tensorflow jupyter
pip install yfinance pandas-datareader quantlib-python
1.2 Required Python Libraries
1.2.1 Core Data Science Stack
# Data manipulation and analysis
import pandas as pd
import numpy as np
# Visualization
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
# Statistical analysis
import scipy.stats as stats
import statsmodels.api as sm
1.2.2 Financial Libraries
# Financial data acquisition
import yfinance as yf
import pandas_datareader as pdr
# Quantitative finance
import quantlib as ql
# Time series and econometrics
from arch import arch_model
1.2.3 Machine Learning & AI
# Traditional ML
from sklearn import *
import xgboost as xgb
import lightgbm as lgb
# Deep learning
import tensorflow as tf
from tensorflow.keras import layers
# Natural Language Processing
from textblob import TextBlob
from transformers import pipeline
1.3 Installation Commands
1.3.1 Option 1: Conda Installation (Recommended)
# Create new environment for FIN510
conda create -n fin510 python=3.9
conda activate fin510
# Install core packages
conda install pandas numpy matplotlib seaborn plotly
conda install scikit-learn jupyter jupyterlab
conda install -c conda-forge yfinance
# Install additional packages via pip
pip install arch pandas-datareader quantlib-python
pip install xgboost lightgbm tensorflow
pip install textblob transformers vaderSentiment
1.3.2 Option 2: Pip Installation
# Install all packages via pip
pip install pandas numpy matplotlib seaborn plotly
pip install scikit-learn jupyter jupyterlab
pip install yfinance pandas-datareader quantlib-python
pip install arch statsmodels scipy
pip install xgboost lightgbm tensorflow
pip install textblob transformers vaderSentiment
1.4 Verification Script
Run this script to verify your installation:
# FIN510 Environment Verification Script
import sys
import importlib
= [
required_packages 'pandas', 'numpy', 'matplotlib', 'seaborn', 'plotly',
'sklearn', 'yfinance', 'arch', 'statsmodels',
'tensorflow', 'xgboost', 'textblob'
]
print("FIN510 Python Environment Check")
print("=" * 40)
print(f"Python Version: {sys.version}")
print()
= []
missing_packages
for package in required_packages:
try:
= importlib.import_module(package)
module = getattr(module, '__version__', 'Unknown')
version print(f"✓ {package}: {version}")
except ImportError:
print(f"✗ {package}: NOT INSTALLED")
missing_packages.append(package)
if missing_packages:
print(f"\n❌ Missing packages: {', '.join(missing_packages)}")
print("Please install missing packages before proceeding.")
else:
print("\n✅ All required packages installed successfully!")
print("You're ready for FIN510!")
1.5 Development Environment Setup
1.5.1 Jupyter Lab Configuration
# Recommended Jupyter Lab extensions
# Run these commands in your terminal:
# Install extensions
-git
pip install jupyterlab
pip install jupyterlab_code_formatter-variableInspector
pip install jupyterlab
# Configure Jupyter for finance
--generate-config
jupyter lab
# Add to ~/.jupyter/jupyter_lab_config.py:
= True
c.ServerApp.open_browser = 8888
c.ServerApp.port = '/path/to/your/fin510/projects' c.NotebookApp.notebook_dir
1.5.2 VS Code Setup (Optional but Recommended)
Extensions to install: - Python - Jupyter - Python Docstring Generator - GitLens - Pylance
1.6 API Setup
1.6.1 Financial Data APIs
1.6.1.1 1. Yahoo Finance (Free)
import yfinance as yf
# Test Yahoo Finance connection
= yf.Ticker("AAPL")
ticker = ticker.history(period="1mo")
data print("Yahoo Finance connection successful!")
1.6.1.2 2. Alpha Vantage (Free tier available)
- Sign up at https://www.alphavantage.co/
- Get your free API key
- Store in environment variable:
import os
'ALPHA_VANTAGE_API_KEY'] = 'your_api_key_here'
os.environ[
# Test connection
import pandas_datareader as pdr
= pdr.get_data_alphavantage('AAPL', api_key=os.environ['ALPHA_VANTAGE_API_KEY']) data
1.6.1.3 3. Quandl (Optional)
# Install and setup Quandl
pip install quandlimport quandl
= "your_quandl_api_key" quandl.ApiConfig.api_key
1.7 Troubleshooting
1.7.1 Common Issues
1.7.1.1 ImportError: No module named ‘package_name’
# Solution: Install the missing package
pip install package_name
# Or if using conda:
conda install package_name
1.7.1.2 SSL Certificate Errors (yfinance)
# Add this to your Python scripts
import ssl
= ssl._create_unverified_context ssl._create_default_https_context
1.7.1.3 Jupyter Kernel Issues
# Register your conda environment as Jupyter kernel
conda activate fin510
python -m ipykernel install --user --name=fin510
1.7.1.4 Memory Issues with Large Datasets
# Optimize pandas memory usage
import pandas as pd
'display.max_columns', None)
pd.set_option('mode.chained_assignment', None)
pd.set_option(
# Use chunking for large files
for chunk in pd.read_csv('large_file.csv', chunksize=10000):
process(chunk)
1.8 Performance Optimization
1.8.1 Recommended Settings
# Add to your Python startup file
import warnings
'ignore')
warnings.filterwarnings(
# Configure pandas for better performance
import pandas as pd
'display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', 50)
pd.set_option(
# Configure matplotlib for better plots
import matplotlib.pyplot as plt
'seaborn-v0_8')
plt.style.use('figure.figsize'] = (12, 8)
plt.rcParams['font.size'] = 10
plt.rcParams[
# Set random seeds for reproducibility
import numpy as np
42) np.random.seed(
1.9 Getting Help
1.9.1 Course Support
- Discussion Board: Post technical questions
- Office Hours: By appointment
- Email: b.quinn1@ulster.ac.uk
1.9.2 Online Resources
- Python Documentation: https://docs.python.org/
- Pandas Documentation: https://pandas.pydata.org/docs/
- Stack Overflow: Tag questions with
python
andfinance
- GitHub Issues: Course repository for bug reports
1.9.3 Emergency Contacts
- IT Support: 028 9536 7188
- Blackboard Help: blackboardhelpdesk@ulster.ac.uk
This setup guide will be updated throughout the semester. Check back for the latest versions and troubleshooting tips.