rsRustPrimer

Learn Rust, from zero to production.

Learn Rust from scratch by building a real computation engine

A progressive, bilingual course: every notion explained simply, exercises with solutions, and a running project that grows with you into a Monte Carlo risk engine callable from Kotlin.

modules
14
lessons available
32
project steps
11
riskforge/src/main.rs
fn expected_exposure(mtms: &[f64]) -> f64 {
let total: f64 = mtms.iter().map(|m| m.max(0.0)).sum();
total / mtms.len() as f64
}
fn main() {
let mtms = vec![1_200.0, -300.0, 450.0, 0.0, -800.0];
println!("EE = {:.2}", expected_exposure(&mtms)); // 330.00
}

Running project

riskforge, step by step

Throughout the course you build riskforge: a Monte Carlo engine that simulates the exposure of a derivatives portfolio to a counterparty (EE, PFE, EPE, then CVA). Each module ends with a step of the project, so by the end you have a real Rust program, parallelized, benchmarked, and callable from Kotlin.

Workbook on GitHub ↗
  1. 01

    Kick off the project

    A Cargo crate that compiles and prints the simulation context.

  2. 02

    Positive exposure

    Exposure of one scenario and the average over a few hard-coded scenarios.

  3. 03

    Aggregate without copying

    Functions that borrow scenarios (&[f64]) instead of duplicating them.

  4. 04

    Domain model

    Trade, NettingSet and instrument types modeled with structs and enums.

  5. 05

    Portfolio

    Trades filed by counterparty in a HashMap of netting sets, sorted report.

  6. 06

    Load a portfolio

    Reading a CSV of trades with typed errors, without a single panic.

  7. 07

    Diffusion models

    A shared trait for GBM and mean reversion (Ornstein-Uhlenbeck), and a first Monte Carlo simulation.

  8. 08Coming soon

    Exposure profiles

    EE, 97.5% PFE and EPE computed with iterators across the whole time grid.

  9. 09Coming soon

    Tests and benchmarks

    Unit tests, comparison with the Kotlin results and criterion benchmarks.

  10. 10Coming soon

    Parallelization

    Simulation spread across every core with rayon, speedup measured.

  11. 11Coming soon

    Called from Kotlin

    C-ABI library called from the JVM (FFM API), final JVM versus Rust benchmark.

Your progress

0/32

You haven't started yet. Jump into the first lesson!

Course modules

1

Getting started

0/4

Understand what Rust is, install the toolchain, and run your first Cargo project.

4 lessonsStart
2

Language basics

0/5

Variables, types, functions and control flow: the core grammar of Rust.

5 lessonsStart
3

Ownership and borrowing

0/4

The concept that makes Rust unique: who owns a value, who may read it, who may change it.

4 lessonsStart
4

Structs, enums and pattern matching

0/5

Model a domain with precise types, and let match check every case.

5 lessonsStart
5

Collections

0/4

Vec, String and HashMap: the everyday data structures.

4 lessonsStart
6

Error handling

0/5

Option, Result and the ? operator: errors visible in the types, no exceptions.

5 lessonsStart
7

Traits and generics

0/5

Polymorphism the Rust way: shared behavior, with zero runtime cost.

5 lessonsStart
8

Closures and iterators

map, filter, fold: functional code as fast as a hand-written loop.

Coming soon
9

Lifetimes

Understand 'a annotations and why the compiler sometimes needs them.

Coming soon
10

Modules, tests and benchmarks

Organize a crate, write built-in tests and measure with criterion.

Coming soon
11

Smart pointers

Box, Rc, Arc and RefCell: when single ownership is not enough.

Coming soon
12

Concurrency

Threads, channels and rayon: parallelism without data races, guaranteed by the compiler.

Coming soon
13

Async with Tokio

async/await, futures and the Tokio runtime for network programs.

Coming soon
14

FFI and JVM interop

Controlled unsafe, the C ABI, and calling a Rust library from Kotlin.

Coming soon