Monte Carlo Simulation and Python 13 - D'Alembert Strategy

sentdex · Beginner ·💻 AI-Assisted Coding ·12y ago

Key Takeaways

Programs D'Alembert strategy using Monte Carlo simulation

Full Transcript

what is going on everybody welcome to the 12th monte carlo and python tutorial video you don't know it but i just recorded this entire video uh without recording it so i guess i didn't record it but anyway this will be the second time i walk through this entire video so uh so in the last video we saw um at least with our multiple we saw what kind of we were with our first example of a monte carlo simulation actually giving us a variable and we've got two different betting strategies we had one where we just bet the same thing over and over which obviously resulted in a loss because there was a one percent house edge and with rolled ice um before we end this series i can't remember if i already said this or not uh i can't remember if i said it when i was recording or when i wasn't recording but we will change rolled ice uh for pure 50 50 odds just in case you're playing something like roulette or something like that where you really do have 50 50 odds just a rare scenario now um one of the more popular strategies with 50 50 odds is called the i'm gonna butcher the name probably i'm gonna guess it's day to allen bear just to guess it's spelled day apart d apostrophe alan bert uh with your english accent or america accent anyway with this strategy the way it works is as follows so say you're what you're starting wager is a hundred dollars if you lose you would then bet two hundred dollars lose three hundred dollars win two hundred dollars win 100 lose 200 and so on so you increment it that way you're not multiplying it you're just adding one more increment to the original wager size so with that we are we're going to program our own day allen bear strategy now again i already went through this once so i'm a little ticked off but here we go so uh define d a l and of course same parameters as usual funds initial wager and wager count colon and we're going to go ahead and global variables that don't exist but we'll make them so da underscore busts and global ba underscore profit so we can measure this guy value equals funds to start wager equals initial underscore wager uh we're not going to be plotting anything here current wager equals one of course we start at one previous wager uh this is going to be so we know was it a winner loss last time for now we're going to say it was a win just because you will increment well really you're not doing anything you're just you definitely don't want to increment or de-increment or anything so um so that's that and also well never mind we'll get into the next implication but anyway previous wager equals a win and then previous wager amount of course we need to know what we're adding to so initial wager for now is where it starts and now we're ready to begin so while current wager is less than or equal to wager count what do we want to do if the previous wager previous wager was a win then what we want to do is de-increment right but that said just because we want to de-increment every time we have a win let's say that doesn't mean every time we would want to do that say like if you've won so much that you're back to your initial wager amount if you de-increment you'd be you know betting in our case a zero or actually in everybody's cases a0 so you want to have a check so what we're going to say is if wager equals initial wager pass else wager minus equals initial wager okay so that's how we're going to cover that now we're going to roll the dicer assume we roll the dice so roll dice so if roll dice is true so we won we want to do value plus equals wager else we lost value minus equals wager also if we won there's no need to edit the win but if we lost we do need to notify the system that previous uh wager is a loss subsequently if uh if we've gone bust we're gonna say if value is uh less than or equal to zero as usual what do we do we're gonna say d a busts plus equals one and we want to break now we come over underneath this if statement here and we're gonna run alif previous wager if the previous wager was a loss and make some space if the previous wager was a loss uh wager equals previous wager amount plus an ish initial underscore wager so we're adding one increment to it um if but uh if our current value so we need to have a check so we don't go into the negatives as we've done with the other ones so we're gonna say if value so if the amount of money we have minus the wager we're intending to wage um is less than or equal to zero we can't do that so then we're just going to say wager equals value so we can't go into the negatives now when we're all set there the next thing we're going to do is we're going to roll the dice again so if we roll the dice and it is true value oops not caps value plus equals the wager and since this was a loss initially we need to edit that variable so we're going to say previous wager equals a win now else value minus equals wager and we don't need to notify it that the previous wager was lost but we do need to notify what the previous wager amount was and that equals wager and actually we need to do that again here i believe if the roll if we roll dice let's see previous wager equals when if roll dice value equals plus equals wager i think we need to notify the wager amount on all of these let's see previous wager amount equals initial wager if let's see so if we win a plus equals wager i really think we need to update previous wager amount equals wager we need to do this on all of these really so under the if dice do that under the else do that under the if that and we already did it under the else i think we're all set there so now we've covered everything uh except for if we've gone bust so we'd say if value is less than or equal to zero d a underscore bus plus equals one break i don't need to play anymore and finally uh underneath this alif all right if alif we want to do current wager plus equals one finally at the end of everything we come down here and at the end of this entire strategy we want to know if value is greater than funds da underscore profits plus equals 1 and that's basically everything now the next question we want to know however is we'd like to call this strategy first of all so let's go ahead and call this bad boy uh so i'm gonna paste it up here edit in what we need so starting funds initial wager is waiter size and wager count here pace okay copy this or actually cut that and we'll paste that down here and now just for debugging purposes i think it would be wise to have some print statements in here um so so we're sure that this is working as expected so we'll print current wager and then wager and then we'll also print how many funds we have value value and then if roll dice is the case uh print we won current value value otherwise we lost so print we lost current value value and then scrolling down further uh print lost the last wager current wager and we'll say wager and then value value and then again we'll print here print we won current value value and then here print we lost current value value cool let's save that and i think we're prepared to run so let's run it syntax raw we mean syntax i'm looking at it not seeing it oh here we go oh print there we go let's do it again all right so this one person strategy appears to have lost some money but not everything is at 8 200 right now after 100 wagers let's scroll up current wager 100 we won he's still going to wager 100. we lost he lost he's back to 10 000. we lost the last wager current wager 200. we lost we're down to 9 800 then we're gonna wager 300 we lose apparently and we're back down to 9 500. lost the last one so we're gonna wager 400 we won 9900 we're gonna do 300 i'm looking for a streak of two wins it looks like we have one down here so 300 we lost 9 600 okay we're going to wager 400 9 600 we're back to 10 000. current wager 300 103 205 110 six and so on okay so it looks like our day allen bear strategy is now in full effect and just for kicks uh let's go ahead and comment out some of these prints we don't need so many prints and eventually we will actually graph the dale and bear strategy i suspect it'll look quite a bit like the doublers strategy over a long period and that is part of the point of the day allenberry strategy is that you want to be able to play for a while so your odds kind of do go to 50 50. but just for kicks uh sample size wager count will do 10 000 wagers and let's say you're wagering 10 instead so hopefully this guy doesn't go totally broke the a bus is not oh he went bust fan families uh let's just go ahead and i guess define d a underscore busts equals 0.0 and really we need to define all these other variables too uh da busts and da profits where are you i'm so lost right now guys okay we called it here and then everything else is way down there so here's what i want to do time we have time imported okay so da best and we'll also call da underscore profits 0.0 let's run it again at the end i guess we're not actually saying anything are we so at the very end uh i guess we'd want to say uh current wager plus equals zero print value zero zero man all these guys are going broke surely something is arrived everybody is going broke okay i guess i'll uncomment these out maybe it's just too many wagers oh you know what though uh the problem is they're not probably the problem is we're not at 50 50 odds i guess we can watch this guy go broke that is probably the issue here is this is a 50 50 betting strategy that is not good if if you have one percent uh stacked against you i'm gonna go ahead and guess that's it yeah okay so maybe in the next video what we'll work on is uh this poor soul what was the most he ever had he actually went up pretty high it was at like 15 grand for a little bit and it went down from there we lost like some she had some serious losing streaks look at this lost sauce man you'd be getting really pissed off at that point anyway uh so we'll fix that because over the long term scale with a lot of people um in the sample the down bear strategy really ought to do pretty good so anyway uh we'll hit that in the next video probably so anyways hopefully you guys enjoyed you got your day allen bear strategy feel free to play around maybe make your waiter size one if you want you can probably figure out how to edit roll dice to make it 50 50 odds otherwise wait for the next video as always thanks for watching

