# Expectation

# Variance and Covariance

# Correlation

Skip to content
# Category: Knowledge

## Statistics Basics

# Expectation

# Variance and Covariance

# Correlation

## Volatility Surface

# Vol Surface: Term Structure

# Vol Surface: Vol Skew (Risk Reversal)

# Vol Surface: Vol Fly (Butterfly)

# Vol Surface Arbitrage

# Vol Surface Interpolation

## Option Greeks

# European Vanilla Option Greeks

## Delta

### Interpretations

### Delta used on Vol Smile

### Adapted Delta

### Spot Delta vs Forward Delta

### Impact of Spot

### Impact of Time to expiry

### Impact of Vol

## Gamma

### Impact of Time to expiry

### Impact of Vol

### Gamma Trading

## Theta

### Impact of Time to expiry

### Impact of Vol

## Vega

### Impact of Time to expiry

### Impact of Vol

# Continuous Barrier Option Greeks

## Delta

### Impact of Spot

## American Vanilla Option Pricing – Binomial Tree Method

## European Vanilla Option Pricing – Black-Scholes PDE

## Monte Carlo Methods

### Why

#### Simulation / Compute function expectation

#### Compute function integral

#### Important in Exotics pricing as there’s no analytical solutions (e.g. Asian Options)

### Convergence Rate

### Variance Reduction

#### Increase number of simulations

#### Importance Sampling

#### Quasi Monte Carlo (QMC)

##### Low-discrepancy Sequence

###### Halton Sequence

###### Sobol Sequence

###### Faure Sequence

## 由最近市场波动引发的关于对冲(Hedging)的几点思考

### 对冲一定要考虑到现有的position

### 并不是一定要对冲

### Perfect hedging

### 有自己view的对冲

### 对冲风险选择的时间很重要

### Short option一定要非常谨慎

## European Vanilla Option Pricing – Monte Carlo Methods

## 用Python计算分析实现波动率和隐含波动率

### 计算股票的实现波动率

### 计算给定期权的隐含波动率

Term Structure usually refers to ATM implied vols by Time to maturity. And of course, these vols are all annualised vols for consistency.

Term Structure is usually upward sloping. But front-end vols are more sensitive to changes of realised vols and anticipated events (e.g. French election etc.). So market turmoil could lead to Term Structure inversion.

The Term Structure shape tend to be mean-reverting in nature. Trading strategies exploiting this mean-reverting feature involves buying and selling two options in Vega-neutral amounts, so that we have exposure to only the vols curve shape, not the level shift. This is similar to Duration-neutral Yield curve trades in Fixed Income.

Front-end vols are primarily Gamma plays, so views on Gamma is essential to formulating Term Structure. ?

Back-end vols are usually considered as sum of Front-end vols and vols curve. ?

By FX market convention, Risk Reversal is quoted as

Risk Reversal represents **directional** variation of implied vol with Strike. This corresponds to the **Third Standardised Central Moment** of underlying spot distribution.

For reference, the n-th moment of Probability Density Function about value is defined as:

Risk Reversal is well correlated to the **correlation between spot and vol moves. **We can think of Risk Reversal as the **implied skew** while spot-vol correlation as **realised skew**. And this means:

**Positive skew**: Option market expects spot rallies to be more volatile than sell-offs. E.g. USD/EM pairs. The option-implied spot distribution is tilted to the right.

**Negative skew**: Option market expects spot sell-offs to be more volatile than rallies. E.g. JPY cross pairs. The option-implied spot distribution is tilted to the left.

Skews are also often to be valued by comparing to ATM vols, i.e. ratio.

By FX market convention, Butterfly is quoted as

Butterfly represents **undirectional** variation of implied vol with Strike or **convexity** of vol curve / smile. This corresponds to the **Fourth Standardised Central Moment** of underlying spot distribution.

We can think of Butterfly as the dimension of vol curve / smile that richens “wings” or low-delta options compared to ATM options. So non-Zero Butterfly means underlying spot distribution deviates from log normality assumed by Black-Scholes, and wing / low-delta vols are priced at premium to ATM vol.

