Lecture 1: Introduction to Python

MATH60230A - Empirical Finance

Vincent Grégoire

HEC Montréal

Saad Ali Khan

HEC Montréal

🚀 Welcome to the MSc Finance at HEC Montréal!

  • 3 credits on half a semester:
    • 3 credits × 2 × 3 hours = 18 hours of work per week.
    • 6 hours of teaching

⏳ Expect to work 12 hours at home. 😰

Vincent Grégoire, PhD, CFA

👨‍🎓 Education:

  • PhD Finance, U. of British Columbia
  • MSc Fin. Eng., U. Laval
  • MSc Elec. Eng., U. Laval
  • Computer Eng., U. Laval

🔬 Main research area:

  • information economics
  • finance and technology:
    • market microstructure
    • big data & AI in finance
    • cybersecurity

Plan for Today

  • Introduction and course outline.
  • Introduction to Python.
  • Introduction to GitHub and GitHub Classroom.
  • Assignment 1

Course notes

  • Available online.
  • Expect changes (don’t print it all)
  • Still a work in progress, please send feedback

Python for Data Analysis

  • Available for free online
  • For lectures 3-4
  • Panels, data cleaning, arrays, pandas, numpy.

Econometrics

  • Available for free through the library (Springer)

Statistics and Data Analysis for Financial Engineering

  • Available for free through the library (Springer)

Ressources

Course outline

Communication

  • For questions, we will use Microsoft Teams
    • channel O365-MATH 60230A - J01 - H2026.

Why learn to code?

  • It’s fun
  • Saves you time
  • Produce better research
  • You want it1 on your CV
  • You need it for the MSc in Finance

Why Python?

  • General purpose programming language
    • Websites, games, full software
  • Most popular language for data science1
  • Free, open source software
  • Large community
  • Lots of code online -> LLMs know it well

👍 What is it very good for?

  • Data manipulation
  • Visualization
  • Text analysis
  • Statistics and econometrics
  • Linear algebra
  • Machine learning
  • Web scraping

👎 What is it less good for?

  • Very high-performance applications (additional libraries needed)
  • Advanced statistical analysis

Installing Python

To use Python, you need:

  • The Python interpreter: to execute your code
  • A package manager to manage librairies
  • An editor

Preferred: uv and Visual Studio Code

  • All free!
  • See course notes for installation details

uv

  • Package manager for Python
    • Installs and manages Python
    • Installs and manages third-party librairies

Visual Studio Code

  • One of the most popular editor
  • Free, by Microsoft, open-core
  • Extensible and customizable
  • Cross-platform

Git and GitHub

git

  • A free and open source distributed version control system.
  • You can think of git as adding “track changes” to your code, better.

GitHub

  • A hosted solution for git, plus more, owned by Microsoft.
  • We will use GitHub Classroom for assignments.
  • We will use GitHub Copilot for AI coding assistance.

You need to create a free account at github.com and apply for the Student Developer Pack.

Installation

In the cloud

  • You can also run Python in the cloud on GitHub Codespaces1.
  • Above the free tier (90 hours per month for students), you need to pay.
  • This is a good alternative solution if you can’t get Python running on your computer, or if you only have a tablet.

Online resources

Markdown

  • Simple markup language to format text.
  • The syntax is easy to learn.
  • Markdown is everywhere:
    • GitHub, VS Code, Jupyter Notebooks
    • Even these slides are written in Markdown using Quarto
  • Some implementations (i.e., Jupyter, VS Code) support math equations.

▶️ Let’s get started!

Now, let’s try some Python!

For next class

  • Get started on assignment 1
  • Finish reading of course notes Part 1 - Python
    • Chapters “Logging and Configuration” and “Stay Safe with Devcontainers” are optional