Original Description

Monte Carlo Simulation with Python Playlist: http://www.youtube.com/watch?v=9M_KPXwnrlE&feature=share&list=PLQVvvaa0QuDdhOnp-FnVStDsALpYk2hk0 In this video, we program the D'Alembert Strategy. The D'Alembert betting strategy is a progressive betting strategy that uses increments rather than multiples. In the monte carlo simulation with Python series, we test various betting strategies. A simple 50/50 strategy, a martingale strategy, and the d'alembert strategy. We use the monte carlo simulator to calculate possible paths, as well as to calculate preferred variables to use including wager size, how many wagers, and more. There are many purposes for a monte carlo simulator. Some people use them as a form of brute force to solve complex mathematical equations. A popular example used is to have a monte carlo simulator solve for pi. In our case, we are using the Monte Carlo simulator to account for randomness and the degree of risk associated with a betting strategy. In the world of stock trading and investing, people can use the Monte Carlo simulator to test a given strategy's risk. It used to be very much the case that only performance was considered, for the most part, to decide on a trader's value. Only until recently has the paradigm shifted to consider a strategy's risk more closely. Through this series, you will be able to see just how much random variability can affect the outcome, regardless of how "good" or "bad" a strategy might have been. http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related Reads

Up next
How to Create WordPress Maintenance Mode Plugin Using Claude AI (No Coding Skills Needed)
Quick Tips - Web Desiign & Ai Tools
Watch →