Monte Carlo Simulation and Python 16 - Comparing profitability

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

Key Takeaways

The video demonstrates the use of Monte Carlo simulation in Python to compare the profitability of different strategies, calculating return on investment (ROI) and wager size percentage. It utilizes Python's random.uniform function and runs multiple simulations to determine the most profitable approach.

Full Transcript

hello everybody and welcome to another monte carlo and python tutorial video in this video we're going to pick up where we left off with this day allen bear strategy but now what we want to do is we want to use the monte carlo simulator to find out at least a couple variables so in this one we want to do wager size and wager count now again wager size is in direct relationship to your full amount of funds at least that's my argument so i don't really see any reason why we would want to make that as well a variable because really we're looking for a percentage size of the total amount so for now we're just going to do these two variables so with that let's go ahead and get started so what we're going to do is we're just going to have a wild true loop up here and what i'm going to go ahead and do as well is let's go up here where all of our constants are let's go ahead and cut and paste those down here so we'll just paste it right here i guess we don't need lower bust and higher profit so i'm just going to move that up here for now we don't really care about that right now sample size we want that that's going to be a constant starting funds that's also going to be a constant but as i said we're going to want to switch up wager size and wager count and then as well we want the return that's going to be a contingent so we want that to because we're going to make a wild true loop so i believe all of the rest of this will be contained in the wild true so let me make that wow true loop so it makes more sense to you guys and so now we've got this so the only uh constants up here are sample size and starting funds now the next thing that we want is we're going to save trying to think i guess that's really all we need for now so then we come down here wager size equals 100 and wager count equals 100 000 or at least what we've got here um what we might want to do is switch this up a little bit so for example we could do wager size of a hundred um instead what we're going to do is this so comment both of those out and instead wager size is going to equal random.uniform and let's do 1.0 to 100.00 and starting funds instead of 100 000 we're going to make that 10 000. um that way 100 is a decent enough 100 is one percent um and i i guess we could actually we could go all the way up to a thousand um that way we're trading up to 10 starting so wager size anything from one to you know from one one thousandth or actually it's even even smaller you guys get the point it's a wide range of wager sizes next a wager count that's going to equal random dot uniform and this is how many wagers are we willing to perform let's do 1.0 and again i think we should allow up to 10 000 wagers anything between one and ten thousand and really one is a horrible number to start with let's do ten and ten thousand so we've got those down now um so that's going to be our random uh two random variables now we've got return that's always going to be the case d a profits d a bus all of that those stay the same then we've got uh wow counter blah blah blah sounds good we come down here and now what i want to go ahead and do is we're going to set um i guess we will use this but not right this instant but we are going to make an roi variable so let's say roi equals that and then we want to have like a a line that we draw so we want to know how large of a return on investment do we care for now the next problem that we have is let's say we have a first of all let's make this sample smaller so what it's going to do is for every random variable it's going to test the sample so i'm going to make this more like 10 000. that other one was way too big that would take a year to get anything decent uh where was i so down here and so we want to pick a number now i don't really know if i want to i hate to hard code this really we should have you know roi and then let's make a total invested equals that and roi should be some form of total invested right uh so what i think we'll do let's run this a couple times to get a some sort of a number and then we'll make this a percentage so as long as roi out of total invested is greater than x that way we can change the starting funds and all of that um dynamically and we won't have to like pick a new number because obviously if you do more wagers you really are looking for a strategy that makes more money and if you're starting with more money obviously you want to make more money so we don't want to hard code it so with that uh we should be able to just run this so let me save this and run and hopefully we can run and as it goes through the strategies we hopefully it's gonna spit out some stuff so this one lost a lot of money and that was a pretty big number oh you know what let me uh let's break this for now uh so i can actually read this print underscores all right start again so anyway return on in intro let's see we got 300 000 but this one was a huge number this was 2 million 21 million actually we lost 21 million on that strategy these guys are getting screwed right now although these are randoms right we're just randomly picking numbers just for the record so we did have a 21 million that's an 18 million so so far we're seeing like 20 million uh to beat um i wish i knew maybe i'll go consult that video and see what the actual numbers were on the profitable version of this strategy so this was the typical allen bear strategy right here so total invested was 100 billion and we made 865 million so 0.865 percent so that's the number to be 0.865 so let me close out of this and so what we want to do is total invested equals this and then what we want to know is uh i guess percent roi and that's going to equal roi out of total invested um this in parentheses times 100.00 now let's add one more print here just to see if we got this right percent roi and that's gonna equal percent roi save and run it and hopefully we can see a few examples so percent roi eight percent is what it's claiming it can't possibly be correct roi returned eight percent hold on let me pause this and check the maths on that eight percenter um here okay just really wanted to check that math that is correct so the number to beat really is 0.8 and this eight percentages is nice but just keep in mind that we're only running for 10 000 samples okay so that's very attractive and we need to print out what the uh interesting we should print out the uh the wager size and the count as well i would would like to know what that was print um wager size i guess we'll make this typical wager size and print wager count read your account and run it some more lost money large wager size there wager count and i suppose as well what we could do is we could say wager size percentage maybe well that's running let me do that too so print wager size percentage and that would be wager size out of starting funds and then again times 100 so we'll encase this bring that in pretty sure you can have spaces there but we'll find out we don't want to find out wager size percentage okay so now we got a percentage and we'll use that uh later on as well so anyways run it again did anybody make money on this one i don't see anybody oh we do have a three percent roi that's pretty good anyway coming down here uh this was a positive wager size was a two percent wager this was also a positive wager size was seven goodness this was a positive waiter size 0.7 okay so anyways you guys get the point now what do we want to do i'll just leave this running and then we'll look at it in a second but we do know that we need to be at least positive 0.86 uh percent roi right so what we want to do now is come down here and if percent roi is greater than 0.865 uh percent then show us the money right so we don't if it's not greater than 0.865 percent roi we really don't care wow look at this one nine 49 roi wager count six six six five thank goodness it wasn't six six seven uh wager size was pretty big too anyway so we're seeing a bunch of uh successful ones and a bunch of unsuccessful ones you know what else would be kind of cool i have some ideas moving forward anyway so what we're going to do now is we've got this maybe we'd want to make this number a little bit bigger oh it looks like we're still returning negatives but would be interesting is we're eventually going to plot this up so i was just going to plot up the positives but it probably would be a good idea to plot up the negatives too so the positives in green and the negatives in red and then where there's crossover that's risk and then where there's not crossover that's not written i think that's what we'll end up doing uh we're gonna have a pretty badass looking plot by the end of this so anyways um that's gonna conclude this tutorial video at least where at least right now what we're doing is we're turning successful returns basically so um anything that has a percent roi on average greater than 0.865 we return those variables so anyways that's going to conclude this video hopefully you guys enjoyed if you've got any questions or comments feel free to leave them below as always thank you for watching thanks for all the support and subscriptions and until the next video

