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) |
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
def get_latest_highest(stock, comp, year): | |
return get_exec_comp(stock)[get_exec_comp(stock)['year'] == year].drop_duplicates("nameAndPosition").sort_values(by=comp, ascending=False).iloc[0] | |
fr = [] | |
p = [] | |
stock_comp = [] | |
total_comp = [] | |
for ticker in r_2021['Adj Close'].reset_index()['index'].values: | |
fr.append(r_2021['Adj Close'][ticker]) | |
p.append(p_2021['Adj Close'][ticker]) |
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 yfinance as yf | |
import pandas as pd | |
# Define the stock symbols | |
# Define the time period | |
start_date = '2021-01-01' | |
end_date = '2022-01-01' | |
# Download the stock data |
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
plt.figure(figsize=(10, 6)) | |
plt.hist(get_exec_comp("TSLA").drop_duplicates('nameAndPosition')['total']/1000000, bins=30, color='skyblue', edgecolor='black') | |
# Enhancing the plot | |
plt.title('TSLA Salary Distribution (millions)', fontsize=15) | |
plt.xlabel('Salary', fontsize=12) | |
plt.ylabel('Frequency', fontsize=12) | |
plt.grid(True, linestyle='--', alpha=0.7) | |
plt.tight_layout() |
NewerOlder