Butterfly is well correlated with **volatility of ATM vol**. Thus, it is often considered as the parameter capturing **vol-of-vol**.

- Option price sensitivity to spot (Spot Delta)

gradient of option price tangent line

- Proxy for Probability of option finishing ITM.

Delta value is between 0 and 1. But this is just a proxy for exercising probability for interpretation purpose.

In fact, the risk neutral Probability Density Function (PDF) is the 2nd derivative of call price with respect to Strike, i.e.

- Hedge ratio

Conventionally in FX Option space, the x-axis of Vol Smile plot is denoted as Delta (10d, 25d) instead of strikes.

Adapted Delta is the “real delta”, i.e. the actual hedge ratio, taking into account the shape of the vol smile.

Black-Scholes assumes constant vol.

We normally refers Delta as Spot Delta, i.e. spot sensitivity .

Forward Delta is the sensitivity to Forward price, i.e. which captures interest rate risk implicit in forward points.

Forward Delta is typically used for NDF currencies and long-dated options.

As we see from the below plot, as time passes, the option price curve moves closer to the At-Expiry payoff. Therefore, ITM Delta moves closer to 1 and OTM Delta moves closer to 0. ATM Delta has greater uncertainty (high Gamma) near expiry.

For ITM options, higher vol means less certainty that it will finish ITM, i.e. smaller Delta.

For OTM options, higher vol means higher probability that it will finish ITM, i.e. higher Delta.

A doubling of vol has roughly the same effect on an option’s Delta (and its price) as a quadrupling of time. For example,

A doubling of vol has roughly the same effect on an option’s Gamma as a quadrupling of time. For example,

If we long an Option with Delta hedged, we will have positive P/L from long Gamma.

However, this Gamma P/L comes at cost of Theta decay as we are long option.

Theta measures the Option value decay as time passes. We say Theta is positive, meaning, as time passes (time to expiry decreases), Option price also decreases.

But can European Put Option Theta be negative?

**Reversed Knock-Out (RKO)**: Up and Out Call with Barrier > Strike ** OR** Down and Out Put with Barrier < Strike

**Reversed Knock-In (RKI):** Up and In Call with Barrier > Strike ** OR** Down and In Put with Barrier < Strike

**Reversed** means the Barrier level is In-The-Money (ITM).

RKO Call / Put + RKI Call / Put = Vanilla Call / Put

This is true for option price and all greeks.

Delta is the gradient of curve. We notice there’s a Delta gap on barrier trigger, for both RKI and RKO.

RKI Call Option

RKO Call Option

We first divide the American Call option tenor into smaller time steps, each represented as .

In each time step, assume underlying asset price may move from initial value either up to with real-world probability or down to with .

We assume the annualised risk free rate is .

At the end of this time step , the payoff of the American Call option is

We then construct a portfolio with shares of underlying asset and amount of cash invested at risk free rate. The initial portfolio cost is , the portfolio value at end of the time step is or depending on underlying.

And we can carefully choose below and so that this portfolio replicates the payoff of American Call option at end of this time step.

With no arbitrage, the value of the American Call option has to be equal to the portfolio initial cost at beginning of the time step. So we have:

with

So we notice that the real-world probability q is NOT in the formula, which means the American Call option prices does not depend on investors’ individual risk preference.

We also notice is between 0 and 1, and therefore be regarded as the risk neutral probability. And the American Call option price is just the discounted value of future expected payoffs.

In the risk neutral world, is the probability that underlying asset price goes up to , and is the probability it goes down to . And the current underlying price is just the discounted value of future expected payoffs, i.e.

which can be simplified as:

From our assumption, we know the underlying asset price return over one time step follows Binomial distribution, thus the one-step variance of price return is .

Cox introduced another condition:

Now, from the above 3 equations, we can solve for for given as below:

So now we can use above Binomial Tree model to calculate the American Call option price step by step backward from expiry. At each step, we need to evaluate the discounted future expected payoffs and the payoff if we exercise at this step. We take the bigger value of the two as the value for this time step node.

