There is no risk forecasting without code. Every method in these notes is implemented three times over, in R, Python and Julia. Work in whichever you know.
6.1 Installation
6.1.1 R and RStudio
To work with R, you need two components:
R, the language and statistical computing engine.
RStudio, an integrated development environment (IDE) that makes working with R easier.
If prompted, install R first — you will be directed to the correct version for your operating system.
Note: If you are using a Windows ARM-based machine, you may need to search separately for the compatible R version, as it is not always the default option.
Once both are installed, launch RStudio. You should see a console window where you can start entering R code immediately.
6.1.2 Positron
Positron is Posit’s newer IDE. R and Python are both first-class runtimes in it, each with its own console, variables pane and plots pane, so it suits work that moves between the two. It is free for personal and academic use.
Install it as you would any other application — on Windows it also needs the Microsoft Visual C++ Redistributable, which most machines already have;
Open the folder holding your work with File > Open Folder. Positron works on a folder rather than a file, and your data files are read relative to it;
Click Start Session at the top right and choose the interpreter you want to use.
The last step matters more than it looks. A machine usually carries several Pythons — one belonging to the operating system, others installed by other software, another from a distribution such as Anaconda. Positron finds all of them and starts the newest unless told otherwise, which need not be the one holding your packages. The interpreter in use is named at the top right whenever a session is running, and Positron remembers the choice for that folder.
Quarto comes with Positron, so rendering to HTML or Word needs nothing further. PDF is the exception, because Quarto produces it through LaTeX and supplies none. If you have no LaTeX distribution already, run quarto install tinytex once in the terminal.
6.1.3 Python
To work with Python, we recommend uv, a fast package and environment manager that can also install Python itself:
Download and install the current stable release for your operating system;
Alternatively, use juliaup for managing Julia versions.
Once installed, launch Julia to access the REPL (interactive prompt) where you can start entering code immediately.
6.1.5 Packages used in this book
Installing R, Python and Julia gives you the languages, not the packages this book’s code imports. The commands below install those packages at whatever version is current when you run them, not the exact versions used to write the book, so results may differ slightly from what is shown here. We do not distribute a locked, version-pinned environment for any of the three languages.
A few chapters that fetch data directly from the EODHD API use additional author-maintained packages not listed here.
Package installation is the last of the setup. The rest of this chapter is about the environment you work in. Chapter 29 collects the learning material, documentation and community links for all three languages.
6.2 User interfaces
The interface matters. Some tools help beginners learn quickly. Others are better for speed, automation or mixed-language work.
6.2.1 RStudio
For most beginners, RStudio is the practical choice. It keeps the editor, console, help and plots in one place.
6.2.2 Posit Cloud
Posit Cloud provides RStudio through a web browser, without any local installation. It runs the same RStudio interface on remote servers.
Posit Cloud helps when you cannot install software on your computer, when you move between machines or when a class or team needs identical R environments. It sets up R, packages and file storage automatically. Projects are easy to share, and you can reach your work from any device with an internet connection.
The free tier covers learning and small projects but has usage limits and needs an internet connection throughout. For extensive analysis or sensitive data, a local RStudio installation is more appropriate.
6.2.3 Quarto
Quarto combines code, output and prose in one file. That is why we use it for these notes. Chapter 17 has more information.
6.2.4 Jupyter
Jupyter notebooks mix code and prose in a cell-based document that runs one cell at a time and exports to HTML or PDF. Each language needs a support package, known as a kernel (IRkernel for R, ipykernel for Python, IJulia for Julia).
Jupyter is convenient for sharing analysis with colleagues who use different languages, since the same interface serves R, Python and Julia, and it suits teaching and presenting analysis step by step. It is less comfortable for long scripts, refactoring and any task that depends on seeing the whole program at once.
6.2.5 VSCode
Visual Studio Code or VSCode is a general-purpose editor with solid support for R and Quarto. It has become a bit bloated and unwieldy, however, and we have moved to Zed for writing these notes.
VSCode supports AI-assisted coding through extensions such as GitHub Copilot. Cursor is a separate editor built on VSCode with AI features throughout.
6.2.6 Zed
Zed is a newer, faster editor than VSCode, with a useful extension for R and AI assistance built in. It does not yet support Quarto documents, so we edit .qmd files in Zed as plain markdown and render them from the command line.
Zed favours performance and simplicity over breadth. Its R support covers syntax highlighting and basic language features, but falls short of RStudio or VSCode, and its extension ecosystem is smaller. We use Zed. Beginners should start with RStudio.
6.2.7 Basic editors
Each language comes with a basic interface:
R: The base R editor gives a simple text-editing window alongside the R console, with basic syntax highlighting.
Python: Python’s IDLE gives a simple interactive shell and editor.
Julia: The Julia REPL (Read-Eval-Print Loop) is an interactive command-line interface.
None of them offers code completion, a plot pane or any notion of a project. Use them when the machine is too old or too locked down to install anything else. Otherwise use RStudio or VSCode.
6.2.8 Command line
All three languages can be accessed from the command line, which is useful for remote servers, high-performance computing clusters or SSH sessions:
R: Type R in a terminal to start the R interpreter.
Python: Type python or python3 to start the Python interpreter.
Julia: Type julia to start the Julia REPL.
The command line draws no graphics, so it stays usable over an SSH connection that would make an IDE unbearable, and it is how most production work runs. The cost is that errors arrive as text, with no plot pane to look at and no variable explorer to poke around in, which makes debugging harder.
6.2.9 Non-interactive scripts
For automated workflows and batch processing, all three languages can run scripts non-interactively:
R: Rscript filename.R
Python: python filename.py
Julia: julia filename.jl
This is how a risk report gets rebuilt at six every morning with nobody present. A script run this way has to be self-contained. It loads its own data, sets its own parameters and writes its output to a file, because there is no one to answer a prompt or notice a warning scrolling past. That is also why error handling matters more here than in interactive work — an unhandled failure at six in the morning is discovered when someone asks for the report.
6.3 Which language
The next three chapters cover the same ground — assignment, vectors, matrices, dictionaries, data frames, packages and source files — once in R, once in Python and once in Julia. Read the one you work in and skip the other two. They are alternatives, not a sequence, and nothing later in the book assumes you have read more than one of them.