Home

Was ist ein stochastischer Prozess? – Einfache und realistische Beispiele

Ein stochastischer Prozess (auch Zufallsvorgang genannt) ist eine Familie von Zufallsvariablen, die über die Zeit (oder andere Parameter wie Ort, Zustand) veränderbar sind.

Zusammenfassung:

Beispiel 1: Würfelwürfe – Ein einfacher stochastischer Prozess

Wir werfen einen sechsseitigen Würfel 100 mal und notieren das Ergebnis.

Das ist ein stochastischer Prozess, weil:

Denkt an eine Wetterprognose – jeder Tag hat eine zufällige Temperatur, die sich im Laufe der Zeit verändert.
import numpy as np
import matplotlib.pyplot as plt

n_steps = 100
np.random.seed(42)
rolls = np.random.randint(1, 7, size=n_steps)

plt.figure(figsize=(12, 6))
plt.plot(range(1, n_steps + 1), rolls, marker='o', linestyle='-', markersize=4, linewidth=1)
plt.title("Stochastischer Prozess: 100 Würfelwürfe ")
plt.xlabel("Anzahl")
plt.ylabel("Würfelwert (1–6)")
plt.grid(True, alpha=0.3)
plt.xticks(range(1, n_steps+1, 10))
plt.tight_layout()
plt.show()

Beispiel 2: Bakterienwachstum – Stochastischer Prozess in der Biologie

Ein Bakterienpopulation wächst nicht immer gleichmäßig. Es gibt zufällige Faktoren wie Stress oder Antibiotika.

Das Wachstum ist ein stochastischer Prozess:

Wie ein Immunsystem reagiert auf Zufallsfaktoren – man kann nicht genau sagen, wie stark die Reaktion ist.
import numpy as np
import matplotlib.pyplot as plt

v initial_population = 100
n_hours = 10
growth_factors = [0.9, 1.0, 1.1, 1.2]
probabilities = [0.2, 0.25, 0.35, 0.2]

np.random.seed(42)
growth_rates = np.random.choice(growth_factors, size=n_hours, p=probabilities)

population = [initial_population]
for i in range(n_hours):
growth_factor = growth_rates[i]
population.append(population[-1] * growth_factor)

plt.figure(figsize=(12, 6))
plt.plot(range(n_hours + 1), population, marker='o', linestyle='-', color='green', linewidth=2, markersize=6)
plt.title("Stochastischer Prozess: Bakterienpopulation über 10 Stunden")
plt.xlabel("Zeit (Stunden)")
plt.ylabel("Anzahl der Bakterien")
plt.grid(True, alpha=0.3)
plt.xticks(range(n_hours + 1))
plt.ylim(0, max(population) * 1.2)
plt.tight_layout()
plt.show()

print("Wachstumsfaktoren pro Stunde (1 = keine Änderung):")
for i, factor in enumerate(growth_rates):
print(f"Stunde {i+1}: {factor:.2f}x")


Beispiel 3: Aktienkurs – Stochastischer Prozess in der Finanzwirtschaft

Der Kurs einer Aktie (z. B. BMW-Aktie) ist nicht vorhersehbar.

Er schwankt aufgrund von:

Der Kurs ist ein stochastischer Prozess:

Wie ein Wetterbericht: Heute wird es 15°C sein – aber es gibt eine 30% Wahrscheinlichkeit, dass es plötzlich regnet.
import numpy as np
import matplotlib.pyplot as plt

initial_price = 100.0
n_days = 30
daily_change_range = [0.5, 1.0, 1.5]
probabilities = [0.3, 0.4, 0.3]

np.random.seed(42)
daily_changes = np.random.choice(daily_change_range, size=n_days, p=probabilities)

price = [initial_price]
for day in range(n_days):
change_percent = daily_changes[day]
new_price = price[-1] * (1 + change_percent / 100)
price.append(new_price)

plt.figure(figsize=(14, 6))
plt.plot(range(n_days + 1), price, marker='o', linestyle='-', color='blue', linewidth=2, markersize=6)
plt.title("Stochastischer Prozess: BMW-Aktienkurs über 30 Tage")
plt.xlabel("Tag")
plt.ylabel("Kurs (in Euro)")
plt.grid(True, alpha=0.3)
plt.xticks(range(0, n_days + 1, 5))
plt.ylim(80, 120)
plt.tight_layout()
plt.show()

