Monte-Carlo-Sim// Mit den Ergebnissen neues Array erstellen!
Verfasst: Montag 28. September 2020, 13:08
Ich kann damit einen Call mit der Monte-Carlo-Simulation simulieren:
import math
from numpy import *
from time import time
# star import for shorter code
random.seed(20000)
t0 = time()
# Parameters
S0 = 100.; K = 105.; T = 1.0; r = 0.05; sigma = 0.2
M = 252; dt = T / M; I = 1
# Simulating I paths with M time steps
S = S0 * exp(cumsum((r - 0.5 * sigma ** 2) * dt + sigma * math.sqrt(dt) * random.standard_normal((M + 1, I)), axis=0))
# sum instead of cumsum would also do
# if only the final values are of interest
S[0] = S0
# Calculating the Monte Carlo estimator
C0 = math.exp(-r * T) * sum(maximum(S[-1] - K, 0)) / I
# Results output
tnp2 = time() - t0
Die Formel für einen Put kann man so formulieren: P0 = C0 +K*exp(-r*T)-S0.
Kann mit jemand helfen das P0 mit in die Simulation zu ziehen, somit ich mit einer Simulation beides Simuliere.
Weiter wäre meine Frage, dass ich ein Ergebnis als Array S bekomme mit den Werten der Simulation zum Beispiel (253,100).
Ich muss dann im nächsten Schritt ein neues Array erstellen in dem alle Ergebnisse von S (ich schreibe es mit Index mal S_i) in diese Formel packe:
S_i+1 = S0 * explodiert((S_i -S0) / S0) , brauche das Ergebnis wie Bei S dann als (253,100) Array.
import math
from numpy import *
from time import time
# star import for shorter code
random.seed(20000)
t0 = time()
# Parameters
S0 = 100.; K = 105.; T = 1.0; r = 0.05; sigma = 0.2
M = 252; dt = T / M; I = 1
# Simulating I paths with M time steps
S = S0 * exp(cumsum((r - 0.5 * sigma ** 2) * dt + sigma * math.sqrt(dt) * random.standard_normal((M + 1, I)), axis=0))
# sum instead of cumsum would also do
# if only the final values are of interest
S[0] = S0
# Calculating the Monte Carlo estimator
C0 = math.exp(-r * T) * sum(maximum(S[-1] - K, 0)) / I
# Results output
tnp2 = time() - t0
Die Formel für einen Put kann man so formulieren: P0 = C0 +K*exp(-r*T)-S0.
Kann mit jemand helfen das P0 mit in die Simulation zu ziehen, somit ich mit einer Simulation beides Simuliere.
Weiter wäre meine Frage, dass ich ein Ergebnis als Array S bekomme mit den Werten der Simulation zum Beispiel (253,100).
Ich muss dann im nächsten Schritt ein neues Array erstellen in dem alle Ergebnisse von S (ich schreibe es mit Index mal S_i) in diese Formel packe:
S_i+1 = S0 * explodiert((S_i -S0) / S0) , brauche das Ergebnis wie Bei S dann als (253,100) Array.