import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
# Set random seed for reproducibility
np.random.seed(2025)
def generate_techmart_sales_history():
"""
Generate 3 years of sales history for 30 electronics SKUs.
"""
# Define 30 SKUs across 5 categories with category-specific trends
# Trend: annual growth/decline rate (e.g., 0.05 = 5% growth per year)
categories = {
'Smartphones': {'count': 8, 'trend': -0.15}, # Mature market, slight decline
'Laptops': {'count': 6, 'trend': 0.11}, # Stable with slight growth
'Headphones': {'count': 6, 'trend': 0.18}, # Growing premium audio market
'Smartwatches': {'count': 5, 'trend': 0.22}, # Emerging category, strong growth
'Tablets': {'count': 5, 'trend': -0.15} # Declining market
}
skus = []
sku_id = 1
for category, cat_info in categories.items():
count = cat_info['count']
category_trend = cat_info['trend']
for i in range(count):
# Each product has unique characteristics
if category == 'Smartphones':
base_demand = np.random.uniform(100, 410)
elif category == 'Laptops':
base_demand = np.random.uniform(90, 220)
elif category == 'Headphones':
base_demand = np.random.uniform(20, 210)
elif category == 'Smartwatches':
base_demand = np.random.uniform(20, 140)
elif category == 'Tablets':
base_demand = np.random.uniform(80, 170)
# Seasonal strength: how much seasonality affects this product (0.1-0.3)
seasonal_strength = np.random.uniform(0.1, 0.3)
# Noise level: product-specific volatility (std: 0.08-0.20)
noise_std = np.random.uniform(0.03, 0.25)
# Black Friday boost: product-specific multiplier (1.1-1.5)
bf_multiplier = np.random.uniform(1.1, 1.5)
skus.append({
'sku_id': f'SKU-{sku_id:03d}',
'category': category,
'base_demand': base_demand,
'seasonal_strength': seasonal_strength,
'noise_std': noise_std,
'bf_multiplier': bf_multiplier,
'category_trend': category_trend,
'price': np.random.uniform(30, 1200)
})
sku_id += 1
skus_df = pd.DataFrame(skus)
# Generate weekly sales from 2023-01-01 to 2025-11-15 (almost 3 years)
start_date = datetime(2023, 1, 1)
end_date = datetime(2025, 11, 15)
weeks = pd.date_range(start_date, end_date, freq='W')
sales_data = []
for _, sku in skus_df.iterrows():
for week_start in weeks:
week_num = week_start.isocalendar()[1]
year = week_start.year
month = week_start.month
# Base demand (unique per product)
demand = sku['base_demand']
# Component 1: Category-specific trend (small, linear over time)
# Calculate years elapsed from start date (2023-01-01)
years_elapsed = (week_start - start_date).days / 365.25
trend_multiplier = 1.0 + (sku['category_trend'] * years_elapsed)
demand *= trend_multiplier
# Component 2: Annual cycle (52 weeks) - peak in Nov/Dec (Q4), trough in summer (Q3)
annual_seasonality = 1.0 + sku['seasonal_strength'] * np.cos(2 * np.pi * (week_num - 47) / 52)
# Component 3: Quarterly cycle (13 weeks) - shorter-term fluctuations
quarterly_seasonality = 1.0 + (sku['seasonal_strength'] * 0.5) * np.sin(2 * np.pi * week_num / 13)
demand *= annual_seasonality * quarterly_seasonality
# Black Friday boost (product-specific multiplier)
if week_num in [47, 48]:
demand *= sku['bf_multiplier']
# Add normally distributed random noise (product-specific volatility)
noise = np.random.normal(1.0, sku['noise_std'])
demand *= max(0.5, min(1.5, noise)) # Clip to reasonable range
# Round to integer
demand = max(0, int(demand))
sales_data.append({
'sku_id': sku['sku_id'],
'week_start': week_start,
'year': year,
'week': week_num,
'month': month,
'units_sold': demand
})
sales_df = pd.DataFrame(sales_data)
return skus_df, sales_df
# Generate data
skus_df, sales_df = generate_techmart_sales_history()
print("TECHMART ELECTRONICS - SKU CATALOG")
print("=" * 120)
print(skus_df.to_string(index=False))
print("\n" + "=" * 120)
print(f"Total SKUs: {len(skus_df)}")
print("\nBy category:")
for category in skus_df['category'].unique():
count = len(skus_df[skus_df['category'] == category])
print(f" {category}: {count} SKUs")TECHMART ELECTRONICS - SKU CATALOG
========================================================================================================================
sku_id category base_demand seasonal_strength noise_std bf_multiplier category_trend price
SKU-001 Smartphones 142.001331 0.277570 0.235173 1.278227 -0.15 484.235589
SKU-002 Smartphones 179.854895 0.231474 0.138376 1.485695 -0.15 967.151836
SKU-003 Smartphones 241.113638 0.260212 0.039178 1.407783 -0.15 33.710207
SKU-004 Smartphones 190.770912 0.222183 0.230866 1.220046 -0.15 320.860405
SKU-005 Smartphones 306.581553 0.297507 0.133019 1.149315 -0.15 1101.756722
SKU-006 Smartphones 393.304495 0.155539 0.144324 1.161898 -0.15 47.114003
SKU-007 Smartphones 200.515394 0.298180 0.142891 1.450598 -0.15 108.853024
SKU-008 Smartphones 188.087659 0.193780 0.197590 1.469045 -0.15 489.837796
SKU-009 Laptops 210.781398 0.199922 0.206451 1.458632 0.11 594.091018
SKU-010 Laptops 200.230887 0.155336 0.104850 1.142030 0.11 642.082831
SKU-011 Laptops 174.306043 0.279922 0.052851 1.224698 0.11 121.380883
SKU-012 Laptops 211.923125 0.291817 0.072073 1.481608 0.11 549.536481
SKU-013 Laptops 124.245171 0.233980 0.112779 1.494186 0.11 810.475763
SKU-014 Laptops 218.890762 0.294713 0.069920 1.276549 0.11 817.168259
SKU-015 Headphones 144.177841 0.176608 0.177231 1.387934 0.18 946.536415
SKU-016 Headphones 80.986683 0.119412 0.213572 1.110089 0.18 309.358839
SKU-017 Headphones 182.850584 0.110092 0.072704 1.290362 0.18 305.164876
SKU-018 Headphones 88.229309 0.129033 0.059840 1.139115 0.18 207.471104
SKU-019 Headphones 47.458748 0.105895 0.190427 1.370478 0.18 548.940060
SKU-020 Headphones 43.726319 0.135155 0.164134 1.208759 0.18 863.933878
SKU-021 Smartwatches 63.921751 0.155961 0.223931 1.166687 0.22 147.990342
SKU-022 Smartwatches 136.894623 0.291290 0.057567 1.152603 0.22 428.359589
SKU-023 Smartwatches 80.065334 0.269516 0.155000 1.186574 0.22 757.086860
SKU-024 Smartwatches 66.345697 0.176956 0.071607 1.482957 0.22 174.054069
SKU-025 Smartwatches 30.384036 0.220347 0.161101 1.150430 0.22 749.579075
SKU-026 Tablets 109.464296 0.169059 0.104956 1.148955 -0.15 1140.611174
SKU-027 Tablets 111.850145 0.198087 0.043744 1.295709 -0.15 439.401212
SKU-028 Tablets 166.496499 0.152798 0.191875 1.299498 -0.15 1114.312833
SKU-029 Tablets 140.870051 0.114547 0.087424 1.174714 -0.15 783.925103
SKU-030 Tablets 85.573274 0.168057 0.138067 1.413962 -0.15 71.210130
========================================================================================================================
Total SKUs: 30
By category:
Smartphones: 8 SKUs
Laptops: 6 SKUs
Headphones: 6 SKUs
Smartwatches: 5 SKUs
Tablets: 5 SKUs
