Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære 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.

Oppgave

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.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 3
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you explain what geometric Brownian motion is?

How does changing the volatility or interest rate affect the option price?

Can you show how to estimate the price of a European put option using Monte Carlo simulation?

close

bookToy Monte Carlo Pricing

Sveip for å vise menyen

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.

Oppgave

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.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 3
single

single

some-alt