This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
payouts = [] | |
for i in range(10000): | |
n = np.random.geometric(0.5) | |
payouts.append(2 ** n) | |
plt.title("Payout distribution") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
total = 0 | |
num_rolls = 10000 | |
for _ in range(num_rolls): | |
roll = random.randint(1, 6) | |
total += roll | |
average_naive = total / num_rolls |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def HHH(p): | |
return 1/p + 1/(p**2) + 1/(p**3) | |
tosses = [] | |
for i in range(10000): | |
chain = [] | |
while True: | |
chain.append(np.random.choice([0, 1], p=[.5, .5])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import random | |
# Define the state space and number of days | |
state_space = range(101) | |
num_days = 365*20 | |
# Generate fake daily data for the Markov chain | |
# For simplicity, we'll use a random choice for transitions between states | |
daily_data = [random.choice(state_space) for _ in range(num_days)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# transition matrix | |
P = np.array([[.5, .5, 0, 0], | |
[.5, 0, .5, 0], | |
[.5, 0, 0, .5], | |
[.5, 0, 0, .5]]) | |
# Simulation | |
hits = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
N = 10 | |
P0 = np.array([[.5, .5, 0, 0], [.5, 0, .5, .0], | |
[.5, 0, 0, .5], [.5, 0, 0, .5]]) | |
P1 = np.array([[.5, .5, 0, 0], [.5, 0, .5, .0], | |
[.5, 0, 0, .5], [0, 0, 0, 1]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
P = np.array([[.7, .3],[.6, .4]]) | |
P26 = np.linalg.matrix_power(P, 26) | |
print(P26[1][0]*.5 + P26[0][0]*.5) | |
day27 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
day2 = [] | |
for i in range(10000): | |
# Randomly select coin 1 or 2 on day 1 | |
X = np.random.randint(0, 2) | |
# Flip either coin and append the outcome to day2 vector |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
# Assuming df is your DataFrame and it has 'salary' and 'stock_return' columns | |
# df = pd.read_csv('your_data.csv') # Replace with your data source | |
# Creating the scatter plot | |
plt.figure(figsize=(10, 6)) | |
plt.scatter(fr, np.log(stock_comp), color='blue', edgecolor='black', s=50) |
NewerOlder