# (λ Quant Interview Questions)

Here are some interview questions typically asked of quant candidates.

# Mathematics

Math interview problems can consist of really anything. I got asked about fundamental groups once. In practice, focus on the basics: probability, linear algebra, stochastic calculus. Plus whatever you dared put on your resume. Also expect brainteasers.

## Probability Brainteasers

A couple has two children. You are told one is a girl, what is the probability the other is also a girl?

The likelihood that the other child is a girl is only 1/3.

For a random pair of children, there are four equally likely possibilities: boy-boy, boy-girl, girl-boy, and girl-girl. For the sibling in question, we know that boy-boy is not possible. Of the remaining three equally likely possibilities, only one has two girls.

## Combinatorics Brainteasers

Provide an intuitive explanation as to why

$\sum^{n}_{k=0} \binom{n}{k} = 2^n$

for any non-negative integer $n$.

$2^n$ represents the number of subsets of a set of size $n$. This is because a set can be identified by the outcomes of $n$ choices of whether to include a given element or not.

The binomial coefficient $\binom{n}{k}$ represent the number of all subsets of size $k$ chosen from $n$ elements. Summing this from $k=0$ (the empty set) to $k=n$ gives total number of all subsets that can be formed of any size. And, as we demonstrated before, this is equal to $2^n$.

# Computer Fundamentals

## Concurrency

Each process is provided its virtual memory allocation. Processes do not have access to another process's virtual memory. Processes can only communicate through other means (sockets, shared memory, ...).

Threads belonging to a process, however, do share a common heap through which they can communicate. Each thread is allocated its own stack.

(Python-specific) In what situations would you use multiprocessing or multithreading in Python?

The cpython interpreter has a Global Interpreter Lock ("GIL") which acts as a mutex on the entire python interpreter. It cannot be released in python proper. Instead, it can be released in C extensions. This is the case for IO operations. So multithreading makes sense for things like webservers. However, multiprocessing is required to scale compute-intensive workloads.

Alternatively, drop Python and use a language that isn't horrible.

# Databases

## Joins

Consider a table consisting of end-of-day prices for various securities. The fields are: symbol, price, and date. There may not be entries for all possible symbol/date pairs. Write a query that will return the lastest available price for each symbol.

This query can be executed by inner-joining on a subquery that extracts the latest available date for each symbol.

SELECT
x.symbol,
y.price
FROM (SELECT
symbol,
MAX(date) as date
FROM
EODPrices
GROUP BY
symbol) AS x
INNER JOIN
EODPrices AS y
ON
x.date = y.date AND
x.symbol = y.symbol


# Algorithms & Data Structures

Quant interview coding questions are comparable to those of tech companies. The solutions to problems in this section are given in Julia.

## Hash Tables

Construct a function that determines if two strings are permutations of each other's characters.

Create character frequency tables of each string and compare.

areperms(str1, str2) = freqtable(str1) == freqtable(str2)

freqtable(str) = begin
tbl = Dict{Char,Int}()
for chr ∈ str
if chr ∈ keys(tbl)
tbl[chr] += 1
else
tbl[chr] = 1
end
end
tbl
end


## Recursion

Generate all permutations of integers from 1 through N.

Recursively generate all permutations of all integers from 1 through N-1. Then insert the integer N at every place.

permutations(N) = begin
N == 1 && return [[1]]
perms = permutations(N-1)
[insert!(copy(p),N,i) for i in 1:N for p in perms]
end


## Dynamic programming

Consider a street containing $N$ houses. Each house can be be painted red, green, or blue. No two adjacent house can have the same color. The cost of painting the $n$th house red is $R_n$, blue is $B_n$, and green as $G_n$. supposing these values are given for $n=1,\ldots,N$, find the minimum cost to paint these houses.

Denote $\mathcal R_n$ as the minimum cost to paint the first $n$ houses such that the $n$th house is red. Define $\mathcal B_n$ and $\mathcal G_n$ similarly. Then

$\mathcal R_n = R_n + \min\{\mathcal G_{n-1},\mathcal B_{n-1}\}.$

Analogous formulas exist for $\mathcal G$ and $\mathcal B$. For this formula to work for $n=1$, one must set $\mathcal R_0 = \mathcal B_0 = \mathcal G_0 = 0$.

The minumum possible cost is then the minumum of $\mathcal R_N$. $\mathcal G_N$, and $\mathcal B_N$. Below is a simple implementation in linear time and constant space:

mincost(R,G,B) = begin
ℛ = ℬ = 𝒢 = 0
for (r,g,b) in zip(R,G,B)
ℛ, 𝒢, ℬ = r+min(𝒢,ℬ), g+min(ℬ,ℛ), b+min(ℛ,𝒢)
end
min(ℛ,ℬ,𝒢)
end