Original Description

Monte Carlo Simulation with Python Playlist: http://www.youtube.com/watch?v=9M_KPXwnrlE&feature=share&list=PLQVvvaa0QuDdhOnp-FnVStDsALpYk2hk0 Here we compare the profit-ablity of the strategies. Not only does it matter whether or not we profit or go bust, it matters how much we profit when we do. 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

This video teaches how to use Monte Carlo simulation in Python to compare the profitability of different strategies, including calculating ROI and wager size percentage. It provides a practical example of how to apply this concept to real-world problems. By following this lesson, viewers can learn how to build and run their own Monte Carlo simulations to inform their decision-making.

Key Takeaways
  1. Create a Monte Carlo simulation
  2. Define variables for wager size and wager count
  3. Calculate ROI
  4. Run the simulation multiple times to get a number
  5. Make the number a percentage
  6. Print out ROI, wager size, and count
  7. Print out wager size percentage
  8. Compare percent ROI with 0.865 threshold
  9. Plot successful and unsuccessful returns in green and red respectively
  10. Identify crossover between successful and unsuccessful returns as risk
💡 The video highlights the importance of considering not only whether a strategy is profitable, but also how much it profits when it does, and demonstrates how to use Monte Carlo simulation to make this comparison.

Related Reads

📰
The Visual Reverse Engineering Hypothesis: From Phosphenes to Latent Space
Explore the Visual Reverse Engineering Hypothesis to understand how the brain processes visual information and its potential connection to AI models
Medium · AI
📰
AI-Driven Software Engineering: Advances in Agentic Workflows, Code Generation, and Developer…
Learn how AI-driven software engineering advances agentic workflows, code generation, and developer tools, improving software development efficiency and quality
Medium · AI
📰
Can AI Badger Reduce Local Coding Agent Token Usage?
Learn how AI Badger can reduce local coding agent token usage by 32.1% and runtime by 54.5% through compact handoff and compression
Dev.to AI
📰
Devin, the "First AI Software Engineer," Failed 86% of Its Benchmark Tasks, and Then What
Devin, an AI software engineer, failed 86% of benchmark tasks, highlighting limitations of AI in replacing human engineers
Dev.to · Alex @ Vibe Agent Making
Up next
How to Start a SaaS Business in 2026
Learn With Shopify
Watch →