MT19937

Hi guys,

I began reading some basic material on stochastic calculus and numerical methods. I am writing a toy Python library, where I hope to add analytics to support, for example, pricing a risk bond, a swap, CDS, CDswaptions, generate analytical risks, in my own personal free time, for fun.

Based on the C implementation here, I implemented the MT19937 PRNG algorithm - QuantPy/mt19937.py at master · quantophile/QuantPy. I know that this has a period of 2^19937 - 1, and it passes a number of statistical tests. I also know, that it caches 624 numbers.

Practical question: As a Quant, are you supposed to know, how this algorithm works, or it's pretty much a blackbox to practitioners? I couldn't make much sense of why the algorithm works mathematically - except, I could see computationally, it generated uniformly distributed numbers.

Thanks,
Quasar
 
Hi guys,

I began reading some basic material on stochastic calculus and numerical methods. I am writing a toy Python library, where I hope to add analytics to support, for example, pricing a risk bond, a swap, CDS, CDswaptions, generate analytical risks, in my own personal free time, for fun.

Based on the C implementation here, I implemented the MT19937 PRNG algorithm - QuantPy/mt19937.py at master · quantophile/QuantPy. I know that this has a period of 2^19937 - 1, and it passes a number of statistical tests. I also know, that it caches 624 numbers.

Practical question: As a Quant, are you supposed to know, how this algorithm works, or it's pretty much a blackbox to practitioners? I couldn't make much sense of why the algorithm works mathematically - except, I could see computationally, it generated uniformly distributed numbers.

Thanks,
Quasar
If you do not understand how the math works, then you are no better than the next guy who can copy and paste from stackoverflow. A huge drawback of the development of computational libraries is that people know longer actually know what they are doing. For most quant positions, employers are not interested in someone who can use a library. They are interested in someone who understands the mathematics. Take the time to learn the details.
 

Daniel Duffy

C++ author, trainer
OK, I'll bite
A concrete and focused example is to port C++ MC option pricer to Python. Try to program it from the ground up instead oopy and paste from internet. It makes you stronger :ninja:

V1: Serial code
V2: Parallel code in Python (threads or future)

Use the RNG stuff in numpy.

 
Last edited:

Confused and loose post: what is the goal?
There is no point trying to write your own RNG (and this holds for 95% of quants).
Right, I completely, concur, that there is little point in writing your own RNG, for which an efficient implementation already exists, and the same time is better spent on some other tasks.

My idea was, to write some small implementation for fun, for different things I encounter when reading a math finance book, as I like to learn by doing.
 
Last edited:

Daniel Duffy

C++ author, trainer
Very interesting task, I would like to try this.
And when you are finished you can tell the copy and paste data coders how to do it properly. To make life easy, just use the same class structure 1:1 and change C++ syntax to Python syntax. Piece of cake.

Get it working, then get it right, then (AND ONLY THEN) get it optmised.

And implement the blocks in Figure 2 as Python modules (separation of concerns). Ensures your code doesn't degenarate into great balls of mud :giggle:
 
Last edited:
Top