GithubHelp home page GithubHelp logo

quanttest's Introduction

Quantitative Research test

October 13, 2016

In Fall 2016, I applied to a quant trading firm (Jane Street). They had me take a HackerRank test for which I was told it was going to be on 'basic math and probability'. To me, these questions require practice so I thought I would post these questions here as sample questions so that future interviewees can practice and be more prepared than I was.

Time: 30 minutes

4 questions

  1. We randomly select 4 numbers from the set of the first 16 prime numbers, without replacement. What is the probability their sum is even? Why?
  2. You have been chosen to play a game involving a 8-sided die. You get to roll the die once, see the result, and then may choose to either stop or roll again. Your payoff is the sum of your rolls, unless this sum is greater than 8, in which case you "bust" and get nothing. What is your strategy for this game? That is, for each possible outcome of the first roll will you choose stop or to roll again?
  3. A bag has three coins in it which are visually indistinguishable, but when flipped, one coin has a 20% chance of coming up heads, another as a 20% chance of coming up heads, and the last has 60% chance of coming up heads. I randomly draw a coin from the bag and flip it, and the result comes up heads. What is the probability that if I reflip this coin, it will come up heads again? Why?
  4. We have two urns. You can't tell them apart from the outside, but one has four $1 chips and six $10 chips, and the other has three $1 chips and seven $10 chips. You randomly draw a chip from one of the urns and it happens to be a $1 chip. Without replacing this draw, I offer you a chance to draw and keep a chip from either urn. Should you draw from the same urn or the opposite urn, and what is the expected value of the chip you draw? Why?

Good luck. Feel free to compare your solutions against mine afterwards.

quanttest's People

Contributors

maiminhp avatar

Stargazers

Jeff avatar  avatar  avatar Aashish Tripathee avatar  avatar  avatar Cyclotomic Fields avatar Tejas Gupta avatar  avatar km2m avatar SiriusYH avatar Grant Johnson avatar Mo avatar  avatar Jennifer avatar JayFreeman avatar  avatar Charaf ZGUIOUAR avatar  avatar Lukas Drews avatar Shreya Mondal avatar Alexander Remmerie avatar Xiulong Liu avatar  avatar  avatar Brandon Ng avatar Dwight Temple avatar Dhruv Kumar avatar  avatar Angela Lee avatar Tri Hoang avatar  avatar M avatar sabysahoo avatar  avatar Evan Semet avatar GaoLaoHuanXiang avatar  avatar Artemas Radik avatar Ravi Brock avatar Ryan Shen avatar  avatar Ali Fida avatar Andrea Pinto avatar Ujjwal Bhatnagar avatar  avatar  avatar  avatar Valentio Iverson avatar  avatar Alejandro Ballesteros avatar Xinyi Li avatar Kane Norman avatar Ft avatar  avatar  avatar  avatar Ben Brown avatar  avatar Abhiram Rao avatar Hui San Chiam avatar Hugh avatar  avatar Emmanuel Sekyi avatar  avatar Strarch avatar THK Cheng avatar  avatar Samson Qian avatar Gowri Jayaprakash avatar  avatar Sreemanti Dey avatar Peter Niu avatar Yichen Liu avatar  avatar Matthew avatar QIQIN YU avatar Vishad Bhalodia avatar Andrew Giuliani avatar  avatar Elías Abad avatar  avatar Edward Li avatar  avatar Hester Lim avatar  avatar Sanket Saharkar avatar Allen Wang avatar

Watchers

 avatar  avatar

quanttest's Issues

Q4: Expanding on the intuition of the urn probability

I wasn't able to intuitively understand how to mathematically derive this at first glance so I would like to add the explanation for this statement in case anyone faces the same issue:
image

Denoting $D_1$ as the first draw from the urns, the $P(X=1)$ shown above actually means $P(X=1|D_1=1)$. Using the Bayes's rule,

$P(X=1|D_1=1) = \dfrac{P(D_1|X=1)P(X=1)}{P(D_1|X=1)P(X=1)+P(D_1=1|X=2)P(X=2)}$

Since $P(X=1)=P(X=2)=0.5$, we simplify the equation:

$= \dfrac{P(D_1|X=1)}{P(D_1|X=1)+P(D_1=1|X=2)}=\dfrac{0.4}{0.4+0.3}=\dfrac{4}{7}$

Similarly, with $P(X=2|D_1=1) $, we will get $\dfrac{3}{7}$

Mistake in question 2

There's a mistake in question 2. I think the optimal strategy would be to re-roll if first roll <= 3.

You only calculate probabilities but one should look at the expected value. One should only perform a second roll when its expected value is larger than what we currently have by our first roll.

first roll Expected value second roll
1 1/8 * (2 + 3 + 4 + 5 + 6 + 7 + 8) = 35/8
2 1/8 * (3 + 4 + 5 + 6 + 7 + 8) = 33/8
3 1/8 * (4 + 5 + 6 + 7 + 8) = 30/8
4 1/8 * (5 + 6 + 7 + 8) = 26/8
5 1/8 * (6 + 7 + 8) = 21/8
6 1/8 * (7 + 8) = 15/8
7 1/8 * (8) = 1
8 0

As soon as the first roll = 4, the expected value that we obtain by making a second roll is lower than the value we already have. As such, optimal strategy is to re-roll when first roll <= 3.

Another extra question that could be asked here is how much you would be willing to bet. For this, we can calculate the expected value of this game. For first roll equal to 1, 2 or 3, we take the expected value of the second roll. For the others, we take the expected value of the first roll.
Giving us: E[X] = 1/8 * (35 / 8 + 33 / 8 + 30 / 8 + 4 + 5 + 6 + 7 + 8) = 5.28125
--> We are willing to bet anything lower than this value.

One could calculate this for an alternative strategy as well. E.g. re-rolling when first roll <= 4 gives us:
E[X] = 1/8 * (35 / 8 + 33 / 8 + 30 / 8 + 26/8 + 5 + 6 + 7 + 8) = 5.1875

Simulation in Python (ugly code!)

>>> import numpy as np
>>> reward_3 = []
>>> reward_4 = []
>>> for _ in range(1_000_000):
...   r1 = np.random.randint(1, 9)
...   if r1 <= 3:
...     strat1 = r1 + np.random.randint(1, 9)
...   else:
...     strat1 = r1
...   if r1 <= 4:
...     strat2 = r1 + np.random.randint(1, 9)
...   else:
...     strat2 = r1
...   if strat1 > 8:
...     strat1 = 0
...   if strat2 > 8:
...     strat2 = 0
...   reward_3.append(strat1)
...   reward_4.append(strat2)
... 
>>> print(np.mean(reward_3))
5.280888
>>> print(np.mean(reward_4))
5.186363

Notice how the average rewards our expected values very well (law of large numbers)

Possible mistake

possible_mistake
In the solution of the third exercise, i think that in the part above the first probability of each addendum should be conditional to X=C_i instead that F_i=H.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.