Monte Carlo Simulation and Python 18 - 2D charting monte carlo variables
Key Takeaways
This video demonstrates how to use Matplotlib to create a 2D scatter plot of Monte Carlo simulation data, specifically to visualize the relationship between variables and their impact on profit. The code reads data from a CSV file and uses the csv.reader module to parse the data, then plots the data using Matplotlib's scatter plot function.
Full Transcript
what is going on everybody welcome to another monte carlo tutorial video with python uh where we left off we were generating some data and we were just saving it to a csv and basically the data in that csv is if the data is better than uh one percent or worse than negative one percent then we want to know what variables contributed to that data and then we save that to the csv so now what we want to do is we want to chart it up and visualize the data because what we're looking for is if there's any clumps of data either in positive or negative that can kind of give us a bit of an idea of variables that correspond to either the positive or negative changes so with that what we're going to do is i'm going to get rid of this i'm just going to literally delete everything in here i suggest you save yours just in case you want to revisit the code later on or you want to run your own tests so take a moment and save the data maybe just go file new and open yourself up a blank script anyway i'm going to clear my now now and start anew so what we're doing here is we're going to start plotting this stuff so of course if you want to plot you need matplot lib and then we want to import matte matte plot lib.pi plot as plt i assume everybody at this point has matplotlib since we needed it earlier in the video so anyway and then we also want to import csv because we saved this data to a csv now we want to graph this stuff so we're going to have a define graph empty parameter function and now we're going to say with open uh file name here we have money carlo liberal.csv with the intention to read and we're going to open this as monte carlo data is going to equal csv dot reader and what do we want to read well we want to read monte carlo with a delimiter delimiter of a comma because that was our delimiter so again we're using csv.reader which is we imported csv up here and basically this is just python's csv reading app or module basically so just a good way to easily read the contents of a csv file so when you use it you just have to tell it what is it reading and then what's the delimiter and it automatically understands new line and all that so we've got data's next what we want to do is for each line in datas we want to do something with this data just so happens we want to plot it um so we're going to need to explain what's what here so first we're going to say percent roi that is equal to the float of each line zero uh wager size percent equals flow each line one and what we've got going on here is it's automatically being divided up by the comma delimiter so each line and datas is spit out as a list and you've got chunks in that list and it's just so happens it's split up in the uh in the way that we set it up so anyway moving on um so the next part in that list is wager count and that is equal to the flow of each line two and then finally p color for plot color equals each line three just as a quick aside in typical debugging and all this stuff for um python and charting and matplotlib obviously the word color where it doesn't really correspond like before in this tutorial i wanted to use results oh and anyway or like return that was what i wanted to use um and that you can't do that because return is a you know built-in function same thing with color though color is a built-in parameter for you guessed it color of plots so you can't just use color you have to use something else like p color just keep that in mind when you name variables sometimes you might name a variable that runs over the name of a very important variable so each time we find this data what do we want to do with it well we're going to scatter plot it so plot dot scatter and for now we'll just do a simple 2d scatter plot so wager size percent that's what we care about and wager count finally color equals p color so we add those to the plots and then when everything's all said and done after the width uh we're going to plot show now we'll just have it automatically call graph save it run it and the file was actually i'm trying to think how big my file was but it was actually a pretty large file so anyways we have our plot now at least with my eyeballs um i don't see any correlation uh at all here this looks like a pretty random plotting um i mean there's some places where you've got groups but i mean you really have to grasp it at straws here if you think you're seeing any sort of pattern so i don't see any pattern but there is an unsaid variable so far here and that is how much money um so we know that this is more than one percent uh return on investment but we know nothing else we just know it's more than one percent um so we definitely want to dig further into this and the way we would dig further is by how much money did we make um you know what is that percent uh so that's the next thing that we want to look at so luckily we obviously have percent roi that's one of our variables so we can plot that but we also kind of want to plot it alongside this stuff so what we're going to do now is we're going to plot with matplotlib's 3d capabilities so that's what we're going to do in the next video so stay tuned for that also the 3d plotting is very intense for python so what i figured i would do is because this is random um it's also pretty hard to see anything of significance just right now anyways and i bet in the 3d we won't see too much so i went ahead and i've been building a file that is that requires five percent so it has to be a return on investment greater than five percent or less than negative five percent so i've been building that at the moment and so in my video i've got a couple of different things i'll show you the one percent file and i'll also show you the five percent and all of that so anyway that's what we're going to be doing the next video is plotting this on a 3d plot so we can actually see all of the variables here so that should be pretty interesting uh as always thanks for watching thanks for all the support and subscriptions and until next time
Original Description
Monte Carlo Simulation with Python Playlist: http://www.youtube.com/watch?v=9M_KPXwnrlE&feature=share&list=PLQVvvaa0QuDdhOnp-FnVStDsALpYk2hk0
Here we use Matplotlib to chart a 2D representation of our variables and their relationship to profit.
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
Related Reads
📰
📰
📰
📰
How technical interviews should change in the age of AI-assisted coding
Medium · Programming
Why I’m Building an AI Website Builder That Verifies Its Own Work
Medium · Startup
I made a Claude Code plugin that turns your project into a demo video
Medium · Programming
Poolside releases Laguna S 2.1, the open-weight coding model pitched as the West’s answer to DeepSeek and Qwen
The Next Web AI
🎓
Tutor Explanation
DeepCamp AI