Welcome to the monte carlo simulation experiment with python.
Before we begin, we should establish what a monte carlo simulation is. The idea of a monte carlo simulation is to test various outcome possibilities. In reality, only one of the outcome possibilities will play out, but, in terms of risk assessment, any of the possibilities could have occurred.
Monte carlo simulators are often used to assess the risk of a given trading strategy say with options or stocks.
Monte carlo simulators can help drive the point home that success and outcome is not the only measure of whether or not a choice was good or not. Choices should not be assesed after their outcome. Instead, the risks and benefits should only be considered at the time the decision was made, without hindsight bias. A monte carlo simulator can help one visualize most or all of the potential outcomes to have a much better idea regarding the risk of a decision.
With that, let's consider a basic example. Here, we will consider a gambling scenario, where a user can "roll" the metaphorical dice for an outcome of 1 to 100.
If the user rolls anything from 1-50, the "house" wins. If the user rolls anything from 51 to 99, the "user" wins. If the user rolls a 100, they lose.
With this, the house maintains a mere 1% edge, which is much smaller than the typical house edge, as well as the market edge when incorporating trading costs.
For example, consider if you are trading with Scottrade, where the house takes $7 a trade. If you invest $1,000 per stock, this means you have $7 to pay in entry, and $7 to pay in exit, for a total of $14.
This puts the "house edge" to 1.4% right out of the gate. Notably, Scottrade is not the actual house. The house is just not you. This means that, on a long term scale, your bets need to do better than 1.4% profit on average, otherwise you will be losing money. Despite the small number, the odds are already against you. Trading is a 50/50 game, especially in the short term.
A monte carlo generator can also help illustrate the flaws of the gambler's fallacy. Many gamblers, and sometimes especially gamblers who understand statistics, fall prey to the gambler's fallacy.
The fallacy asserts that, taking something like the flipping of a coin for heads or tails, you have a known 50/50 odds. That said, if you just flipped heads five times a row, somehow you're more likely to flip tails next.
No matter how many heads have preceeded, your odds, each time you flip the coin are 50/50. It is easy to fall into the trap of thinking that on a long term scale odds will correlate to 50/50 therefor if the odds are imbalanced currently then the next flip's odds are also not 50/50
So again, with our example in mind, 1-50, house wins. 51-99 user wins. A perfect 100 means house wins.
Now, let's begin. We first need to create our dice. For this, we'll employ the pseudo random number generator in python.
import random def rollDice(): roll = random.randint(1,100) return roll # Now, just to test our dice, let's roll the dice 100 times. x = 0 while x < 100: result = rollDice() print(result) x+=1