联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2024-03-13 10:37

Objective:

? Applications of Queues

? Explain various fundamental abstract data types (ADTs), such as queues and its application

Introduction:

In the financial market, market participants need to price the value of a financial instrument called option.

In simple wordings, option’s price ( or premium ) is a function of the probability of a particular event (in?the?money) happening.

Though the premium can be calculated by a mathematic formula with some assumptions, we can calculate it by an alternate method called Monte Carlo simulation.

The following are the basic steps in Monte Carlo simulation.

1.Define a domain of possible inputs

2.Generate inputs randomly from a probability distribution over the domain

3.Perform a deterministic computation on the inputs

4.Aggregate the results

In this exercise, we will run a Monte Carlo simulation and calculate the stock option price. In the simulation, the Queue ADT is used. Queue data structure is often used in Monte Carlo simulation because of its FIFO nature.

Environment:

? PC installed with Visual Studio Code and Python 3.x.

Implementation

Aclass OptionSimulator isprovidedin option.py whichhascodefortherequiredstochasticfunctions used in the simulation of the stock random walk.

Instruction for Step 2:

You can call the following function to get a random number which follows the probability distribution for stock movements.

def _get_random_number(self):

1

Instruction for Step 3:

You need to fill in the function def simulate(self) for step 3.

self._num_of_walks

OptionSimulator.

First, you need to generate a number, which is defined in, of random numbers and enqueue them in the Queue self._queue of the class

During the simulation, those random numbers are dequeued from the Queue, applied one?by?one on the previous stock price and mimic the stock’s random walk.

Please note that the stochastic process is a log?normal distribution, therefore, every step of the random walk is calculated by

????(????) = ????(?????1) + ???????????? ????????????

After the simulation finishes, you will get a series of steps

{????(??0),????(??1),????(??2),...,????(????)}

and you need to get the values of

??0,??1,??2,...,????

by the exponential function. In Python, you can use the module numpy exponential function for the calculation.

numpy.exp( )

Then, you can get the option payoff on the expiry date by the function payoff_at_last()

Instruction for Step 4:

We run the simulation multiple times and get a list of payoffs.

Then we can calculate the option price by finding the present value of the expected payoffs.


Appendix


This section includes the background knowledge about the theory and the mathematical model used in the Python program. You may read them if you are interested in these topics, but they are not required to complete this assignment.

What is Monte Carlo simulation?

Monte Carlo methods are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. The underlying concept is to use randomness to solve problems that might be deterministic in principle. The name comes from the Monte Carlo Casino in Monaco, where the primary developer of the method, physicist Stanislaw Ulam, was inspired by his uncle’s gambling habits. ( per Wikipedia.org )

What is Option?

A stock option gives an investor the right, but not the obligation, to buy or sell a stock at an agreed?upon price and date. ( Source from Investopedia.com) The payoff of a call option on the expiry date is as follows.

max(0,???? ? ??)

where

???? = Stock price on the expiry date

?? = Strike/Exercise price

Random Walk

Financial literature stocks are said to follow geometric brownian motion

AgeometricBrownianmotion(GBM)(alsoknownasexponentialBrownianmotion)isacontinuous?time stochastic process in which the logarithm of the randomly varying quantity follows a Brownian motion (also called a Wiener process) with drift. It is an important example of stochastic processes satisfying a stochastic differential equation (SDE)

???? = ???????? + ????????(??)

??

????(????) = ????(????????(??)

Brownian motion

Brownian motion is the random motion of particles suspended in a medium. Yes, this idea is from the Physic, but applied in Finance.


ThepictureaboveshowsaBrownianmotionofalargeparticle,analogoustoadustparticle,thatcollides withalargesetofsmallerparticles,analogoustomoleculesofagas,whichmovewithdifferentvelocities

in different random directions.

( Source from Wikipedia.org )

–End—


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp