Monte Carlo Methods
a case study
Dmitri Nesteruk
dmitrinesteruk@gmail.com
Hi!
• My name is Dmitri
• Quant finance
• Developer Evangelist @ JetBrains (2010-…)
• Visiting Researcher @
University of ...
Calculation of 𝜋𝜋
• Generate lots of points in
square
• Area of circle
𝜋𝜋𝑟𝑟2
• Area of square
4𝑟𝑟2
• ∴ 𝜋𝜋 = 4
𝑆𝑆𝑐𝑐𝑐𝑐𝑐𝑐 𝑐𝑐𝑐...
� 𝑒𝑒 𝑥𝑥2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
2
4
6
8
10
12
14
16
18
Poker (is largely bots  )
AH 7S
? ?
AS KH TC
try every single combination
6
C
6
D
win
win
loss
loss
loss
AH 7S
40% to win
Challenging (&geeky) games for heavy MC
HearthStone
• ~400 differentcards
• Player pick a deck of 30
• Each card has stationary and transient behaviors
• May affe...
Rules
• Stored in an XML file
• Parsed via boost::regex
• Result in creation of std::function objects
Everything affects everything
• This card gives bonus to other card
• When card enters play, …
• When card leaves play, …
...
Properties
• Properties are built-in in C#, not available in C++ or Java
• __declspec(property) compiler extension
• Suppo...
Change notifications
• We want to be informed when properties change
• Use boost::signals
• Let’s borrow .NET ideology!
Event Bus
• Global communication pipeline
• Entity signs up when enters game, disconnects on exit
• Also uses signal/slot ...
Realtime Analysis
• The game uses Unity
• Decompiled .NET libs
• Reverse-engineerProtocol Buffer definitions
• …
• PROFIT!...
Packet Capture
• Winpcap
• Capture game state
• Reanalyze at each significant change
Architecture
• Intel C++
• >10k Xeon cores
• 24x Intel Xeon Phi
That’s it!
• Monte-Carlo Methods in
Financial Engineering, Paul
Glasserman, Springer
• Boost
http://boost.org
• Course on ...
Monte Carlo C++
Upcoming SlideShare
Loading in …5
×

Monte Carlo C++

456 views
364 views

Published on

Slides from my MC talk at the C++ User Group, St.Petersburg, Russia, June 2014

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
456
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Monte Carlo C++

  1. 1. Monte Carlo Methods a case study Dmitri Nesteruk dmitrinesteruk@gmail.com
  2. 2. Hi! • My name is Dmitri • Quant finance • Developer Evangelist @ JetBrains (2010-…) • Visiting Researcher @ University of Southampton (2002-…) • MVP Visual C# (2009-…)
  3. 3. Calculation of 𝜋𝜋 • Generate lots of points in square • Area of circle 𝜋𝜋𝑟𝑟2 • Area of square 4𝑟𝑟2 • ∴ 𝜋𝜋 = 4 𝑆𝑆𝑐𝑐𝑐𝑐𝑐𝑐 𝑐𝑐𝑐𝑐𝑐𝑐 𝑆𝑆𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 • Area ~ number of points r
  4. 4. � 𝑒𝑒 𝑥𝑥2
  5. 5. 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 2 4 6 8 10 12 14 16 18
  6. 6. Poker (is largely bots  )
  7. 7. AH 7S ? ? AS KH TC try every single combination 6 C 6 D win win loss loss loss AH 7S 40% to win
  8. 8. Challenging (&geeky) games for heavy MC
  9. 9. HearthStone • ~400 differentcards • Player pick a deck of 30 • Each card has stationary and transient behaviors • May affect 0, 1 or several other cards
  10. 10. Rules • Stored in an XML file • Parsed via boost::regex • Result in creation of std::function objects
  11. 11. Everything affects everything • This card gives bonus to other card • When card enters play, … • When card leaves play, … • This interaction method does not map well to OOP
  12. 12. Properties • Properties are built-in in C#, not available in C++ or Java • __declspec(property) compiler extension • Supported on at least Intel and MSVC compilers • A person structure keeps the person’s age • Age (read/write) • Only people older than 16 can vote • CanVote (readonly) • This is a derivative property (at runtime you need an std::function)
  13. 13. Change notifications • We want to be informed when properties change • Use boost::signals • Let’s borrow .NET ideology!
  14. 14. Event Bus • Global communication pipeline • Entity signs up when enters game, disconnects on exit • Also uses signal/slot paradigm
  15. 15. Realtime Analysis • The game uses Unity • Decompiled .NET libs • Reverse-engineerProtocol Buffer definitions • … • PROFIT!!!
  16. 16. Packet Capture • Winpcap • Capture game state • Reanalyze at each significant change
  17. 17. Architecture • Intel C++ • >10k Xeon cores • 24x Intel Xeon Phi
  18. 18. That’s it! • Monte-Carlo Methods in Financial Engineering, Paul Glasserman, Springer • Boost http://boost.org • Course on Boost at http://pluralsight.com • Send feedback to: @dnesteruk dmitrinesteruk@gmail.com

×