Exercise 0: Technical prerequisites
Before we begin working with R, Python, and Quarto in Advanced Empirical Finance, please set up your computer so that you can run code from day one. No prior experience with programming or development tools is required — this guide walks you through everything step by step. Should you encounter any issues, please do not hesitate to contact your TAs or me for assistance. To facilitate collaboration, please ask me via the Absalon discussion board to make sure everyone can benefit from the solution.
Prerequisites
Install the required software
Install Positron (latest Version). Positron is the integrated development environment (IDE) we use. It supports R, Python, Git, and Quarto in one place. Install Positron using the default settings.
Register a free account on GitHub. GitHub allows us to share course materials and collaborate.
Install Git. Git is the version control system we use to connect to GitHub.
Install uv and uvr. uv installs Python and the Python packages of the course; uvr does the same for R. You don’t install R or Python yourself. Open a terminal and run the two lines for your system:
macOS and Linux (Terminal):
curl -LsSf https://astral.sh/uv/install.sh | sh curl -fsSL https://raw.githubusercontent.com/nbafrank/uvr/main/install.sh | shWindows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/nbafrank/uvr/main/install.ps1 | iex"Then close the terminal and open a new one, so it finds
uvanduvr. If uv and uvr are already on your computer, for example from another course, update them instead withuv self updateanduvr upgrade; the course needs uvr 0.4.8 or later.
Set up the course repository
- Clone the course repository in Positron:
Open the Source Control view Ctrl-Shift-GCtrl-Shift-G. If Git is not yet installed, the view shows how to install it.
Click
Clone Repositoryand paste the address of the course repository:https://github.com/advanced-empirical-finance/course-repository.gitChoose a local folder for the repository. Cloning means creating your own copy of a shared project on your computer, so you can work on it without affecting the original.
- Open the cloned repository in Positron with
File→Open Folder. The folder holds the slides, the templates for the mandatory assignments, the R and Python environment and thedatafolder; the licensed data from Absalon go there, too (see the exercises on financial data). When we announce new course material, get it withgit pullin the Terminal, or Pull in the Source Control view.
We encourage you to use Git and GitHub for your team work, but you do not have to. If you want to, one of you creates the team’s repository; it stays connected to the course repository, so new course material still reaches you.
On GitHub, create a new private repository, without a README, for example
aef27-<team>. Under Settings → Collaborators, invite your teammates.In the Terminal of your clone of the course repository, run (with your username and repository name):
git remote rename origin upstream git remote add origin https://github.com/<username>/aef27-<team>.git git push -u origin main git config pull.rebase falseYour teammates accept the invitation, clone the team repository instead of the course repository, and run
git remote add upstream https://github.com/advanced-empirical-finance/course-repository.git git config pull.rebase false
From then on, git pull and git push work with your team’s repository, and git pull upstream main brings new course material. How to split the work and check each other’s reports: collaboration with Git and GitHub.
Install R, Python and the course packages
In the Terminal (not the Console) of Positron: because you opened the course repository in step 6, the Terminal starts in the repository’s folder, the one that holds
uvr.tomlandpyproject.toml. Then runuvr r install 4.6.1 uvr sync uv syncuvr r installinstalls R,uvr syncinstalls all R packages of the course, anduv syncinstalls Python and all Python packages of the course, includingaefsim, the client for the trading game. Everyone gets exactly the same package versions, because they are recorded in the repository (uvr.lockfor R,uv.lockfor Python). If Positron asks which R or Python to use, choose R 4.6.1 for R. For Python, choose the environment thatuv syncjust created in the.venvfolder of the course repository: its path ends incourse-repository/.venv, not in a Python installed elsewhere on your computer.Adding a package works the same way in both:
uvr add tidymodelsfor R,uv add polarsfor Python. To collaborate with your peers, commit the filesuvr.toml,uvr.lock,pyproject.tomlanduv.lock; your colleagues only have to runuvr syncanduv syncto replicate your exact package environment.To verify that R is working correctly, click on
New/New Fileand selectR fileto open a new R script in Positron and typelibrary(tidyfinance) download_data( domain = "Stock Prices", symbols = "AAPL", start_date = "2000-01-01", end_date = "2023-12-31")Mark everything and press to run the code. If everything is working correctly, you should see that you just downloaded financial data in the console. If you receive an error such as
there is no package called 'tidyfinance', Positron is not using the course’s R: when R starts, the console should sayuvr: library linked (… packages). If it doesn’t, choose R 4.6.1 with the interpreter icon on the top right, restart R (Session→Restart R), and runuvr syncin the Terminal again.To verify that Python is working correctly, click on
New/New Fileand selectPython fileto open a new Python script in Positron and typeimport tidyfinance as tf tf.download_data( domain="Stock Prices", symbols="AAPL", start_date="2000-01-01", end_date="2023-12-31")Mark everything and press to run the code. If everything is working correctly, you should see that you just downloaded financial data in the console. If you receive an error, select the course’s Python environment first: click on the interpreter icon on the top right and choose the one in the course repository’s
.venv.
Render PDFs with TinyTeX
You hand in every mandatory assignment as a PDF that Quarto renders from your .qmd file. Quarto comes with Positron, but PDF output also needs LaTeX. Install TinyTeX, a small LaTeX distribution, once:
In Positron’s Terminal, run:
quarto install tinytexCheck the installation with
quarto check. Under “Checking LaTeX”, the output should name TinyTeX. If it saysTex: (not detected), run the install command again, then restart Positron.Test it: open
mandatory-assignments/MA_R_template.qmd(orMA_python_template.qmd) from the course repository and click Preview. Positron shows the PDF in the Viewer.