assignment1-checkpoint
Assignment 1¶
Submission should be in a Jupyter note book (.ipynb)
Copyright By PowCoder代写 加微信 powcoder
Implement a function that converts a fixed
def fromFixedPoint(w: int, b:int, bits:[int]) -> float:
# w: width of the binary representation
# b: binary point
Test the following inputs
fromFixedPoint(10, 3, [0, 1, 0, 1, 1, 0, 0, 1, 1, 0])
fromFixedPoint(10, 5, [1, 0, 0, 1, 0, 1, 0, 1, 1, 1])
fromFixedPoint(8, 2, [1, 0, 1, 0, 1, 0, 1, 1])
def fromFixedPoint(w: int, b:int, bits:[int]) -> float:
Calculate the price of the following questions step by step using two step Cox Rox Rubinstein (CRR) Binomial tree
a. European call option with $S = 100$, $K = 105$, $r = 3%$, $T=1$, $\sigma = 20%$
b. European put option with $S = 100$, $K = 105$, $r = 3%$, $T=1$, $\sigma = 20%$
c. European call option with $S = 100$, $K = 105$, $r = 3%$, $T=1$, $\sigma = 10%$
d. European put option with $S = 100$, $K = 105$, $r = 3%$, $T=1$, $\sigma = 10%$
What is the value of the portfolio that is long (a) and short (b)? How about the portfolio that long (c) and short (d)?
import math
from enum import Enum
class PayoffType(str, Enum):
def crrTwoStepBinomial(S, r, vol, optType, K, T):
print(a,b,c,d)
print(a-b)
print(c-d)
7.334893644625006 9.231674667218366 3.555283800757024 5.452064823350393
-1.89678102259336
-1.8967810225933692
Greeks measure the sensitivity of the price of derivatives to a change in underlying asset’s parameters. They are used for hedging and risk
management. The commonly used greeks are:
Delta $\Delta = \frac{\partial V}{\partial S}$: measures the rate of change of the option value with respect to changes in the underlying asset’s price.
Gamma $\Gamma = \frac{\partial^2 V}{\partial S^2} = \frac{\partial \Delta}{\partial S}$: measures the rate of change of delta with respect to changes in the underlying asset’s price.
Vega: $v = \frac{\partial V}{\partial \sigma}$: measures the rate of change of the option value with respect to changes in the underlying asset’s volatility.
Theta: $\theta = \frac{\partial V}{\partial t}$: the rate of change in the price of an option with respect to pricing time. Note that we normally use $t$ to represent pricing time, $T$ to represent expiry time, time to expiry in our pricer is $T-t$. In the implementation of the pricers that take time to expiry as an argument, we implicitly set pricing time to 0 (present).
Rho (PV01): the rate of change in the price of an option in response to a change in the interest rate.
The greeks are normally not known in closed form since numerical pricers are used. They are approximated by finite differences:
\begin{align}
& \Delta = \frac{\partial V}{\partial S} \approx \frac{V(S + \Delta S) – V(S-\Delta S)}{2 \Delta S}, ~~~\Delta S = 0.1\% S \\
& \Gamma = \frac{\partial V^2}{\partial S^2} \approx \frac{V(S + \Delta S) – 2V(S) + V(S-\Delta S)}{\Delta S^2} \\
& v = \frac{\partial V}{\partial \sigma} \approx \frac{V(S, \sigma +\Delta \sigma) – V(S, \sigma -\Delta \sigma)}{2 \Delta \sigma } ~~~~~~~\Delta \sigma = 0.1\% \\
& \theta = \frac{\partial V}{\partial t} \approx \frac{V(S, t+\Delta t, T) – V(S, t, T)}{\Delta t} ~~~~\Delta t = 0.004 \\
& \text{PV01} = \frac{\partial V}{\partial r} \approx \frac{V(S, r+\Delta r) – V(S, r – \Delta r)}{2 \Delta r} ~~~~~\Delta r = 0.0001
\end{align}
Implement a Greeks calculater for binomial tree pricer provided below. The signature of the greeks calculator is
def binomialGreeks(S, r, vol, T, strike, greekType) -> float
Setting $S = 100, r = 0.03, vol = 0.2, t = 0, T = 1$, plot each greeks as a function of strike from 50 to 150. Play with different binomial models and see if there is any difference.
Note that in practice, the greeks are rescaled with a pre-defined scaler, so that they give a sense of how much PV (Delta) changes with a typical move of the market. The rescaling is not incorporated in this exercise.
# binomial pricer for exercise 3
class EuropeanOption():
class AmericanOption():
def crrCalib(r, vol, t):
def jrrnCalib(r, vol, t):
def jreqCalib(r, vol, t):
def tianCalib(r, vol, t):
def binomialPricer(S, r, vol, trade, n, calib):
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com