## 欧式期权定价回顾

```while i < num_iterations:
S_T = generate_asset_price()
payoffs += payoff_function(S_T)
i += 1
option_price = exp(-r*T) * (payoffs / num_iterations)```

## 二元期权

```def binary_call_payoff(K, S_T):
if S_T >= K:
return 1.0
else:
return 0.0```

## 模拟计算过程

```def gbm(S, v, r, T):
return S * exp((r - 0.5 * v**2) * T + v * sqrt(T) * random.gauss(0,1.0))```

```import random
from math import exp, sqrt
def gbm(S, v, r, T):
return S * exp((r - 0.5 * v**2) * T + v * sqrt(T) * random.gauss(0,1.0))
def binary_call_payoff(K, S_T):
if S_T >= K:
return 1.0
else:
return 0.0
# parameters
S = 40.0 # asset price
v = 0.2 # vol of 20%
r = 0.01 # rate of 1%
maturity = 0.5
K = 40.0 # ATM strike
simulations = 50000
payoffs = 0.0
# run simultaion
for i in xrange(simulations):
S_T = gbm(S, v, r, maturity)
payoffs += binary_call_payoff(K, S_T)
# find prices
option_price = exp(-r * maturity) * (payoffs / float(simulations))
print 'Price: %.8f' % option_price```

## 检验结果

```>>> from scipy.stats import norm
>>> from math import exp, log, sqrt
>>> S, K, v, r, T = 100.0, 100.0, 0.2, 0.01, 0.5
>>> d2 = (log(S/K) + (r - 0.5 * v**2) * T) / v*sqrt(T)
>>> print exp(-r * T) * norm.cdf(d2)
0.490489409105```
{"ft_lang_label":"__label__zh","ft_lang_prob":0.7524627,"math_prob":0.9972616,"size":1945,"snap":"2022-27-2022-33","text_gpt3_token_len":1135,"char_repetition_ratio":0.090159714,"word_repetition_ratio":0.19844358,"special_character_ratio":0.34344473,"punctuation_ratio":0.2,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999677,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-09T22:33:54Z\",\"WARC-Record-ID\":\"<urn:uuid:4edb3535-ec0a-40f0-8bfb-ded1eb68ceb8>\",\"Content-Length\":\"46692\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:923b3502-74af-4ed8-af7c-09f6db4d2a0a>\",\"WARC-Concurrent-To\":\"<urn:uuid:3ec49434-c851-4bd5-b66b-305f56930e86>\",\"WARC-IP-Address\":\"172.67.157.1\",\"WARC-Target-URI\":\"https://flashgene.com/archives/239441.html\",\"WARC-Payload-Digest\":\"sha1:UXAX4DXJU57OCXD5FXTON7WZTIZHAIVJ\",\"WARC-Block-Digest\":\"sha1:ZY3KVRQ7FMF2CFPOYUL3252Z4HKVNLDU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571090.80_warc_CC-MAIN-20220809215803-20220810005803-00745.warc.gz\"}"}