DEV (fm-finance)
This is my development scratch space for code and math examples in the fm-finance book.
Use the navbar to navigate to a chapter.
1 Getting set up
The examples in this book are written in two free programming languages: R and Python. You don’t need to know either one yet—this page walks you through installing both, no matter which computer you use.
You only have to do this once. Set aside about 20–30 minutes, and feel free to take it one language at a time.
A few words you’ll see along the way:
- Install: download a program and add it to your computer, the same way you’d add any app.
- Console: a window where you type a command and the computer types back. We use it only to check that things are working.
- IDE (Integrated Development Environment): a friendly workspace for writing and running code. Think of it as a word processor built for programming.
2 Installing R
R is the language I’m most familiar with, so we will install it first. We’ll install two things: R itself (the engine) and RStudio (the workspace where you’ll actually write code).
2.1 Step 1 — Install R
Pick the tab for your computer below.
- Go to the R download page: cran.r-project.org/bin/windows/base.
- Click the large Download R for Windows link at the top.
- Open the file you just downloaded (it’ll be in your Downloads folder).
- Click Next through the installer, accepting the suggested options.
- Go to the R download page: cran.r-project.org/bin/macosx.
- Download the file that matches your Mac:
- Apple Silicon (M1, M2, M3, or newer) — most Macs sold since late 2020.
- Intel — older Macs.
- Not sure? Click the Apple menu () in the top-left corner → About This Mac. If it says “Apple M…”, choose Apple Silicon.
- Open the downloaded
.pkgfile and click Continue through the installer.
Most Linux systems install R through their built-in software manager. Open a terminal and run the command for your system:
On Ubuntu, Pop!_OS, or Debian:
sudo apt update && sudo apt install r-baseOn Fedora:
sudo dnf install R2.2 Step 2 — Install RStudio
RStudio is the same on every operating system.
- Go to posit.co/download/rstudio-desktop.
- Scroll to Step 2 on that page and click the download button for your computer (the website detects it for you).
- Open the downloaded file and follow the prompts to install.
Install R before RStudio. RStudio is just the workspace—it needs R already on your computer to do anything.
2.3 Step 3 — Check that R works
Open RStudio. In the Console (the panel on the left), type the line below and press Enter:
2 + 2If you see [1] 4, R is working. 🎉
3 Installing Python
Python is the second language we’ll use. We’ll install Python itself and a free workspace called Positron.
3.1 Step 1 — Install Python
- Go to python.org/downloads and click the yellow Download Python button.
- Open the downloaded file.
- Important: on the first installer screen, check the box that says Add Python to PATH before clicking Install Now. This lets your computer find Python later.
- Go to python.org/downloads and click the yellow Download Python button.
- Open the downloaded
.pkgfile and click Continue through the installer, accepting the suggested options.
Most Linux systems already include Python. Open a terminal and run the command for your system to make sure it’s installed:
On Ubuntu, Pop!_OS, or Debian:
sudo apt update && sudo apt install python3 python3-pipOn Fedora:
sudo dnf install python3 python3-pip3.2 Step 2 — Install Positron
Positron is a free workspace for writing Python (and R) code, made by the same team as RStudio.
- Go to positron.posit.co/download.
- Download the version for your computer.
- Open the downloaded file and follow the prompts to install.
3.3 Step 3 — Check that Python works
Open a console and type the line below, then press Enter:
Open the Start menu, type cmd, and open Command Prompt. Then run:
python --versionOpen the Terminal app and run:
python3 --versionIf you see something like Python 3.12.0, Python is working. 🎉
4 Where to go next
You’re all set! Head to the Income chapter using the navbar to start running the examples.
If an install didn’t work, the most common fixes are restarting your computer (so it notices the new software) and re-running the check command from the steps above.