Python code:

def binomialTree(callPut, spot, strike, rate, sigma, tenor, N=2000, american=True): # Each time step period deltaT = float(tenor) / N u = np.exp(sigma * np.sqrt(deltaT)) d = 1.0 / u a = np.exp(rate * deltaT) p = (a - d) / (u - d) oneMinusP = 1.0 - p # Initialize the arrays fs = np.asarray([0.0 for i in xrange(N + 1)]) # Stock tree for calculations of expiration values fs2 = np.asarray([(spot * u ** j * d ** (N - j)) for j in xrange(N + 1)]) # Vectorize the strikes to speed up expiration check fs3 = np.asarray([float(strike) for i in xrange(N + 1)]) # Compute the Binomial Tree leaves, f_{N, j} if callPut == 'Call': fs[:] = np.maximum(fs2 - fs3, 0.0) else: fs[:] = np.maximum(-fs2 + fs3, 0.0) # Calculate backward the option prices for i in xrange(N - 1, -1, -1): fs[:-1] = np.exp(-rate * deltaT) * (p * fs[1:] + oneMinusP * fs[:-1]) fs2[:] = fs2[:] * u if american: # Simply check if the option is worth more alive or dead if callPut == 'Call': fs[:] = np.maximum(fs[:], fs2[:] - fs3[:]) else: fs[:] = np.maximum(fs[:], -fs2[:] + fs3[:]) return fs[0]

Assume underlying spot follows Geometric Brownian Motion, i.e.

Let be the call option price. We obtain using Ito Lemma

Construct a delta neutral portfolio (short call option and long underlying), then we have:

If we combine the terms, we will get

Realise is independent of random term , thus portfolio is risk free.

Realise is independent of expected return .

Thus, portfolio should earn the risk free rate of return, i.e.

Therefore, combining with in the previous step, we have below Black-Scholes PDE:

Now we need to solve the above Black-Scholes PDE.

Step 1

Transformation: Let’s introduce new variables , and .

Therefore, the Call option price can be represented using new variables and as .

Now we introduce a new function . We need to find the PDE for where

By Chain rule for partial derivatives, we have:

Now we plug into the Black-Scholes PDE, then we find the PDE for :

Step 2

Transformation to Heat Equation: Let’s introduce a new function . We need to choose constants so that the PDE of is Heat Equation.

Together with the PDE for , we can derive the PDE for :

To be a Heat Equation, we need to force the last two terms be . Thus

Then we have

Step 3

The solution of PDE is given by Green formula as below:

Step 4

We look at the boundary condition .

Then

which can be integrated as below, where is the cumulative distribution function (CDF) for Normal distribution.

Step 5

From the above steps, we have relation

And from Step 4, we know the result of .

Therefore, we derive as

Now we plug in , , , from previous steps. Finally, Call option price can be represented as

where

Python implementation of Black-Scholes formula:

def ncdf(x): """ Cumulative distribution function for the standard normal distribution. Alternatively, we can use below: from scipy.stats import norm norm.cdf(x) """ return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0 def npdf(x): """ Probability distribution function for the standard normal distribution. Alternatively, we can use below: from scipy.stats import norm norm.pdf(x) """ return np.exp(-np.square(x) / 2) / np.sqrt(2 * np.pi) def blackScholesOptionPrice(callPut, spot, strike, tenor, rate, sigma): """ Black-Scholes option pricing tenor is float in years. e.g. tenor for 6 month is 0.5 """ d1 = (np.log(spot / strike) + (rate + 0.5 * sigma ** 2) * tenor) / (sigma * np.sqrt(tenor)) d2 = d1 - sigma * np.sqrt(tenor) if callPut == 'Call': return spot * ncdf(d1) - strike * np.exp(-rate * tenor) * ncdf(d2) elif callPut == 'Put': return -spot * ncdf(-d1) + strike * np.exp(-rate * tenor) * ncdf(-d2) def blackScholesVega(callPut, spot, strike, tenor, rate, sigma): """ Black-Scholes vega """ d1 = (np.log(spot / strike) + (rate + 0.5 * sigma ** 2) * tenor) / (sigma * np.sqrt(tenor)) return spot * np.sqrt(tenor) * npdf(d1) def blackScholesDelta(callPut, spot, strike, tenor, rate, sigma): """ Black-Scholes delta """ d1 = (np.log(spot / strike) + (rate + 0.5 * sigma ** 2) * tenor) / (sigma * np.sqrt(tenor)) if callPut == 'Call': return ncdf(d1) elif callPut == 'Put': return ncdf(d1) - 1 def blackScholesGamma(callPut, spot, strike, tenor, rate, sigma): """" Black-Scholes gamma """ d1 = (np.log(spot / strike) + (rate + 0.5 * sigma ** 2) * tenor) / (sigma * np.sqrt(tenor)) return npdf(d1) / (spot * sigma * np.sqrt(tenor))

