首页 > 编程语言 >MA323财经数学pytho算法

MA323财经数学pytho算法

时间:2023-04-05 09:03:09浏览次数:29  
标签:MA323 Python 算法 option time must Carlo your pytho


MA323 Computational Methods in Financial Mathematics
Assessed Coursework (2023)
02/03/2023
1 Guidelines
1.1 Submission
Your coursework must be submitted by
Monday 17th April 2023, 4pm (UK time).
All consequences regarding late submission can be found on the School’s website
https://info.lse.ac.uk/Staff/Divisions/Academic-Registrars-Division/
Teaching-Quality-Assurance-and-Review-Office/Assets/Documents/Calendar/
GeneralAcademicRegulations.pdf
Note in particular: Five marks (out of 100) will be deducted for coursework submitted late
within 24 hours of the deadline and a further five marks will be deducted for each subsequent
24-hour period until the coursework is submitted.
After five working days, coursework will only be accepted with the permission of the Chair
of the Sub-Board of Examiners.
Please submit your complete report together with all files to [email protected].
Include “MA323 submission” in the subject line.
For the submission please only submit one zip-file that contains all your files except
the Plagiarism Statement, which you should submit in the same email. Your zip-
file should have the following name: If your candidate number is 123456, then name your
zip-file MA323 CN123456.zip.
Your zip-file must contain your Jupyter Notebook (please provide an ipynb file, which the
examiners can run, and a pdf version of it.) You should name these files according to your
course code and candidate number, e.g., MA323 CN123456report.ipynb.
The content of your work must remain anonymous, so do not write your name on anything ex-
cept the Plagiarism Statement. Instead, you must identify your work with your Examination
Candidate Number. You can check your candidate number on ‘LSE for You’.
1.2 Academic integrity
When you submit the coursework you must submit a completed and signed copy of the
Plagiarism Statement (available on Moodle).
You are required to read the information on plagiarism on the following website:
https://info.lse.ac.uk/Staff/Divisions/Academic-Registrars-Division/
Teaching-Quality-Assurance-and-Review-Office/Assets/Documents/Calendar/
RegulationsAssessmentOffences-Plagiarism.pdf
1
Note in particular the first paragraph on this website:
“All work for classes and seminars (which could include, for example, written assignments,
group work, presentations, and any other work, including computer programs) must be the
student’s own work. Direct quotations from other work must be placed properly within
quotation marks or indented and must be cited fully. All paraphrased material must be
clearly acknowledged. Infringing this requirement, whether deliberately or not, or passing off
the work of others as the student’s own work, whether deliberately or not, is plagiarism.”
You must take this assessment completely alone and not show or discuss it with anyone else.
This is an open book assessment and you are allowed to use any material made available on
Moodle for MA323 and any academic literature as long as you cite the material that you use
fully.
You are not permitted to: consult any other person or AI tool about the content of the
assessment; allow any other person or AI tool to edit or proofread your work; submit any
ideas or phrasing that are not your own (without appropriate citation).
You should not include any writing of your own that has been submitted for a different
summative assessment.
The examiners may conduct vivas to check that you were the author of your submitted
assessment.
1.3 Specific guidelines on report
The coursework consists of four problems. Your answers to all four problems will count
towards the final mark.
Write a report and not just a question-answer style exercise set solution to answer the ques-
tions. Your report should contain all results and their derivation, interpretation and discus-
sion. Use complete sentences throughout. Give detailed arguments to explain your ideas and
carefully justify your answers.
The only acceptable programming languages are Python 3.7, 3.8, 3.9, 3.10, or 3.11.
Please provide only one notebook. Separate answers to the different questions clearly in this
notebook.
Your submitted Jupyter notebook should run completely without any error messages.
In particular, note that your Jupyter notebook should NOT ask the user to enter variables
needed for the computation. Choose reasonable default parameters yourself and make clear
in your instructions what the meaning and the names of the variables are such that the
examiners can test several examples.
Add appropriate comments to your code to explain what your code is doing.
Your figures should be well formatted, with good axis labelling and appropriate titles.
1.4 Assessment
The coursework will be marked in line with the departmental assessment criteria which are available
on pages 19/20 of your student handbook:
https://www.lse.ac.uk/Mathematics/assets/documents/Handbooks/2022-23/
22-0201-UG-Mathematics-Handbook-Final.pdf
? LSE 2023 2
2 Coursework Description
If you use a random number generator for any of the problems below, seed the generator so that
the results are reproducible.
Problem 1. Consider the two integrals.
(a) Describe a numerical method to approximate the value of I1 such that the approximation error
is guaranteed to be bounded by 1/100. Implement this method in Python and provide the value
of the approximation.
(b) Explain how one can approximate the integral I2 using a Monte-Carlo estimator. Implement
the Monte-Carlo estimator in Python and provide a figure that plots a Monte-Carlo estimate
against the number of samples (as we have done in the lectures and programming sessions).
Describe a variance-reduction technique that can be applied here and discuss how well this
technique works in this example.
(c) Develop and implement a Monte-Carlo estimator in Python to approximate the sum S.
Problem 2. Consider the function f : R→ R given by
f(x) =
{
3
2(x? 1)2, if x ∈ (0, 2),
0, if x /∈ (0, 2).
(a) Suppose you would like to generate a sample from f using von Neumann’s acceptance-rejection
algorithm. Specify a probability density function g ?= f that can be used for this purpose
and describe in detail how you can obtain a sample from f by sampling from g using von
Neumann’s acceptance-rejection algorithm. For your choice of g what is the best possible
proportion of numbers that your algorithm accepts? Implement von Neumann’s acceptance-
rejection algorithm in Python to obtain 10000 samples from f and plot a histogram of the
samples.
(b) An alternative to von Neumann’s acceptance-rejection algorithm from part (a) for sampling
from f would be to use the inverse transform method. Implement it in Python and draw again
a histogram of the samples. Which of these two methods do you think is more suitable for
generating a sample from f and why?
Hint: If you get a Python runtime warning, the following discussion might help:
https://stackoverflow.com/questions/45384602/
numpy-runtimewarning-invalid-value-encountered-in-power
? LSE 2023 3
Problem 3. We consider a financial market consisting of three assets (one riskless asset and two
stocks). The riskless asset has time-t price Bt = e
rt, where r ≥ 0 is the constant interest rate, and
the two stocks have time-t prices
0 > 0 are the initial stock prices, σ > 0 and η > 0 are the volatilities, and
(WAt )t≥0 and (WBt )t≥0 are independent Brownian motions under the risk-neutral measure. (In
Latex, η is written as \eta.)
Consider a European option with payoff H at the maturity date T > 0 given by
H = max{SAT , SBT }.
(a) Write down a Monte-Carlo estimator for the time-0 price of this option. Justify your answer.
(b) Explain in detail how one can generate the random variables that are used in your Monte-
Carlo estimator in part (a).
(c) Write Python code that computes the approximation of the time-0 price of the option using a
Monte-Carlo estimator.
(d) Use your Python code to compute the time-0 price of the option for the model parameters
SA0 = 4, S
B
0 = 3, r = 0.01, σ = 0.2, η = 0.4, T = 2 using the Monte-Carlo estimator.
? LSE 2023 4
Problem 4. We now consider a financial market consisting of two assets (one riskless asset and
one stock). We still assume that the time-t price of the riskless asset is given by Bt = e
rt with
r ≥ 0. We now assume that the dynamics under the risk-neutral measure of the risky asset are
given by
dSt = rStdt+ σ(St ? 1)dWt,
where (Wt)t≥0 is again a Brownian motion under the risk-neutral measure and σ > 0. We assume
S0 > 1.
(a) Explain how you can generate a sample path of S = (St)t≥0 on the discrete time grid 0 < h <
2h < . . . < nh for h > 0, n ∈ N. Write Python code that provides samples of ST for T > 0.
Create a plot with ten sample paths of (St) for S0 = 4, r = 0.01, σ = 0.2, and T = 1 with
h = 1/250.
(b) Consider a European call option with strike K = 4erT , i.e, an option whose payoff H at the
maturity date T > 0 is given by
H = (ST ? 4erT )+.
Write down a Monte-Carlo estimator for the price of this option. Justify your answer.
(c) Write Python code that computes the approximation of the time-0 price of the option using a
Monte-Carlo estimator together with an asymptotic confidence interval. Use your Python code
to compute the time-0 price of the option for the model parameters S0 = 4, r = 0.01, σ = 0.2,
T = 1 using the Monte-Carlo estimator. Provide a 95%-asymptotic confidence interval for
the time-0 price of the option. Discuss your results.
(d) Specify a variance-reduction technique for approximating the time-0 price of the option in part
(b) and implement it in Python. Discuss your findings.

WX:codehelp mailto: [email protected]

标签:MA323,Python,算法,option,time,must,Carlo,your,pytho
From: https://www.cnblogs.com/qujava/p/17288797.html

相关文章

  • 开源 文本到视频:Tune-A-Video 本周 star 增长数:1,050+,主语言:Python
    开源不到48小时获35kstar的推荐算法「GitHub热点速览转载自己笔记备用 非公开  原作者博客园 本周的热点除了GPT各类衍生品之外,还多了一个被马斯克预告过、在愚人节开源出来的推特推荐算法,开源不到2天就有了35k+的star,有意思的是,除了推荐算法本身之外,阅......
  • python
    我感觉我静不下心来真的不会像其他博主写的很详细,就是一顿瞎写的。。。python列表列表可进行修改遍历列表列表名=列表内容for列表名1in列表名:print(列表名1)PS:需要缩进列表解析列标切片元组元组不可进行修改字典,键值对输入......
  • Python ORM Pony 常用表连接聚合操作(sum()、count()、min()、max()、avg()等)
    Pony是一个高级的对象关系映射器ORM框架。Pony它能够使用Python生成器表达式和lambdas向数据库编写查询。Pony分析表达式的抽象语法树,并将其转换为SQL查询。支持SQLite,MySQL,PostgreSQL和Oracle等数据库,本文主要介绍PythonORMPony中常用聚合操作(sum()、count()、min()、max(......
  • python安装g2opy与pagolin踩坑记录
    0x00.前言本文是在python环境下跑slam时配置环境的一点记录,感谢代码作者uoip的贡献项目代码:g2opy:https://github.com/uoip/g2opypangolin:https://github.com/uoip/pangolin0x01.安装笔者的环境是使用anaconda搭建的虚拟环境,由于一开始没有激活虚拟环境导致踩坑,之后虽然......
  • python中的sys.argv,以及sys.exit(1)怎么用?
    一、sys.argv是获取运行python文件的时候命令行参数,且以list形式存储参数其中,sys.argv[0]代表当前module的名字以下用代码举例:importsysa=sys.argvb=len(sys.argv)print(a)print(b)打印结果如下:   还是上面的代码,当我运行时候输入:python a.py shi输出......
  • flask框架01 flask与pythonweb框架介绍 flask快速使用 登录显示用户信息案列 配置
    今日内容详细目录今日内容详细1Flask和pythonweb框架介绍1.1flask介绍2flask快速使用3登录,显示用户信息小案例3.1login.html3.2home.html3.3detail.html3.4py文件4配置文件方式5路由系统5.1转换器1Flask和pythonweb框架介绍pythonweb框架的本质都一样1.同步框架......
  • python快速求因子
    n=2021041820210418l=[]#!!!!用于存因数不是因子例如:10=2*5i=2x=nwhilei<pow(x+1,0.5):ifx%i==0:l.append(i)x=x//ielse:i+=1l.append(x)s=set()#!!!!用于存因子如10=1*2*5*10s.add(1)forjinl:p=set()forkin......
  • python用于新建空文件夹/文件&以时间命名的文件&文件夹内的文件合并
    '''用于新建空文件夹'''path="/root/temp/"defmake_Empty_Dir(path):'''如果path这个路径下存在文件夹,就先删除它,再新建它,如果不存在,就新建它,目的是为了temp为新的空文件夹'''importosimportshutilifos.path.isdir(path......
  • 四种语言刷算法之重排链表
    力扣143. 重排链表1、C/***Definitionforsingly-linkedlist.*structListNode{*intval;*structListNode*next;*};*/voidreorderList(structListNode*head){structListNode*p=head;intcount=0;while(p){p......
  • 算法问题——动态规划和回溯算法问题
    回溯算法树形问题排列问题组合问题二位平面的回溯算法回溯递归问题树形问题17.电话号码的字母组合(全排列的问题)/***Copyright(C),2018-2020*FileName:letterCombinations*Author:xjl*Date:2020/3/2015:30*Description:给定一个仅包含数字2-9的字......