print("Tägliche Änderungen (in %):")
for i, change in enumerate(daily_changes):
print(f"Tag {i+1}: {change:.1f}%")

Fortgeschrittenes Beispiel 1: Geometrische Brownian-Motion (GBM) – Realistisches Finanzmodell

GBM ist das Standardmodell in der Finanzmathematik für Aktienkurse.

Formel:

S(t) = S₀ ⋅ exp(μt + σW(t))

Der Kurs wächst exponentiell – das ist realistisch für Aktien!
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

S0 = 100.0
mu = 0.01
sigma = 0.02
n_days = 30
dt = 1 / 365.0

t = np.arange(0, n_days + 1) * dt
W = np.cumsum(np.random.normal(0, np.sqrt(dt), n_days))
S_t = S0 * np.exp(mu * t + sigma * W)

plt.figure(figsize=(14, 7))
plt.plot(t, S_t, marker='o', linestyle='-', color='red', linewidth=2, markersize=6, label="BMW-Aktienkurs (GBM)")
plt.axhline(y=100, color='gray', linestyle='--', alpha=0.7, label="Startkurs (100€)")
plt.title("Stochastischer Prozess: BMW-Aktienkurs über 30 Tage (Geometrische Brownian-Motion)")
plt.xlabel("Tag")
plt.ylabel("Kurs (in Euro)")
plt.grid(True, alpha=0.3)
plt.xticks(range(0, n_days + 1, 5))
plt.ylim(60, 140)
plt.legend()
plt.tight_layout()
plt.show()

avg_price = np.mean(S_t)
std_price = np.std(S_t)
print(f"Simulation Ergebnisse (30 Tage):")
print(f"Startkurs: {S0} €")
print(f"Durchschnittlicher Kurs: {avg_price:.2f} €")
print(f"Standardabweichung: {std_price:.2f} €")
print(f"Erwartete Wachstumsrate: {mu*100:.1f}% pro Tag")
print(f"Volatilität: {sigma*100:.1f}% pro Tag")

Fortgeschrittenes Beispiel 2: Markov-Kette – Wetter in Bayern und BMW-Produktion

Das Wetter beeinflusst die Produktion – ein klassisches Beispiel für eine Markov-Kette.

Zustände:

Übergangswahrscheinlichkeiten:

Vorheriger Zustand Sonne Regen
Sonne 80% 20%
Regen 30% 70%
Der nächste Zustand hängt nur vom vorherigen ab – die Markov-Eigenschaft!
import numpy as np
import matplotlib.pyplot as plt

transition_matrix = np.array([
[0.8, 0.2],
[0.3, 0.7]
])

states = ["Sonne", "Regen"]
initial_state = 0
days = 30

current_state = initial_state
weather = [current_state]

for day in range(1, days):
rand = np.random.rand()
if current_state == 0: # Sonne
if rand < 0.8:
next_state = 0
else:
next_state = 1
else: # Regen
if rand < 0.3:
next_state = 0
else:
next_state = 1
weather.append(next_state)
current_state = next_state

plt.figure(figsize=(14, 6))
plt.plot(range(days), weather, marker='o', linestyle='-', color='blue', linewidth=2, markersize=6)
plt.title("Stochastischer Prozess: Wetter in Bayern (Markov-Kette) über 30 Tage")
plt.xlabel("Tag")
plt.ylabel("Wetterbedingung")
plt.grid(True, alpha=0.3)
plt.xticks(range(0, days, 5))
plt.ylim(0, 1.5)
plt.tight_layout()
plt.show()

print("Übergangswahrscheinlichkeiten (Bayern-Wetter):")
print("Sonne → Sonne: 80%")
print("Sonne → Regen: 20%")
print("Regen → Sonne: 30%")
print("Regen → Regen: 70%")
print(f"Anzahl Regentage: {weather.count('Regen')} ({weather.count('Regen')/days*100:.1f} %)")

Fortgeschrittenes Beispiel 3: Markov-Prozess für den Ölmarkt

Ein komplexer, realitätsnaher stochastischer Prozess: Krieg im Iran + Blockade der Straße von Hormus → Ölpreis-Schwankungen.