Suppose we want to find the value of:

in some region with volume .

Now, we can estimate this integral by estimating the proportion of random points that fall under , then multiplied by .

The speed Monte Carlo method converges to the correct result as we increase the sample size / number of simulations.

Monte Carlo has convergence rate .

Quasi Monte Carlo has convergence rate .

Reduce the variance of Monte Carlo simulated result with regard to the true result.

Not very feasible, as in order to decrease variance / noise linearly, we have to increase simulations exponentially.

We take any prime number r where r>=2. Any integer n has a unique expansion with base r. We can then generate a sequence of numbers in the interval [0, 1), which are equally spaced within the interval.

For example, r = 3 and n = 7. We can write 7 in the form of base 3 as below:

Now, if we reflect this number about its “decimal point”, we get a new number in [0, 1):

We keep on doing this for every number n, we will generate a sequence in interval [0, 1). And we observe that the newly generated number keep filling the gaps in proceeding sequence. For example, for n = 1 to 9, we have below Faure Sequence:

In a general form, for any given number n, we can represent n in base r:

Then, we can find the corresponding Faure number in interval [0, 1) as follows:

最近一直比较忙，在大家的再三催促下，抽出点时间写写这几天的感悟。：）

进入2018年2月以来市场打破了几年来的平静，有据说程序带来的闪崩，有FB为主的data privacy的担心，更有特朗普炮轰亚马逊和trade war的恐慌。总之，一个字：不平静。

市场的波动性理论上会带来更多的盈利机会，当然，也会给很多小白带来很多不确定性和亏损。应对这种不确定性，避免自己爆仓，对冲（hedging）自然是非常重要的。

对于对冲，简单谈谈几点思考，以后有机会还会做进一步展开讨论。

比如，如果我现在已经massive long FB，但它的股票一直在跌，我现在就不可以long call 或者short put，而是应该相反。hedge的size和tenor也要根据自己的view来决定。

尤其在time horizon很长（比如10年）和leverage很低的情况下。这种情况下不需要担心爆仓等。如果是passive investment，比如buy and hold S&P500，一定要相信经济长期是盘旋向上的，尤其美国经济也是整体向上的，这在短时间内不会改变。即便是明年经济危机，最多两年又会恢复。我们从Cobb-Douglas production function就可以看出productivity, capital, labor都会推动整个经济增长，而股市往往又是跟随经济起伏。记得之前有人十年如一日做空VIX发家致富大概也是一个道理。

这是另外一种极端的情况。比如对于卖方/做市商来讲，他们通常只赚取spread和flow，不会take risk。假如一个FX Derivatives market maker有residual risk exposure （delta, gamma, vega等等），他会马上去做hedging，让自己的PNL不会因spot, vol波动而起伏。

根据我们view不同，可以做的对冲structure也多种多样，以下是一些常见例子：

