代写Computational Finance with Python、代做Python程序语言
Summative project
Computational Finance with Python
Table of contents
General information 1
Marking and credit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Academic integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Submission instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1 Black-Scholes model 3
1.1 Historical volatility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 Binomial tree approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Local volatility model 8
2.1 Option pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.1 Monte Carlo method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.2 Finite difference methods . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Theta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
References 10
General information
Each student has a unique individualised assignment. Download your assignment directly from the submission point on Moodle.
1
Marking and credit
This project contributes 90% towards the final mark for the module.
The project will be marked anonymously. Do not include your name, student number or
any identifying details in your work.
In each exercise, marks are allocated for both coding (style, clarity and correctness) and
accuracy of numerical results, as well as explanations and written work (including comments and docstrings in the code). The marks indicated are indicative only.
Partial credit will be given for partial completion of an exercise, for example, if you are
able to do a Monte Carlo estimate with fewer paths or time steps.
It may prove impossible to examine projects containing code that does not run, or does
not allow data to be changed. In such cases a mark of 0 will be recorded. It is therefore
essential that all files are tested thoroughly in Colab before being submitted in Moodle.
Academic integrity
You may use and adapt any code submitted by yourself as part of this module, including
your own solutions to the exercises. You may use and adapt all Python code provided
in Moodle or on GitHub as part of this module, without the need for acknowledgement.
Any code not written by yourself must be acknowledged and referenced.
This is an individual project. You must not collaborate with anybody else or use code
that has not been provided in Moodle without acknowledgment. This includes, for example, discussing the questions with other students, actively using discussion forums or
using generative artificial intelligence (such as ChatGPT). Please consult the University’s
Student guidance on using AI and translation tools and Policy on Acceptable Assistance
with Assessment. Collusion and plagiarism detection software will be used to detect
academic misconduct, and suspected offences will be investigated.
Submission instructions
Submit your work by uploading it in Moodle by 4pm on 31 May. Work should be submitted as follows:
• Code (and numerical results) should be submitted in the form of Colab notebooks.
Code will be tested using unseen test data: use variables to store parameters rather
than values hard-wired into your code.
2
• Written text should be submitted in pdf format. Scans of handwritten text are acceptable, provided that they are legible.
• Use a separate set of files (ipynb and pdf, as appropriate) for parts 1 (Black-Scholes
model) and 2 (Local volatility model). “Part1.ipynb” or “part1.pdf” are examples of
sensible filenames.
Late submissions will incur a penalty according to the standard rules for late submission
of assessed work. It is advisable to allow enough time (at least one hour) to upload your
files to avoid possible congestion in Moodle. In the unlikely event of technical problems
in Moodle please email your files in a zip archive to alet.roux@york.ac.uk before the
deadline.
1 Black-Scholes model
Consider a risky asset with stock price S that follows geometric Brownian motion below
under the risk neutral measure Q, in other words,
dS_t = r S_t dt + sigma S_t dW^Q_t
or, equivalently,
S_t = S_0e^{(r-sigma ^2/2)t + sigma W^Q_t},
where r is the risk free rate, sigma is the volatility and W^Q is a standard Brownian motion
under Q.
The following code accesses data about a company Warner Bros. Discovery, Inc. using
Yahoo Finance.
import yfinance as yf 1
# create Ticker object which will allow data access
data = yf.Ticker('WBD')
# name of company
print("Name of company:", data.info['longName'])
# summary of company business
import textwrap 2
print("
", textwrap.fill(data.info['longBusinessSummary'], 65))
3
1 See Arrousi (2024) for more details and usage instructions. This package is available
in Google Colab, but on local installations (such as Anaconda) it may need to be
installed before use—Arrousi (2024) provides instructions.
2 See The Python Software Foundation (2024) for more details on wrapping text.
Name of company: Warner Bros. Discovery, Inc.
Warner Bros. Discovery, Inc. operates as a media and
entertainment company worldwide. It operates through three
segments: Studios, Network, and DTC. The Studios segment produces
and releases feature films for initial exhibition in theaters;
produces and licenses television programs to its networks and
third parties and direct-to-consumer services; distributes films
and television programs to various third parties and internal
television; and offers streaming services and distribution
through the home entertainment market, themed experience
licensing, and interactive gaming. The Network segment comprises
domestic and international television networks. The DTC segment
offers premium pay-tv and streaming services. In addition, the
company offers portfolio of content, brands, and franchises
across television, film, streaming, and gaming under the Warner
Bros. Motion Picture Group, Warner Bros. Television Group, DC,
HBO, HBO Max, Max, Discovery Channel, discovery+, CNN, HGTV, Food
Network, TNT Sports, TBS, TLC, OWN, Warner Bros. Games, Batman,
Superman, Wonder Woman, Harry Potter, Looney Tunes, HannaBarbera, Game of Thrones, and The Lord of the Rings brands.
Further, it provides content through distribution platforms,
including linear network, free-to-air, and broadcast television;
authenticated GO applications, digital distribution arrangements,
content licensing arrangements, and direct-to-consumer
subscription products. Warner Bros. Discovery, Inc. was
incorporated in 2008 and is headquartered in New York, New York.
The following code downloads 6 months of daily prices and stores it in a NumPy array S.
# Download 6 months of price data (daily closing prices)
hist = data.history(period="6mo")
4
# Store closing prices in NumPy array S
import numpy as np
S = np.array(hist["Close"])
# Plot closing prices
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize = (8,6))
ax.set(title = f"Closing prices of {data.info['longName']}",
ylabel = "Price", xlabel = "Time step")
ax.xaxis.grid(True)
ax.yaxis.grid(True)
ax.plot(S)
plt.show()
5
1.1 Historical volatility
A popular way of calibrating the volatility sigma is to estimate it from historical data. Suppose
that stock prices S_i (i=0,1,ldots ,m ) have been recorded at some fixed time intervals of
length au >0 measured in years (for example, au =1/12 for monthly recorded stock prices).
The log returns on these prices over each time interval of length au are
R_i=ln (S_i/S_{i-1})
for i=1,ldots ,m . The sample variance of these returns is s^2 , where
s^2=frac {1}{m-1}sum _{i=1}^mleft (R_{i}-overline {R}
ight )^{2},
where protect overline {R} = frac {1}{m}sum _{i=1}^m R_{i}. The sample variance s^2 estimates the variance sigma ^2 au of the log return
on the stock price over a time interval of length au . It follows that
hat {sigma }_{ ext {hist}}=frac {s}{sqrt { au }}
is an estimate for the volatility sigma . This is called historical volatility.
Exercise 1.1 (Coding task: 10% of project mark). Write a function that calculates the historical volatility of a given set of stock prices. It should have two arguments: a NumPy array
of stock prices, as well as au , and return the estimate protect hat {sigma }_{ ext {hist}} .
Then use your code to calculate and display the historical volatility of the Warner
Bros. Discovery, Inc. stock prices. You should copy and paste the code given above into
your Colab notebook in order to download the data.
1.2 Binomial tree approximation
The continuous process S can be approximated by a binary tree. One approach is based
on the log price process x defined as
x_t = ln S_t.
A binomial tree for x on the interval [0,T] can be built by taking Delta t = T/M , where M is
the number of steps in the tree. The steps are at the equidistant times
t_i = iDelta t ext { for } i=0,ldots ,M,
and x^{(M)}_i is the relevant approximation of x_{t_i} .
6
Consider the binomial tree approximation of x in which, at any time t_i and over a small
time interval Delta t, the approximation x^{(M)}_i of x_{t_i} can go up by Delta x (the space step, to be
determined), or go down by Delta x, with probabilities q and 1-q , respectively, i.e.
x^{(M)}_{i+1} = egin {cases} x^{(M)}_i + Delta x & ext {with probability } q x^{(M)}_i - Delta x & ext {with probability } 1-q. end {cases}
The drift and volatility parameters of the continuous time process are now captured by
Delta x and Delta t, together with the parameters r and sigma . We take x^{(M)}_0 = x_0 .
Exercise 1.2 (Binomial tree approximation: 25% of project mark). Design a binary tree
method that approximates the Black-Scholes model and can be used to price European
options. Your work should include the following:
1. Written work:
(a) Compute the conditional first and second moments of x_{t+Delta t} - x_t in the
continuous-time model and x^{(M)}_{i+1}-x^{(M)}_i in the binomial tree model.
(b) Given the value of Delta t, derive formulae for Delta x and q in terms of r and sigma by
matching the first and second moments of the continuous-time model and the
binomial tree model.
(c) State the algorithm used for pricing a European-style derivative security with
payoff at time T given by f(S_T) .
2. Write a Python function that uses the tree approximation to calculate the price at
time 0 of a European style derivative security with payoff at time T given by f(S_T) .
Your function should take the arguments S_0 , T, r, sigma , M and f.
3. Use your code to price a derivative with payoff
f(S) = egin {cases} S^{ 1.9 } & ext {if } S < K, 0 & ext {otherwise}end {cases}
and the following data:
• T = 0.5 .
• r = 0.03 .
• sigma = hat {sigma }_{ ext {hist}} as calculated for the Warner Bros. Discovery, Inc. data (use sigma =0.3 if
you were not able to calculate protect hat {sigma }_{ ext {hist}} ).
• S_0 as the final item in the array of Warner Bros. Discovery, Inc. data.
• M = 180 .
• K = S_0 .
7
2 Local volatility model
A model for a stock S is given by the stochastic differential equation
phantomsection label {eq-local-vol-model}{dS_t = r S_t dt + sigma (t, S_t) S_t dW_t^Q,} (1)
where r is the risk-free interest rate and W^Q is a Brownian motion under the risk-neutral
probability Q. The function sigma is defined as
sigma (t,S) = 0.25 e^{ -0.03 t} left (frac { 105 }{S}
ight )^{ 0.4 }.
The aim of this part of the project is to use Monte Carlo and finite difference techniques to
study a European style derivative where the payoff at time T=1 is
X = egin {cases} (S_T - 110)^+ & ext {if } S_t ge 100 ext { for all } tin [0,T], 0 & ext {otherwise.} end {cases}
Take S_0=£105 and r=0.05 .
2.1 Option pricing
The aim in this section is to approximate the price of the put option at time 0 for a range
of stock price values.
2.1.1 Monte Carlo method
Exercise 2.1 (Monte Carlo estimate: 30% of project mark). Implement Monte Carlo simulation to estimate the price of this derivative at time 0 under Q. Use the Euler method, and
antithetic variates to reduce the variance of the estimate.
Your work should include a statement of the Monte Carlo algorithm that you are using.
Report the Monte Carlo estimate of the price, the standard error and an approximate 95%
confidence interval with 10000 paths and 20000 steps per path.
Hint: To reduce the discretization error, apply the Euler method to the process Y defined
as Y_t=ln S_t instead of to S directly. Use the Itô formula to derive a stochastic differential
equation for Y.
8
2.1.2 Finite difference methods
The price of a path-independent option at time t can be expressed as V(t,S_t) , where the
function V satisfies the partial differential equation
phantomsection label {eq-local-vol-pde}{frac {partial V}{partial t}(t,S) + r S frac {partial V}{partial S}(t,S) + frac {1}{2}sigma ^2(t,S)S^2frac {partial ^2 V}{partial S^2}(t,S) - rV(t,S) = 0} (2)
for all tin [0,T) and S>0 , together with boundary condition
V(t, 100) = 0
and final value
V(T, S) = egin {cases} (S - 110)^+ & ext {if } S ge 100, 0 & ext {otherwise}. end {cases}
Exercise 2.2 (Backward Euler method: 25% of project mark). Design an implicit (backward Euler) finite difference scheme to approximate the solution to the partial differential
equation in Equation 2. Your work should include the following:
1. Convert the final value problem into an initial value problem, and define a suitable
grid that contains the points (0,100) and (0,S_0) .
2. Propose an appropriate boundary condition for S
ightarrow infty .
3. Derive the iterative scheme in matrix form that would allow you to approximate
the value of V at the grid points. Give the lower diagonal, main diagonal and upper
diagonal elements of the matrix.
4. Write a Python function to implement the iterative scheme. Your function should
have suitable arguments and return values.
5. Compare your results to the Monte Carlo estimate. Is it possible to choose values
for the step sizes that result in the price V(0,S_0) being within the confidence interval
produced by the Monte Carlo method?
6. Report numerical results in an appropriate way, for example, via a 3d surface representing option prices for all tin [0,T] and a 2d graph representing option prices at
time t=0 , all for a range of S.
2.2 Theta
Exercise 2.3 (Theta: 10% of project mark). Approximate the value of the theta Theta = frac {partial V}{partial au } at
all the grid points used for the finite difference approximation in Exercise 2.2. Your work
should include the following:
9请加QQ:99515681 邮箱:99515681@qq.com WX:codinghelp
- 情感共振 WhatsApp拉群营销工具用心打造每个用户的个性化体验之旅
- Ins批量筛选群发营销采集神器,Instagram助你打造营销新局面!
- instagram营销推流上粉营销工具,ins打粉爆粉群发营销助手
- instagram2024最强群发营销引流软件,ins引流营销推广必备神器
- WhatsApp拉群营销利器 有人发现了吗 分享一下你的独特体验
- tg群发营销软件,tg拉群私信群发,海外获客爆粉就用天宇爆粉神器
- 跟着林永健、武大靖一起探班体彩开奖现场
- 绿色农业,守护我们共同的家园
- InBody亮相CMEF 开启健康管理新篇章
- 突破创意边界,成就非凡:LINE工具为您的业务注入前所未有的创造力!
- 不忘初心,奋楫千里 贸泽电子庆祝公司成立60周年
- Telegram代群发消息都可能是下一笔交易的喜悦源泉,这是生意的魅力所在
- 安徽谷器数据荣获“2023年度数字化服务创新引领奖”
- Instagram营销软件 - ins采集软件/ig采集助手/ins群发助手
- 北京爱尔英智眼科医院刘畅提醒广大市民,飞絮季节谨防过敏性结膜炎
- 鸿蒙生态千帆启航仪式即将启动
- 电报拉群神器!Telegram营销软件助你实现社交爆发!
- WhatsApp购买协议号方式/ws劫持号频道号快速购买
- 点燃乡村儿童阅读热情,TT语音幸福书屋建设互联网教育体系
- WhatsApp营销软件,ws最强群发工具/ws协议号/ws业务咨询大轩
- Ins高效筛选助手,Instagram群发代发工具,让你的营销更高效!
- 外贸小白迷茫中 WhatsApp拉群营销工具有什么好用的 值得推荐吗
- Telegram自动引流营销软件使用教程,TG营销引流工具
- Ig引流软件,Instagram批量群发私信助手,ig引流必备工具
- 数据摆在面前 WhatsApp拉群营销工具助我在全球范围内建立了稳健的品牌形象
- Ins引流利器,Instagram高效营销软件,助你轻松推广品牌!
- CSC1002代写、代做Python/c++语言程序
- AI6126代做、Python设计程序代写
- ins自动群发软件,instagram智能获客引流营销软件
- 2024“一带一路”瓜菜产业发展大会在新疆疏勒盛大开幕
推荐
- 升级的脉脉,正在以招聘业务铺开商业化版图 长久以来,求职信息流不对称、单向的信息传递 科技
- 智慧驱动 共创未来| 东芝硬盘创新数据存储技术 为期三天的第五届中国(昆明)南亚社会公共安 科技
- B站更新决策机构名单:共有 29 名掌权管理者,包括陈睿、徐逸、李旎、樊欣等人 1 月 15 日消息,据界面新闻,B站上周发布内部 科技
- 创意驱动增长,Adobe护城河够深吗? Adobe通过其Creative Cloud订阅捆绑包具有 科技
- 如何经营一家好企业,需要具备什么要素特点 我们大多数人刚开始创办一家企业都遇到经营 科技
- 疫情期间 这个品牌实现了疯狂扩张 记得第一次喝瑞幸,还是2017年底去北京出差的 科技
- 全力打造中国“创业之都”名片,第十届中国创业者大会将在郑州召开 北京创业科创科技中心主办的第十届中国创业 科技
- 老杨第一次再度抓握住一瓶水,他由此产生了新的憧憬 瘫痪十四年后,老杨第一次再度抓握住一瓶水,他 科技
- 苹果罕见大降价,华为的压力给到了? 1、苹果官网罕见大降价冲上热搜。原因是苹 科技
- 丰田章男称未来依然需要内燃机 已经启动电动机新项目 尽管电动车在全球范围内持续崛起,但丰田章男 科技