<jupyter_start><jupyter_text>- Prove the following facts: Supose $f$ is a function satisfying  - $f(0) = f_{min},$ and $\lim_{x\to \infty}f(x) =  f_{max}$  - $f$ is continuous  - $f$ is strictly increasing    then, for any $p\in  (f_{min}, f_{max})$,   - there exists unique $\hat \sigma$, such that $f(\hat \sigma) = p$ and    $$\hat \sigma = \arg\min_{\sigma\in (0,\infty)} | f(\sigma) - p|.$$__Pf:__By Intermediate Value Theorem, there exists $\hat \sigma$, such that $f(\hat \sigma) = p$, since $f$ is continuous and $p\in  (f_{min}, f_{max})$.Assuming that there exists $\hat \sigma' \ne \hat \sigma$, such that $f(\hat \sigma') = p$, then we must have $$\hat \sigma' < \hat \sigma$$ or $$\hat \sigma' > \hat \sigma.$$Without loss of generality, assuming that $\hat \sigma' < \hat \sigma$. Because $f$ is strictly increasing, we have $$p = f(\hat \sigma') > f(\hat \sigma) = p,$$which contradicts the assumption above.Therefore, there exists unique $\hat \sigma$, such that $f(\hat \sigma) = p.$Plus, since $| f(\sigma) - p| \ge 0$, we have $$\min_{\sigma\in (0,\infty)} | f(\sigma) - p| \ge 0,$$Because $\hat \sigma$ is the unique point which satisfies  $$f(\hat \sigma) - p = 0 ,$$we can conclude that$$\hat \sigma = \arg\min_{\sigma\in (0,\infty)} | f(\sigma) - p|.$$__Q.E.D__ - Now we denote by $f(\sigma)$ the BSM put price with the following parameters:  - vol_ratio = $\sigma$; spot_price = 100.; drift_ratio = .0475; strike = 110.; maturity = 1.    Answer the following questions:  - What is $f_{min}$ and $f_{max}$?  - Is $f$ strictly increasing on $(0,\infty)$? Justify your answer.  - If the market put price is $10$, then what's the implied volatility?__Soln:__The put price with maturity $T$ and $K$ will be known as $P_0$ given as below:$$P_0 = \mathbb E [e^{-rT} (S(T) - K)^-] = K e^{-rT} \Phi(- d_2) - S_0  \Phi(- d_1),$$where $d_i$ are given as$$d_1 = \frac{(r + \frac 1 2 \sigma^2) T - \ln \frac{K}{S_0}}{\sigma \sqrt T},$$and$$d_2 = \frac{(r - \frac 1 2 \sigma^2) T - \ln \frac{K}{S_0}}{\sigma \sqrt T} = d_1 - \sigma \sqrt T$$- $f_{min} = f(0) = 4.8972$ , $f_{max} = \lim_{x\to \infty}f(x) = 104.8972$- $f$ is strictly increasing on $(0,\infty)$, which has been proved in Hw_3/2.- The implied volatility $\hat \sigma = 0.1787$. The main code is shown as follows. ____<jupyter_code>from scipy.optimize import fsolve

def f(x):
  gbm1 = Gbm(vol_ratio = x)
  option1 = VanillaOption(otype=-1)
  return(gbm1.bsm_price(option1)-10)

ans_sig = fsolve(f,0.1)
print(ans_sig)<jupyter_output><empty_output><jupyter_text>- Find its implied volatility with the following parameters:  - BSM call price is 10.;  spot_price = 100.; drift_ratio = .0475; strike = 110.; maturity = 1.<jupyter_code>import numpy as np
import scipy.stats as ss

class VanillaOption:
    def __init__(
        self,
        otype = 1, # 1: 'call'
                  # -1: 'put'
        strike = 110.,
        maturity = 1.,
        market_price = 10.):
      self.otype = otype
      self.strike = strike
      self.maturity = maturity
      self.market_price = market_price #this will be used for calibration
      
        
    def payoff(self, s): #s: excercise price
      otype = self.otype
      k = self.strike
      maturity = self.maturity
      return max([0, (s - k)*otype])

class Gbm:
    def __init__(self,
                 init_state = 100.,
                 drift_ratio = .0475,
                 vol_ratio = .2
                ):
        self.init_state = init_state
        self.drift_ratio = drift_ratio
        self.vol_ratio = vol_ratio

def bsm_price(self, vanilla_option):
    s0 = self.init_state
    sigma = self.vol_ratio
    r = self.drift_ratio
    
    otype = vanilla_option.otype
    k = vanilla_option.strike
    maturity = vanilla_option.maturity
    
    d1 = (np.log(s0 / k) + (r + 0.5 * sigma ** 2) 
          * maturity) / (sigma * np.sqrt(maturity))
    d2 = d1 - sigma * np.sqrt(maturity)
    
    return (otype * s0 * ss.norm.cdf(otype * d1) #line break needs parenthesis
            - otype * np.exp(-r * maturity) * k * ss.norm.cdf(otype * d2))

Gbm.bsm_price = bsm_price
from scipy.optimize import fsolve

def f(x):
  gbm2 = Gbm(vol_ratio = x)
  option2 = VanillaOption(otype=1)
  return(gbm2.bsm_price(option2)-10)

ans_sig_2 = fsolve(f,0.1)
print('>>> The implied volatility is ' + str(ans_sig_2))<jupyter_output>>>> The implied volatility is [0.30199229]
StarcoderdataJupyterStructuredCleanDedup