Zustände:

Übergangswahrscheinlichkeiten:

Vorheriger Zustand Stabil Risiko Blockade
Stabil 70% 20% 10%
Risiko 30% 40% 30%
Blockade 10% 20% 70%
Der Ölpreis steigt mit zunehmendem Risiko – realistisch und wirtschaftlich relevant!
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

n_days = 100
initial_state = 0
prices = np.array([70.0, 80.0, 100.0])
states = ["Stabil", "Risiko", "Blockade"]

transition_matrix = np.array([
[0.7, 0.2, 0.1],
[0.3, 0.4, 0.3],
[0.1, 0.2, 0.7]
])

current_state = initial_state
state_history = [current_state]
price_history = [prices[current_state]]

for day in range(1, n_days):
rand = np.random.rand()
cumsum = 0
for i in range(3):
cumsum += transition_matrix[current_state][i]
if rand <= cumsum:
next_state = i
break
current_state = next_state
state_history.append(current_state)
price_history.append(prices[current_state])

fig, ax1 = plt.subplots(figsize=(14, 8))

ax1.plot(range(n_days), price_history, marker='o', linestyle='-', color='red', linewidth=2, markersize=6, label="Ölpreis (USD/barrel)")
ax1.set_title("Stochastischer Prozess: Ölpreis aufgrund Krieg im Iran und Blockade der Straße von Hormus")
ax1.set_xlabel("Tag")
ax1.set_ylabel("Ölpreis (USD/barrel)")
ax1.grid(True, alpha=0.3)
ax1.xticks(range(0, n_days, 10))
ax1.axhline(y=70, color='gray', linestyle='--', alpha=0.7, label="Stabil (70€)")
ax1.axhline(y=80, color='orange', linestyle='--', alpha=0.7, label="Risiko (80€)")
ax1.axhline(y=100, color='darkblue', linestyle='--', alpha=0.7, label="Blockade (100€)")
ax1.legend()
ax1.set_ylim(60, 110)

plt.figtext(0.02, 0.02,
f"Übergangswahrscheinlichkeiten:\n" f"Stabil Stabil: 70% | Risiko: 20% | Blockade: 10%\n"
f"Risiko Stabil: 30% | Risiko: 40% | Blockade: 30%\n"
f"Blockade Stabil: 10% | Risiko: 20% | Blockade: 70%",
fontsize=10, bbox=dict(boxstyle="round", facecolor="lightgray", alpha=0.8))

plt.tight_layout()
plt.show()

print("=" * 60)
print(" SIMULIERTE ÖLPREIS-ENTWICKLUNG (100 Tage)")
print("=" * 60)
print(f"Startzustand: {states[initial_state]} (Preis: {prices[initial_state]:.1f} €)")
print(f"Anzahl Tage mit Stabil: {state_history.count(0)} ({state_history.count(0)/n_days*100:.1f}%)")
print(f"Anzahl Tage mit Risiko: {state_history.count(1)} ({state_history.count(1)/n_days*100:.1f}%)")
print(f"Anzahl Tage mit Blockade: {state_history.count(2)} ({state_history.count(2)/n_days*100:.1f}%)")
print(f"Maximaler Ölpreis: {max(price_history):.1f} €")
print(f"Minimale Ölpreis: {min(price_history):.1f} €")
print(f"Durchschnittlicher Ölpreis: {np.mean(price_history):.1f} €")

Zusammenfassung: Eigenschaften eines stochastischen Prozesses

Eigenschaft Erklärung
Zufälligkeit Keine exakte Vorhersage möglich – nur Wahrscheinlichkeiten.
Zeitabhängigkeit Der Zustand ändert sich mit der Zeit.
Statistische Beschreibung Wir können durchschnittliche Werte oder Übergangswahrscheinlichkeiten angeben.
Reproduzierbarkeit Mit np.random.seed() kann jeder Prozess exakt wiederholt werden.
Fazit: Ein stochastischer Prozess ist kein exaktes Modell. Es ist ein Werkzeug der Realität – es berücksichtigt Zufall und Zeit. In Biologie, Finanzwirtschaft und internationalen Märkten helfen solche Modelle, Risiken zu bewerten, Entscheidungen zu treffen und Muster zu erkennen.