-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_generation.py
61 lines (49 loc) · 1.86 KB
/
data_generation.py
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
61
import pandas as pd
import numpy as np
# Set random seed for reproductibility
np.random.seed(42)
# Number of samples
n_samples = 100000
# Generating random parameters for options
S = np.random.uniform(50, 150, n_samples) # Spot price between $50 and $150
K = np.random.uniform(50, 150, n_samples) # Strike price between $50 and $150
T = np.random.uniform(0.25, 2, n_samples) # Time to maturity between 3 months and 2 years
r = np.random.uniform(0.01, 0.072, n_samples) # risk free rate between 1% and 7.2%
# Introducing volatility skew:
# Options with lower strike prices will tend to have higher volatilities
sigma = np.random.uniform(0.1, 0.4, n_samples) + (K < S) * np.random.uniform(0.05, 0.15, n_samples)
# Creating a dataframe to store these values
options_df = pd.DataFrame(
{
'Spot_Price': S,
'Strike_Price': K,
'Time_to_Maturity': T,
'Risk_Free_Rate': r,
'Volatility': sigma
}
)
import pandas as pd
import numpy as np
# Set random seed for reproductibility
np.random.seed(42)
# Number of samples
n_samples = 100000
# Generating random parameters for options
S = np.random.uniform(50, 150, n_samples) # Spot price between $50 and $150
K = np.random.uniform(50, 150, n_samples) # Strike price between $50 and $150
T = np.random.uniform(0.25, 2, n_samples) # Time to maturity between 3 months and 2 years
r = np.random.uniform(0.01, 0.072, n_samples) # risk free rate between 1% and 7.2%
# Introducing volatility skew:
# Options with lower strike prices will tend to have higher volatilities
sigma = np.random.uniform(0.1, 0.4, n_samples) + (K < S) * np.random.uniform(0.05, 0.15, n_samples)
# Creating a dataframe to store these values
options_df = pd.DataFrame(
{
'Spot_Price': S,
'Strike_Price': K,
'Time_to_Maturity': T,
'Risk_Free_Rate': r,
'Volatility': sigma
}
)
print(options_df.head())