- 假如我现在long 10K USD SPY spot position，我的view是2018年会比较波动但不会有大危机，预期5%-10%的回报率。这种情况下，我就可以做一个collar，short out-of-money call 同时 long out-of-money put，这样的hedge不会很贵因为premium抵消一些，可以做到获取一定范围内的upsides收益，同时也有downside protection.
- 假如我的view是美股今年可能继续大涨，downside risk不会很大。那我可以在现有Long spot position基础上，Long higher strike OTM put, 同时short lower strike OTM put. 这样我们去除了一部分downside risk，同时hedge不会很贵。唯一的风险是美股大幅下跌的情况，但根据我们的view是小概率事件。
- 假如我现在Long FB股票，但市场对科技股情绪下降，如果我相信FB的前景和基本面好于其他科技股，如Twitter，特斯拉等，我可以选择short 这些科技股来对冲掉科技股行业的风险，只留下company specific risk。这就是Long short的思想。或者我可以short tech index，因为我相信FB会outperform 行业。

很显然当我已经损失了很多的时候才想到去对冲，充其量只能停止损失更多。而且市场跌的时候也往往代表反弹的概率在增大。市场情绪差的时候也往往是对冲cost很高的时候，因为市场波动性大。所以现在回望18年1月美股的牛市，在市场不理性的上升时，要感到恐惧和敬畏，那时候也是最佳对冲的时候。

因为有unlimited downside risk。而我们往往低估或不能预测市场的走向和不确定性。08年经济危机的时候就有人利用这点赚了很多钱。危机之所以是危机，是因为它出乎人们的预料。

- We start with the assumption that underlying follow Geometric Brownian Motion (GBM):

- We use Ito’s Lemma with , then we have

By Ito’s Lemma, we have

- Therefore, the change of between time 0 and future time T, is normally distributed as following:

Thus, the future underlying price can be written as,

is the noise term from standard normal distribution.

Note, we will take , which is the risk free rate. This means investors are risk neutral and requires risk free return on underlying asset. This is to be consistent with the risk neutral probabilities used in simulation.

Correspondingly, we also use risk free rate in the discount factor in step 5.

- So now we can simulate the future underlying price at expiry. With European Call or Put boundary condition to calculate the payoff.

- We then need to discount the future payoff back to present by multiplying a discount factor,

- The above two steps are repeated many times and its expectation is calculated as the final simulation result.

python code：

def getMCPrice(self): """ Determine the option price using a Monte Carlo approach. The log return of underlying follow Normal distribution. s_T = s_t * exp((r - 1/2 * sig^2) * (T-t) + sig * sqrt(T-t) * sig_Normal) """ calc = np.zeros([self.iterations, 2]) rand = np.random.normal(0, 1, [1, self.iterations]) mult = self.spot * np.exp(self.tenor * (self.rate - 0.5 * self.sigma**2)) if self.callPut == 'Call': calc[:,1] = mult * np.exp(np.sqrt((self.sigma**2)*self.tenor) * rand) - self.strike elif self.callPut == 'Put': calc[:,1] = self.strike - mult*np.exp(np.sqrt((self.sigma**2) * self.tenor) * rand) avgPayOff = np.sum(np.amax(calc, axis=1)) / float(self.iterations) return np.exp(-self.rate * self.tenor) * avgPayOff def getBSPrice(self): """ Determine the option price using the exact Black-Scholes expression. """ return blackScholesOptionPrice(self.callPut, self.spot, self.strike, self.tenor, self.rate, self.sigma)

We can run the above in Python console：

from option_pricer import EuropeanVanillaPricer pricer = EuropeanVanillaPricer() pricer.getMCPrice() 2.1620364099067015 pricer.getBSPrice() 2.1736062697012564

As we can see in the above Monte Carlo simulation, we rely on drawing random numbers, from a Standard Normal distribution.

Alternatively, we can use random numbers from a Uniform distribution, i.e. equal probability of each random number.

Alternatively, we can use random numbers from a Uniform distribution, i.e. equal probability of each random number.

To do this, we combine step 3, 4 and 5, the current option price is obtained by integrating the terminal payoff under the risk neutral measure:

In the first line, function is just the payoff condition at expiry. As we are integrating with regard to , which follows Standard Normal distribution, the last term is the probability density function.

