官术网_书友最值得收藏!

Finance, Python - Monte Carlo pricing

Another algorithm in popular use is Monte Carlo simulation. In Monte Carlo, as the name of the gambling resort implies, we simulate a number of chances taken in a scenario where we know the percentage outcomes of the different results, but do not know exactly what will happen in the next N chances. We can see this model being used at http://www.codeandfinance.com/pricing-options-monte-carlo.html. In this example, we are using Black-Scholes again, but in a different direct method where we see individual steps.

The coding is as follows. The Python coding style for Jupyter is slightly different than used directly in Python, as you can see by the changed imports near the top of the code. Rather than just pulling in the functions you want from a library, you pull in the entire library and the coding uses what is needed:

import datetime
import random # import gauss
import math #import exp, sqrt
random.seed(103)
def generate_asset_price(S,v,r,T):
return S * exp((r - 0.5 * v**2) * T + v * sqrt(T) * gauss(0,1.0))
def call_payoff(S_T,K):
return max(0.0,S_T-K)
S = 857.29 # underlying price
v = 0.2076 # vol of 20.76%
r = 0.0014 # rate of 0.14%
T = (datetime.date(2013,9,21) - datetime.date(2013,9,3)).days / 365.0
K = 860.
simulations = 90000
payoffs = []
discount_factor = math.exp(-r * T)
for i in xrange(simulations):
S_T = generate_asset_price(S,v,r,T)
payoffs.append(
call_payoff(S_T, K)
)
price = discount_factor * (sum(payoffs) / float(simulations))
print ('Price: %.4f' % price)

The results under Jupyter are shown as follows:

The result price of 14.4452 is close to the published value 14.5069.

主站蜘蛛池模板: 淄博市| 子洲县| 台北县| 海淀区| 扎鲁特旗| 民权县| 宜良县| 大兴区| 曲沃县| 定远县| 黄山市| 扶余县| 霍州市| 抚顺县| 阿城市| 溧阳市| 迁安市| 黄浦区| 汾西县| 株洲县| 吉水县| 十堰市| 株洲县| 牡丹江市| 岗巴县| 融水| 昭苏县| 渭南市| 九龙县| 五原县| 宁南县| 长丰县| 兴海县| 昌邑市| 临汾市| 来宾市| 英吉沙县| 惠安县| 香格里拉县| 鹤壁市| 奇台县|