Team Ai
Modelpublic

ParallelLLC/algorithmic_trading

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
27likes36downloads
generate_sample_data.py45 linesDownload Raw Back to root
1import pandas as pd2import numpy as np3from datetime import datetime, timedelta4 5# Generate more realistic sample data6start_date = datetime(2024, 7, 1, 9, 30)7dates = [start_date + timedelta(minutes=i) for i in range(1000)]  # 1000 data points8 9# Generate realistic price movements10np.random.seed(42)11base_price = 150.012prices = []13for i in range(1000):14    if i == 0:15        price = base_price16    else:17        # Add some trend and volatility18        change = np.random.normal(0, 0.5) + (0.001 * i)  # Small upward trend19        price = prices[-1] + change20    prices.append(max(price, 1))  # Ensure price doesn't go negative21 22# Create OHLCV data23data = []24for i, (date, price) in enumerate(zip(dates, prices)):25    # Generate realistic OHLC from base price26    volatility = 0.0227    high = price * (1 + np.random.uniform(0, volatility))28    low = price * (1 - np.random.uniform(0, volatility))29    open_price = price * (1 + np.random.uniform(-volatility/2, volatility/2))30    close_price = price * (1 + np.random.uniform(-volatility/2, volatility/2))31    volume = int(np.random.uniform(5000, 50000))32    33    data.append({34        'timestamp': date,35        'open': round(open_price, 2),36        'high': round(high, 2),37        'low': round(low, 2),38        'close': round(close_price, 2),39        'volume': volume40    })41 42df = pd.DataFrame(data)43df.to_csv('data/market_data.csv', index=False)44print(f'Generated {len(df)} realistic data points from {df.timestamp.min()} to {df.timestamp.max()}')45print(f'Price range: ${df.close.min():.2f} - ${df.close.max():.2f}')