In the second line, we just use a new function h of epsilon to make the expression more compact.

In the third line, we do inverse transformation to integrate with regard to the cumulative probability, .

So now it becomes an integral of function over the UNIFORM distribution with range [0, 1].

Now our simulation task becomes taking random number from the Uniform distribution [0, 1], and then calculate integral of function using Monte Carlo.

To be more specific, our task has been changed from calculating

To evaluating

When we use Monte Carlo to estimate function integral, we may run into problem of random number clustering, which essentially leads to Convergence rate of .

To conquer this issue, instead of using pseudo-random numbers, we can use a deterministic sequence, whose numbers are more equally spaced. And this is exactly what Quasi Monte Carlo (QMC) does. More details on the low-discrepancy sequences can be found in this post.

今天又敲了一个volatility_pricer.py，可以分别计算给定股票的实现波动率，和用Black-Scholes算出的隐含波动率。

Python代码可以详见:

class VolatilityPricer(): """ Realized vol: Same as Black-Scholes, we assume the underlying follows a Geometric Brownian Motion. Then its log return follows a Normal distribution, with mean as 0. We take as input the historical daily underlying prices. Annualization factor is 252. Degree of Freedom is 0 as we are calculating the exact realized vol for the given historical period. Implied vol: Use Black-Scholes to back out the implied volatility from the given market option price. """ def __init__(self): self.historicalDataBySymbol = dict() self.dataHub = DataHub() self.realizedVolBySymbol = dict() def _loadHistoricalUnderlyingData(self, startDate, endDate, symbols): self.historicalDataBySymbol = self.dataHub.downloadDataFromYahoo(startDate, endDate, symbols) def _calculateRealizedVol(self, ts): """ Calculate the realized vol from given time series """ pctChange = ts.pct_change().dropna() logReturns = np.log(1+pctChange) vol = np.sqrt(np.sum(np.square(logReturns)) / logReturns.size) annualizedVol = vol * np.sqrt(252) return annualizedVol def getRealizedVol(self, startDate=datetime.date.today()-datetime.timedelta(days=30), endDate=datetime.date.today(), symbols=['SPY']): """ Calculate the realized volatility from historical market data """ self._loadHistoricalUnderlyingData(startDate, endDate, symbols) for symbol, df in self.historicalDataBySymbol.iteritems(): # Use daily Close to calculate realized vols realizedVol = self._calculateRealizedVol(df.loc[:, 'Close']) self.realizedVolBySymbol[symbol] = realizedVol return self.realizedVolBySymbol def getImpliedVol(self, optionPrice=17.5, callPut='Call', spot=586.08, strike=585.0, tenor=0.109589, rate=0.0002): """ Calculate the implied volatility from option market price """ return blackScholesSolveImpliedVol(optionPrice, callPut, spot, strike, tenor, rate)

这个我们也是假设股票的价格遵循Geometric Browian Motion，进而它的log return就服从Normal Distribution。

我的pricer可以自动从Yahoo Finance抓取历史数据，并以此构建时间序列。这样我们就可以算出股票的log returns序列，进而就可以算出它的方差，最后把波动率年化。

使用方法：

from volatility_pricer import VolatilityPricer vp = VolatilityPricer() vp.getRealizedVol() {'SPY': 0.086197389793546381} vp.getRealizedVol(startDate=datetime.date(2018,1,1)) {'SPY': 0.16562165494524139}

这个原理就很简单了，用Black-Scholes已知期权价格back out波动率。

但是没有公式可以直接进行计算，所以我用了牛顿导数方法来不断求最优解。我们在每一步需要计算一个当前波动率下的期权价格以及对应的Vega，然后不断缩小误差，直到满意的误差范围。

使用方法：

from volatility_pricer import VolatilityPricer vp = VolatilityPricer() vp.getImpliedVol() 0.21921387741959775

哈哈，我还是一如既往地太懒写细节，大家就自己看code吧。

如果有问题或者需要交流，欢迎关注和联系我哈。