Last active
April 10, 2023 14:45
-
-
Save catslovedata/2d09d8042c4f3c3b786da2252b5fff57 to your computer and use it in GitHub Desktop.
This file contains 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 pandas as pd | |
import matplotlib.pyplot as plt | |
import matplotlib.font_manager as fm | |
from datetime import datetime, timedelta | |
# Set the seed for reproducibility | |
np.random.seed(300) | |
# Dates | |
start_date = datetime(2023, 1, 1) | |
end_date = datetime(2023, 1, 31) | |
num_days = (end_date - start_date).days + 1 | |
# Starting stock price | |
start_price = 100 | |
# Generate 31 random percentage changes in price | |
daily_changes = np.random.normal(0, 0.03, size=num_days+1) | |
high_values = np.random.normal(0, 0.5, size=num_days) | |
low_values = np.random.normal(0, 0.5, size=num_days) | |
# Calculate the daily prices | |
daily_prices = start_price * np.cumprod(1 + daily_changes) | |
open_prices = daily_prices[:-1] | |
close_prices = daily_prices[1:] | |
high_prices = np.maximum(open_prices, close_prices) + abs(high_values) | |
low_prices = np.minimum(open_prices, close_prices) - abs(low_values) | |
volume = np.random.normal(1000000, 500000, 31) | |
# Create a DataFrame to store the simulated data | |
data = pd.DataFrame({ | |
'Open': open_prices, | |
'High': high_prices, | |
'Low': low_prices, | |
'Close': close_prices, | |
'Volume': volume | |
}) | |
data["python_date"] = [start_date.date() + timedelta(days=x) for x in range(num_days)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment