Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Toy Monte Carlo Pricing | Portfolio and Pricing Toy-Simulations
Simulation and Monte Carlo Modeling with Python

bookToy Monte Carlo Pricing

Monte Carlo simulation is a powerful tool for estimating the value of financial instruments when analytic pricing formulas are unavailable or impractical. A classic example is the European call option, which gives the holder the right (but not the obligation) to buy an asset at a specified strike price on a fixed future date. By simulating many possible future asset prices and averaging their payoffs, you can estimate the fair price of such an option. This approach is especially useful when the underlying asset's price follows a stochastic process, such as geometric Brownian motion.

123456789101112131415161718192021222324
import numpy as np # Parameters for the simulation S0 = 100 # Initial asset price K = 105 # Strike price T = 1.0 # Time to maturity (in years) r = 0.05 # Risk-free interest rate sigma = 0.2 # Volatility of the asset n_sim = 10000 # Number of Monte Carlo simulations # Simulate final asset prices at maturity using geometric Brownian motion np.random.seed(42) # For reproducibility Z = np.random.randn(n_sim) ST = S0 * np.exp((r - 0.5 * sigma**2) * T + sigma * np.sqrt(T) * Z) # Calculate the payoff for each simulation (call option) payoffs = np.maximum(ST - K, 0) # Discount payoffs back to present value discounted_payoffs = np.exp(-r * T) * payoffs # Estimate the option price call_price = np.mean(discounted_payoffs) print(f"Estimated European call option price: {call_price:.2f}")
copy

The logic behind this Monte Carlo pricing model is straightforward. First, you generate a large number of possible future asset prices at the option's maturity using the geometric Brownian motion formula. For each simulated outcome, you calculate the payoff of the call option, which is the greater of zero or the difference between the final asset price and the strike price. These payoffs are then discounted to present value using the risk-free interest rate, reflecting the time value of money. By averaging all discounted payoffs across simulations, you obtain an estimate of the fair price for the call option. The accuracy of this estimate improves as you increase the number of simulations, leveraging the law of large numbers.

Taak

Swipe to start coding

You will implement a function that prices a European put option using a Monte Carlo simulation with geometric Brownian motion (GBM).

The option payoff at maturity is:

max(KST,0)\max(K - S_T, 0)

Your task:

  1. Accept the following arguments:

    • S0 — initial asset price
    • K — strike price
    • T — time to maturity
    • r — risk-free interest rate
    • sigma — volatility
    • n_sim — number of simulations
  2. Simulate final asset prices using GBM:

    ST=S0exp((r1.2σ2)T+σTZ)S_T = S_0 \exp\Big( (r - \tfrac{1}. {2}\sigma^2)T + \sigma\sqrt{T}Z \Big)

    where ZN(0,1)Z \sim N(0, 1).

  3. Compute the put payoff of each simulation.

  4. Discount payoffs to present value:

    Price=erTE[payoff]\text{Price} = e^{-rT} \cdot \mathbb{E}[\text{payoff}]
  5. Return the estimated option price as a float.

Use only numpy.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 3
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

close

bookToy Monte Carlo Pricing

Veeg om het menu te tonen

Monte Carlo simulation is a powerful tool for estimating the value of financial instruments when analytic pricing formulas are unavailable or impractical. A classic example is the European call option, which gives the holder the right (but not the obligation) to buy an asset at a specified strike price on a fixed future date. By simulating many possible future asset prices and averaging their payoffs, you can estimate the fair price of such an option. This approach is especially useful when the underlying asset's price follows a stochastic process, such as geometric Brownian motion.

123456789101112131415161718192021222324
import numpy as np # Parameters for the simulation S0 = 100 # Initial asset price K = 105 # Strike price T = 1.0 # Time to maturity (in years) r = 0.05 # Risk-free interest rate sigma = 0.2 # Volatility of the asset n_sim = 10000 # Number of Monte Carlo simulations # Simulate final asset prices at maturity using geometric Brownian motion np.random.seed(42) # For reproducibility Z = np.random.randn(n_sim) ST = S0 * np.exp((r - 0.5 * sigma**2) * T + sigma * np.sqrt(T) * Z) # Calculate the payoff for each simulation (call option) payoffs = np.maximum(ST - K, 0) # Discount payoffs back to present value discounted_payoffs = np.exp(-r * T) * payoffs # Estimate the option price call_price = np.mean(discounted_payoffs) print(f"Estimated European call option price: {call_price:.2f}")
copy

The logic behind this Monte Carlo pricing model is straightforward. First, you generate a large number of possible future asset prices at the option's maturity using the geometric Brownian motion formula. For each simulated outcome, you calculate the payoff of the call option, which is the greater of zero or the difference between the final asset price and the strike price. These payoffs are then discounted to present value using the risk-free interest rate, reflecting the time value of money. By averaging all discounted payoffs across simulations, you obtain an estimate of the fair price for the call option. The accuracy of this estimate improves as you increase the number of simulations, leveraging the law of large numbers.

Taak

Swipe to start coding

You will implement a function that prices a European put option using a Monte Carlo simulation with geometric Brownian motion (GBM).

The option payoff at maturity is:

max(KST,0)\max(K - S_T, 0)

Your task:

  1. Accept the following arguments:

    • S0 — initial asset price
    • K — strike price
    • T — time to maturity
    • r — risk-free interest rate
    • sigma — volatility
    • n_sim — number of simulations
  2. Simulate final asset prices using GBM:

    ST=S0exp((r1.2σ2)T+σTZ)S_T = S_0 \exp\Big( (r - \tfrac{1}. {2}\sigma^2)T + \sigma\sqrt{T}Z \Big)

    where ZN(0,1)Z \sim N(0, 1).

  3. Compute the put payoff of each simulation.

  4. Discount payoffs to present value:

    Price=erTE[payoff]\text{Price} = e^{-rT} \cdot \mathbb{E}[\text{payoff}]
  5. Return the estimated option price as a float.

Use only numpy.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 3
single

single

some-alt