In this worksheet we look at different distribution functions, sampling methods, and probability calculations. Next we consider a calculation of a Europen option using Monte Carlo simulation, and compare results to calculation using Black-Scholes.
Remember to always set your working directory to the source file location. Go to ‘Session’, scroll down to ‘Set Working Directory’, and click ‘To Source File Location’. Read carefully the below and follow the instructions to complete the tasks and answer any questions. Submit your work to RPubs as detailed in previous notes.
Always read carefully the instructions on Sakai. For clarity, tasks/questions to be completed/answered are highlighted in red color (visible in preview) and numbered according to their particular placement in the task section. Quite often you will need to add your own code chunk.
Execute all code chunks, preview, publish, and submit link on Sakai follwoing the naming convention. Make sure to add comments to your code where appropriate. Use own language!
#Install package quantmod
if(!require("quantmod",quietly = TRUE))
install.packages("quantmod",dependencies = TRUE, repos = "https://cloud.r-project.org")
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Version 0.4-0 included new data defaults. See ?getSymbols.
Learn from a quantmod author: https://www.datacamp.com/courses/importing-and-managing-financial-data-in-r
Consider the free cash flow example with an estimated range set by a minimum of -$25M and maximum $275M. We start by generating a sample random set. Following is an example to generate a random set of 10 data points from a uniform distribution with probability \(\frac{1}{b-a}\), a minimum of a, and a maximum of b.
ud = runif(10, min=5, max=15) # runif is in reference to uniform distribution
# Other R functions needed for this task are hist(), mean(), sd(), punif(), runif(), pnorm(), and rnorm(). Check the Help command in R for more details about these functions.
##### 1A) Assuming a uniform probability distribution, generate a sample of 100 random observations (or deviates) representing the cash flows
rd=runif(100,min=-25, max=275)
print (rd)
[1] 153.779934 260.776200 233.378240 13.614148 243.291696 87.885175 144.461995 -24.209968 223.930833
[10] 263.949889 210.341433 215.769819 -2.485833 169.795024 7.484515 61.906213 132.313789 170.958078
[19] 23.809770 186.904852 220.868410 212.574781 -2.025383 254.050782 272.662752 224.003071 63.747046
[28] 224.342844 86.010188 17.672373 187.963285 194.567291 66.582234 257.889826 -11.081490 -5.713185
[37] 225.381513 230.045019 18.441578 154.785102 36.334086 196.343514 221.029084 100.320630 96.018428
[46] 201.381286 174.734811 121.024411 151.555225 207.392869 238.055864 11.274754 181.407933 124.025256
[55] 123.944595 173.171505 60.251407 106.658534 158.197772 33.545049 2.927321 61.924601 -2.755574
[64] -9.352144 172.843391 126.256524 176.072002 232.245488 50.434351 144.857440 98.005523 196.667046
[73] 169.451795 161.150079 151.821549 144.654360 3.873376 244.053004 268.496708 122.336631 80.968014
[82] 6.112153 121.626264 196.893978 16.527901 36.230061 61.699742 189.722865 172.143544 110.242101
[91] -20.533783 178.171387 20.006414 -8.775508 166.506759 124.018976 46.926042 20.940222 49.780941
[100] -24.935138
Next we plot a histogram to describe the generated sample data, and calculate the mean and standard deviation of the sample using the proper R-functions
##### 1B) Plot a histogram and calculate the mean and standard deviation of your sample. Compare the mean and standard deviation of the sample to the theoretical values obtained using the proper formulas.
hist(rd)
mean(rd)
[1] 124.4733
sd(rd)
[1] 87.40137
The theoretical mean is 125 and the standard deviation is 86.7. These values are both fairly close but are not a 100% exact match as it is not the true distribution.
##### 1C) Repeat 1A & 1B above by increasing the sample size to 1000. Share your insights.
rd2=runif(1000,min=-25, max=275)
print (rd2)
[1] 4.5056587 176.7900212 45.0529795 157.9348834 -18.4235958 234.9703598 47.0131409 227.7497962
[9] 52.5700177 218.8823346 40.0784922 93.2220657 260.2421682 102.7605534 175.5781943 155.8945463
[17] 154.5716276 -18.2053926 52.6720955 191.8607773 29.3135246 85.8743928 218.2378439 19.6007349
[25] 104.4678586 115.0195444 201.1400796 149.2313183 172.7909546 244.1556679 147.7622574 111.0538527
[33] 124.4027172 70.5990435 67.3652073 60.3218909 9.7187813 231.0032110 257.7425116 74.4193489
[41] 5.5817288 21.5673304 94.5716082 113.0246978 272.3025735 60.0775462 211.7602743 90.8391532
[49] 196.6361555 252.1111939 259.7558694 -12.2317666 111.7715508 125.1903789 2.6642898 177.8117717
[57] 178.6652627 174.1349735 261.9555064 232.5235120 27.4229049 108.5691256 10.6795907 81.0782809
[65] 210.3043196 33.4119335 94.8726235 219.7345343 139.5281194 75.0870690 89.7725642 273.4336561
[73] -23.3408403 152.8306206 35.4027176 190.9663390 -13.3245551 73.3234293 15.0204130 197.6283759
[81] 146.2144237 56.8663632 47.8781354 38.2569410 257.1372762 0.8629256 49.0393167 153.3447684
[89] 124.9789861 152.5500622 259.3895924 41.2742740 8.7733721 161.1930752 122.5080559 264.6005910
[97] 212.0133196 119.6806820 202.9711224 -13.3651769 140.6798653 255.1982420 270.6808443 57.9479063
[105] 12.7483101 -8.1033960 -17.6019864 142.5228405 255.1760500 76.9788278 113.9901948 19.5126552
[113] 172.2760762 -24.0222110 83.8944016 222.7745795 267.7773728 -11.2589756 41.3214326 90.4319177
[121] -6.1189855 236.2582649 65.1051550 37.9220052 101.5472103 15.7842833 7.7964394 82.1693095
[129] 101.9596335 229.2001545 140.7207020 169.3195784 64.3581474 22.0973481 84.6049306 265.3581687
[137] -11.8564056 37.9607115 111.0453837 132.3245479 7.8606786 112.6370528 22.7435906 17.3339822
[145] 222.9573638 259.8297154 204.2861896 241.6773173 99.1447870 186.8484484 25.7987682 133.4917815
[153] 234.2902764 97.4782245 197.6374246 39.9054277 116.3820019 -11.1188746 45.6373345 225.8569275
[161] 138.1882850 208.8698435 52.8375475 29.4559775 -0.3545903 86.4477687 34.5958917 71.8241937
[169] 66.1125880 230.1088863 248.9325195 156.9697568 259.2973688 152.2411174 247.3007387 128.8499187
[177] 178.2477766 62.2797811 223.3493726 187.5465874 -21.5066847 10.3432479 197.8125870 -3.1661495
[185] 211.7452853 27.9578036 85.4191682 141.7933408 127.1802941 76.7540530 124.4109370 -22.6512132
[193] 185.9925703 222.0600394 -7.6689797 94.2480707 126.0676128 39.9812341 229.5553133 -5.5449802
[201] 95.9119538 28.7223928 234.4029240 199.6625328 -23.8388334 -21.3973949 192.7410747 74.3046813
[209] -3.3980711 135.9435400 246.1865420 82.8690956 66.6972829 62.0221840 165.2223436 212.1502075
[217] 191.1114641 248.6732129 214.5948230 213.2002420 134.4539846 98.8961753 74.4128694 133.9124297
[225] 25.4025917 227.4724329 213.4590374 169.4024776 184.0194863 112.2080419 29.9263759 5.3832678
[233] 262.1564187 -13.2244724 75.0785052 132.9798607 166.8343164 112.5259252 146.1547429 263.5658006
[241] 236.0837308 75.0725245 -3.7548222 21.8760530 181.1182743 193.0171401 42.3107827 183.5006055
[249] 217.6092023 121.3554610 56.4988086 -18.6375454 257.2334497 52.1374941 102.9939639 174.6285209
[257] 86.5151872 93.9680719 166.3547750 73.0735929 211.4742330 252.8088741 263.2907825 48.8239459
[265] 191.5230961 77.6748945 61.2953801 138.0012350 189.0754489 3.1389211 229.8544205 132.0069206
[273] 10.0645459 129.9891918 195.3921979 36.0911340 51.2760559 36.1787942 246.5385503 269.5704260
[281] 37.4163605 3.0739900 84.0116049 206.0043314 150.7666202 168.1646062 4.1694182 182.6613156
[289] 180.9296513 145.2022480 46.7733236 -5.3831121 173.3545595 144.3258756 19.2375914 159.4991765
[297] 182.5217138 254.8888817 66.9373479 248.6124939 256.8112054 104.3298266 162.7253869 144.1423113
[305] 107.7790721 92.4390102 131.7601754 45.1637845 137.4676526 199.0021339 181.9297071 87.6086944
[313] 233.2317437 104.6497901 -10.9440517 126.7362993 249.2099111 -1.8904275 68.0645886 73.1956091
[321] 255.9226909 -5.4356816 179.5258712 124.3810991 96.3384124 3.9624420 177.9768662 177.2580127
[329] 160.9435125 161.8070100 -19.1376359 181.7320086 212.7291343 90.6470556 36.0191127 196.2575624
[337] -22.2700567 262.5156500 94.0142355 140.1507161 211.6547945 53.7990242 228.7033990 87.5595527
[345] 17.5627440 10.7817210 74.7262907 48.4406193 167.2361234 147.6024468 261.9540534 46.9865248
[353] 249.6601815 40.5517325 15.8892052 78.4340753 77.3745126 -16.2249057 52.0329186 40.9575926
[361] 151.1292220 7.3216756 17.0436324 138.2441107 16.7250503 199.2536788 196.6926830 17.6661225
[369] 27.5716561 5.2751475 11.3671042 271.6045021 125.7134494 157.8446116 86.2870512 25.1291786
[377] 264.0487855 182.1329931 31.2605081 26.9007395 114.3088717 262.9956581 1.8012971 -3.4324098
[385] 83.1382662 191.8731115 -7.2003877 11.9079371 36.8061199 141.8267410 253.2030401 269.0541807
[393] 226.7628139 228.1458051 136.6340690 47.9646783 245.0053075 196.1386313 52.3607268 166.7642828
[401] 87.5711367 227.0835782 61.4044575 271.7231875 -10.5620827 12.0424558 142.9485587 208.8447993
[409] 167.1717979 157.0027490 74.2327021 43.0784277 -15.5167036 186.7504491 223.9826507 112.7483254
[417] -1.3390952 143.3401528 73.3866170 241.2505515 98.0276312 258.9245380 6.1058962 -8.6232558
[425] 170.1093348 100.4163078 272.0044943 215.4769321 10.3723583 256.3579179 252.9004906 -3.9537092
[433] 137.6409391 191.5640955 69.9833428 7.1001517 235.1956579 271.4388278 265.8088672 124.6494957
[441] 268.4058215 220.4919861 -14.1488706 242.1965293 159.8937402 34.0917316 177.1747406 269.5330591
[449] 211.6995039 7.1752581 240.5224791 257.6660559 69.2970622 161.7660484 32.9374730 180.7278571
[457] 64.2839689 262.2015567 38.4484180 230.7472183 147.4930376 146.8266396 33.2557261 128.2465673
[465] 215.1059884 272.6792337 105.5469229 119.0435605 71.5396463 126.1297211 229.2453329 107.9317762
[473] 238.4310659 62.1584407 247.6549139 105.8001669 253.9069748 266.8827297 87.8289848 161.2949708
[481] 131.6816653 201.6524122 159.8600329 71.3582366 207.9525718 98.7556427 241.8678312 49.5900960
[489] 205.9700051 28.2457753 153.8895475 3.6195832 176.8403688 217.4888397 200.9107433 242.8876434
[497] 38.7814867 157.8548030 243.7685264 172.5124201 213.5179250 227.5617332 18.0714514 83.1749053
[505] 49.4682378 86.2535579 129.2505834 196.1145707 207.2088889 223.2959453 39.2502195 36.4802185
[513] 183.7354874 -12.5276825 162.9968288 36.2575544 110.9259329 205.2387701 273.9397437 267.6833882
[521] 109.0942675 180.6238572 223.2161413 85.7128563 70.6785783 69.5953589 266.1540024 74.9034567
[529] -1.4272979 248.2319206 174.5606079 224.1149597 272.6705048 79.8851777 -14.9233550 170.5559418
[537] 120.8433850 116.5492364 126.1046151 122.9268499 133.1066316 9.5740348 112.9954302 119.3764530
[545] 53.1454299 39.5743736 200.2365696 127.2558197 242.6728417 121.5759615 219.7457649 -9.2680550
[553] 245.2927187 180.9708017 17.4221179 81.5079347 109.3452197 -22.2841153 164.2023046 27.1481624
[561] 130.2480717 64.3232366 88.8620742 64.3355487 176.5251687 194.2898620 42.3484453 24.5773723
[569] 36.3346001 64.2049368 244.3417600 224.0907995 148.0854995 13.8186669 70.4466514 52.8116222
[577] 78.3368943 125.2407401 156.6604881 86.2498973 65.2126529 84.4768963 -21.5159387 131.2703339
[585] 225.0118120 223.7053059 14.0048402 254.0483259 124.7051851 171.5659879 211.8920223 86.8806259
[593] 233.9337847 102.6134024 265.0270861 248.5169103 171.5194607 245.1165431 92.1575815 143.8107625
[601] 81.7485658 265.1450746 272.8812486 131.7613230 91.2629193 3.6932003 262.4754258 170.3852158
[609] 212.5088529 236.8772768 121.8262724 141.0691294 125.9505316 251.5372207 147.4404656 38.6429504
[617] 215.9938224 148.0942474 152.1725142 253.3640160 210.5716017 158.2821681 87.3310571 240.4454935
[625] 210.8050379 69.1901953 63.3144241 230.9359723 6.0342664 132.0635645 133.2950741 167.8424509
[633] 135.9617080 258.7371282 167.7285359 156.0213019 140.1136261 197.7008451 33.9431414 24.8502003
[641] 238.8762509 62.1080763 207.3890961 107.5584182 79.5708297 274.7498402 38.2671780 236.7057865
[649] 88.8406492 234.9999069 204.4549115 145.4577122 162.0257439 239.0843200 99.8722540 193.8099922
[657] 35.5830577 0.3299551 141.4094638 175.9727834 151.0458030 105.9062826 193.2427355 65.6499354
[665] 128.0191364 63.5356878 136.7190223 -10.0004004 65.5250048 33.7946724 24.1528508 177.8416882
[673] 137.8825664 -19.4733419 205.9254091 151.4591544 137.1954988 241.8893801 100.7505601 196.3048844
[681] 113.7604309 212.3080977 123.3578329 181.2701798 135.7865023 78.3558911 57.4077360 274.1743659
[689] 57.0871463 -23.8656539 150.1714868 254.0845503 -1.4996208 55.8913868 79.9929856 210.7866167
[697] 252.0154357 259.1790384 23.4982412 128.6157095 194.1520774 230.7912067 117.1100205 202.6633147
[705] 159.7651556 49.4382879 18.9586971 214.5739729 13.4834210 89.5421922 21.7384214 226.9420089
[713] 73.6440646 191.9353480 141.4676405 16.0118770 128.6773654 170.0091242 198.9779635 169.8780257
[721] 240.2224707 238.0261797 -24.3595182 96.8101687 200.7499628 26.1623759 203.2282089 -23.2644843
[729] 11.2822685 235.0393561 79.4772045 98.2256143 20.9515745 122.9165700 141.2671851 184.5526951
[737] 198.2676554 -11.8889074 112.7405697 42.3580434 198.8331669 244.2063480 238.2237772 155.6647221
[745] 222.8967082 -2.1094575 206.7459098 12.4002454 223.0413846 213.9349462 233.6269380 28.0144500
[753] 30.4755434 69.4060927 219.1408057 209.0053295 151.8475478 105.7442274 61.2334065 256.1497471
[761] 31.4019205 -22.7373886 190.9743260 167.5728722 249.2214529 128.8643379 -4.6292054 242.1842488
[769] 61.9662770 38.7295922 67.3757655 -13.8556385 108.5397015 33.2067318 179.6578952 65.3918722
[777] 268.0420613 118.3426541 43.5074451 82.2716724 232.6887566 99.3908901 137.5794200 205.8010706
[785] 175.3389633 140.3787637 50.3375495 25.1776872 138.1175427 15.0423417 6.3345578 100.4309132
[793] 1.4226214 157.4914741 210.1364427 -22.0158275 233.3178151 104.7822979 217.1049527 172.7856625
[801] 235.2928712 57.7808168 52.9539758 155.3351578 165.4854215 28.6590953 90.6368928 7.3677107
[809] 248.4004423 152.3069585 240.8666645 65.8523530 -24.3447678 117.4325998 137.9499535 115.3491837
[817] 165.4440372 188.0876125 215.0764368 23.9761803 31.8298662 7.6314151 178.0319987 206.4918740
[825] 165.1648546 193.7315803 125.2212076 89.8759760 159.2053537 35.6609489 160.7920759 269.6677830
[833] 12.7156564 113.0591419 7.5179261 174.6183883 204.2504938 238.5334208 21.9504565 187.2826259
[841] 238.7468361 220.7133142 47.8885239 211.0775109 158.4496803 169.4717279 160.5870086 234.8976463
[849] 188.1076860 136.9175443 267.0533383 116.3538252 50.1468615 93.4562626 -14.0589754 213.0229641
[857] 23.5795245 267.2048926 125.0312508 -10.3750253 63.2851939 58.9875219 -13.2566008 56.1691068
[865] 49.3725075 92.7451816 68.9656463 135.4183190 65.8362374 23.9278800 144.5047005 88.7750148
[873] 38.7699923 56.9172898 33.0086107 153.9559357 248.4278349 269.5905362 109.2532212 -10.3106472
[881] 42.4244087 100.3025091 24.8610893 259.5391850 171.7007478 -0.1694644 83.6170358 269.5645430
[889] -23.9027283 131.7459363 220.2626427 161.7609552 226.3599316 80.8036968 237.5743035 103.3627438
[897] 26.5725413 95.5940378 151.7213500 -8.2293039 210.9526077 134.4267843 218.3426148 26.2299063
[905] 46.8851731 147.3519039 229.3088055 231.6546436 107.8237111 71.2706134 262.7057005 136.7041949
[913] 69.1367950 23.9727109 163.3130515 227.3128663 221.3531850 177.5642951 37.0534639 140.4945605
[921] 193.0516785 207.4061237 235.5681117 77.8810187 18.6604926 70.9014019 151.5344610 154.0232999
[929] 191.7699950 69.4472786 186.1264241 259.7711772 52.5066657 75.4770991 154.7478076 218.0498073
[937] 192.6482811 230.0482977 135.2458838 192.6326808 90.7409893 263.6722410 209.0478635 -3.7563532
[945] 184.3774417 -13.0575300 115.1668076 51.7294983 101.9933542 -12.7796186 115.8178962 113.3746485
[953] 8.7699784 272.5396535 249.4193922 93.3444569 154.8927698 39.4621288 233.0962616 244.4303591
[961] 109.1978309 240.3049121 23.9831174 228.2809206 -7.0967617 231.7957355 116.3976077 229.0548471
[969] 210.0573406 227.7554203 119.1664518 209.8536110 100.3338413 207.9391403 50.8665591 161.4544193
[977] 34.4113599 97.1270217 193.3080481 87.7432472 43.3730424 90.2785278 47.3817551 111.7552416
[985] 141.7703139 7.9894606 105.5482685 161.4432593 106.4854467 73.6137297 77.4850708 99.1922191
[993] 48.1737905 81.0834597 -7.5752888 135.2077718 0.8387504 5.7257933 11.4193346 32.1843325
hist(rd2)
mean(rd2)
[1] 125.8985
sd(rd2)
[1] 85.40285
The random distribution of 100 vs 1000 random values look fairly similar on the histogram plot. Additionally, the mean and standard are relatively close.
Given the characteristics of a probability distribution we should be able to compute various probability scenarios using the proper functions in R.
##### 1D) Calculate the probability that the free cash flow is negative
pnorm(0, mean = 125.9, sd =85.4)
[1] 0.07020864
We will now repeat the above exercises 1A, 1B, 1C using instead a normal distribution.
##### 1E) Repeat steps A-C for the case of a portfolio daily returns with normal probability distribution,a mean=1.2% and a standard deviation= 3.7%
pd = rnorm(100, mean=1.2, sd= 7)
print(pd)
[1] 5.7389091 17.6264930 3.1023529 5.1035898 4.3999953 -4.2346473 1.0660514 7.8498347
[9] 12.9880227 9.3118396 -0.5399629 1.0453504 -12.5343093 -1.9675323 -2.8690851 -6.8359737
[17] 0.3778260 6.0938071 4.6726227 7.2924211 -0.6347464 -3.7612360 -2.7505104 7.9079841
[25] 5.9961301 16.9198138 -9.4114400 -13.4472820 17.7243719 -2.7483319 -5.5334133 -4.0289846
[33] 15.4148751 8.0140540 -3.6404915 7.5557962 -5.8149800 0.6996060 -6.1843653 4.9663073
[41] -5.8686016 0.1400170 4.5621313 -0.2356885 -1.9844051 7.5746890 -17.2145026 -3.2745164
[49] -0.6133139 10.6760788 -3.9334404 4.0445797 -0.6157746 5.3386132 3.4877017 2.9199130
[57] 6.1212290 -3.0863874 5.1076324 5.7145437 -2.4159959 -0.8468763 8.3126061 5.7213771
[65] 5.1331475 0.3205653 0.2000846 4.3949565 2.5294882 10.7412235 -15.8791042 -7.6169620
[73] -5.9059737 2.2144628 -1.4585495 0.5065027 -2.0134737 2.0542273 -2.9356106 5.2781272
[81] 6.0670224 -0.5432488 8.1129411 -5.4012628 8.4159449 -3.7821453 -1.1709011 -4.6181476
[89] 0.8674188 -11.4275311 0.9575522 6.8552320 -3.3373356 -5.6453016 7.9154456 4.0804589
[97] -8.1320785 7.3010799 -1.6207146 2.2099100
hist(pd)
pd2 = rnorm(1000, mean=1.2, sd= 7)
print(pd2)
[1] -1.82530051 -5.67697996 -4.15960873 2.29724865 5.31830111 -2.06025791 16.96042202 -5.29665625
[9] 14.58416434 -10.26407825 -0.38298306 9.68359676 4.69801377 -5.56192103 -3.69575835 -1.80644340
[17] 7.54074150 -1.26766743 1.69960924 -0.05477233 12.74446027 -6.91351507 -3.77997964 3.49481900
[25] 8.52869090 -7.64449818 5.65821084 5.37133672 6.23783335 -0.68393638 2.74329582 3.95683297
[33] 10.16288242 2.57817333 4.87056251 11.57460530 0.85343818 -1.08646633 7.49685073 5.63716107
[41] 6.63389699 10.76110329 -3.18185577 17.23960534 -4.17540928 6.10086215 -1.62419138 -13.54267004
[49] -12.84662984 3.44977437 1.10565345 14.63311473 -0.66745954 8.22051018 -10.00890839 6.67662458
[57] 0.15553497 -2.25281457 14.41684225 3.82597024 -2.41416476 1.25714579 2.97077074 -10.93705188
[65] 2.44530992 -6.04835129 7.08330906 -9.03129416 -11.75221600 -1.23798122 14.73544751 -10.79708118
[73] 4.91834166 2.62268697 0.19673455 1.92743096 -1.75442018 2.09497450 1.71531088 -10.00612174
[81] 1.71351570 -6.77979014 -3.74746632 -8.58945460 -6.69462379 -7.31852659 -4.11877735 3.54683228
[89] 7.95031281 -7.26586080 7.72670303 8.60268781 15.32667352 9.51128290 -6.64012613 -0.98465636
[97] 12.26306255 0.58129585 3.78824756 -7.79111530 10.67262967 13.39322070 5.93386743 0.87964269
[105] 0.78955426 2.48048392 2.41336610 -6.44482492 9.77851677 7.77989168 6.26357759 2.48980982
[113] -10.52635027 -4.19324012 6.32044863 10.02532854 -7.81897539 8.25886110 5.54820785 7.59557404
[121] -15.72952770 0.94476781 2.43781004 -0.88073160 -0.18905809 0.59151803 3.94046135 6.79304640
[129] 6.80315174 15.94885422 -0.15272643 -3.68360719 -1.97309568 -2.55890790 -2.97709430 -2.49659357
[137] 6.78013354 -3.47770311 -1.47499722 -14.34004051 1.42927657 -0.37343395 -3.44763088 -0.06907991
[145] -2.80994277 4.50918683 -10.21487857 6.58983913 3.37633286 -7.44911943 -1.23155143 -1.86029752
[153] 1.72071118 -10.31663976 -9.64571863 9.94552569 4.54701980 -1.29770310 7.73668330 9.79467873
[161] 5.27999967 -0.59131107 -10.15356791 1.23140305 5.61020119 17.94693670 -5.45729062 -6.29272679
[169] 6.52545856 -3.54229047 1.59897528 -0.58972514 6.31460377 -1.91215560 -16.89611552 7.72738901
[177] 0.49022830 11.43989438 -10.60249721 9.40631973 6.43934744 17.99818227 4.20984401 4.18473441
[185] 5.79432105 -2.37191262 6.03566936 3.04338817 0.28131175 -1.04985019 -1.67640434 9.23477735
[193] -1.90476654 2.07890718 4.51024858 -1.00347197 -3.56594407 -2.87567881 -8.39151306 4.58673768
[201] 4.87097396 -3.50985057 14.58628814 9.53451677 -0.72541330 0.73502162 8.75069065 3.07543486
[209] 2.65833232 10.40478016 -0.22377002 -0.67850200 0.54836036 13.27078881 12.37026093 4.77240845
[217] -9.79715472 2.18176971 13.37030880 -1.13437882 5.40325791 6.21713649 7.88703978 5.94779144
[225] -3.54178522 14.47819652 -4.42732301 -3.75080401 -3.08711997 2.74953860 7.27880609 14.54449819
[233] 5.95077287 0.02650757 7.86893781 -4.60375246 0.65043347 -5.18993595 2.27621043 11.06415296
[241] 6.16859284 9.88591121 -3.31481343 -7.51841480 6.46402563 2.44226095 1.16519575 -8.80656381
[249] -1.71491037 4.50123116 -9.06669338 2.22913650 11.23828171 1.28317743 -0.82473761 2.82965063
[257] 9.05142139 -5.88557061 8.41616639 -5.15354277 8.66256371 -3.23186644 -2.55641322 1.98640912
[265] -1.14309699 3.52633340 0.52438760 -2.03991946 2.14997042 -1.83232776 6.00238073 7.24164129
[273] 7.22894149 2.13634033 3.02902208 -2.64439090 -5.53673232 1.43280722 0.13210654 -7.09297371
[281] 6.94007527 -0.35471759 -2.45482592 15.23659520 -4.65872378 3.39005390 1.03803111 9.35135436
[289] 3.48710989 -10.90022022 4.09502754 4.02160804 0.14174438 8.66583384 7.87523490 -4.87811360
[297] -5.92763566 1.67593624 -3.08666488 -4.18738832 6.48846551 -7.47740522 -1.06252867 -6.44647509
[305] 12.87129539 2.27572142 -9.49847778 -1.79822569 5.03862376 -11.00436363 -3.22637406 -5.21098993
[313] 0.88044569 0.14069516 9.19351613 -1.93292108 9.30020328 5.87918430 -0.23538847 1.52403490
[321] 4.28056538 7.22721243 10.26201839 1.66494995 5.83450989 13.21162310 16.58162442 -9.13656473
[329] 3.26750963 -5.48230714 -8.58541865 -8.97214145 4.49002097 -5.11077991 -11.43586937 4.22744919
[337] -0.63435772 -1.77019273 -11.28237394 18.46640098 -1.53072748 5.01510695 -12.57633929 -10.30098671
[345] -4.77950997 7.81432702 -4.41247696 -7.52421573 4.49124467 1.19475131 8.78611964 5.21116743
[353] 22.72378944 -3.49078271 -0.81064260 5.72046608 -0.93196356 -1.22000744 4.77785245 -2.02298119
[361] 9.64291970 -0.76582927 7.18966287 -1.70744665 3.47507958 -2.19700242 -10.05296816 -9.07595556
[369] 10.03360123 3.42498539 3.25005501 9.94196983 -1.50650035 3.54254626 -2.13669595 4.82588806
[377] -1.79675574 7.82173509 -13.28846367 -7.55200689 -1.52059075 -2.84312085 1.23274879 9.76261020
[385] 0.74190388 2.31281582 7.89560460 11.69445679 8.33761076 9.85115594 -5.77819901 4.28988593
[393] 2.94140186 -1.35635782 -12.44422499 -0.10438567 9.95634489 -1.79665239 2.68684410 16.73628311
[401] -17.06419434 -8.25875650 -3.16087827 -6.04351119 6.67600811 -1.50412797 -7.89019789 0.14139412
[409] -10.35993263 -0.77142863 0.94728837 12.84479481 -10.43050120 2.63794300 10.31468465 4.12024472
[417] -1.18650053 0.16370811 -11.48124017 9.74339774 14.25142056 -5.07209051 7.66348476 5.69343275
[425] 12.27917525 -2.47840542 0.35295522 0.53236592 -5.72195971 -12.69977757 3.41272589 13.31569873
[433] 7.34624828 -0.03647776 -8.88160404 0.24072753 -5.68665848 -3.62966901 14.57034224 -6.22847950
[441] 8.35574930 -13.26389039 -13.37892824 -4.92663794 -2.78379351 7.25926623 -2.04545976 -15.48040277
[449] 8.58336577 -2.36757264 -0.45319416 6.53438791 -10.89698351 -14.46210290 -2.79754347 1.76786375
[457] 0.90570845 4.99809429 0.80594319 -10.36381577 9.13836202 -9.00067253 -10.16792515 6.65780899
[465] 8.96516489 -6.71424436 6.09464933 2.80655421 8.15977179 6.43129150 4.30559862 1.22216332
[473] 5.24736926 8.04974511 -2.99924715 13.89684519 6.61959572 4.73915458 -6.79439362 1.44902586
[481] 3.76817906 -3.02041974 4.17201106 10.39817260 -7.05288798 6.38828263 -0.68635231 -2.93603383
[489] 7.83679029 0.49909941 7.08283071 -4.26237920 6.30221922 -1.82557946 -1.68097240 2.03377488
[497] -11.17733820 -2.15435716 -2.39351632 1.69892599 -6.39503037 1.15216306 0.03483049 -1.73216082
[505] -0.62875691 9.93685198 6.85066666 -6.93811360 -5.62437257 4.71035800 9.40773434 0.47591032
[513] -0.81768956 4.40822267 13.79602885 5.95818735 -5.08083006 -0.49097132 5.72800140 -3.48560909
[521] 1.25362526 -12.97483408 -4.58656153 3.61474983 14.01071027 -3.34785798 4.78841025 -5.68497534
[529] 5.72952186 -3.00473182 -3.70721995 -9.02500368 3.29167466 -3.90137033 -9.75905216 -0.31790715
[537] -12.41998387 13.14444011 -5.76345506 -1.48315958 9.39834920 2.05755822 3.32244518 5.93616076
[545] -1.69806585 9.70757006 -7.05197736 6.21161010 1.75562925 -8.87560747 3.02736238 2.74307914
[553] -2.64888395 3.57716376 7.17703387 7.07440643 -11.26985394 0.86963294 -9.26931492 -2.20750940
[561] -7.01158543 9.09600948 1.64548716 2.16295753 1.67776436 0.18837243 10.48513115 3.50027153
[569] -5.07976259 -5.36416646 0.79525589 -6.54657832 -5.63112528 3.01788942 -3.19539131 -2.02931259
[577] 13.74819450 -10.58599667 4.70665586 -6.93907076 8.88534674 10.73850410 -1.21223585 -5.40750776
[585] -1.71814494 -2.67422379 5.28090932 0.46371028 -4.13272461 -7.69087903 9.61011192 2.08760263
[593] -3.19308461 5.51612490 -13.87887276 3.50965656 7.14788042 3.96221773 -0.53201006 -3.74329951
[601] -1.65010294 -2.71145279 -0.85182149 -7.28052350 10.25333079 3.45898643 0.90684134 6.92094505
[609] -0.99988309 10.80946636 5.46127058 2.77916764 8.11513093 14.08376439 -0.46571437 3.64065106
[617] 10.50896471 1.70380372 8.23075493 -7.78342665 -1.32630149 11.65158424 -1.51412854 3.87509932
[625] 7.41227536 1.67686144 -9.32031093 19.10704873 6.92212046 12.96014112 7.09593788 -2.20256316
[633] -1.04597655 6.12681920 -9.29310396 -2.70696401 -2.47574367 -10.62344136 -4.14292689 -1.23379145
[641] -2.37485513 1.17368279 -2.59392579 -10.97286961 -3.34546876 2.48052037 -6.56188184 5.02095656
[649] 3.78390442 -5.01167829 -13.97627767 -15.05615480 -1.67414650 4.22628158 13.56177081 -0.96334249
[657] 13.04485145 -3.28682755 7.83058022 6.32420646 -0.23723057 1.27146907 12.56194255 7.31440082
[665] -2.26592346 7.71357270 -4.37377914 2.86937179 -4.65034276 -0.64213139 -1.61953216 3.66755868
[673] 4.10565372 0.34046343 7.64616863 7.73795788 9.76151718 3.62461536 -9.83464434 -0.71883996
[681] 2.40132677 -3.69099217 -1.70776094 4.14211983 7.33311756 -9.07322144 -0.33962699 1.49670902
[689] -4.93186907 0.18967789 7.64293596 9.84422973 -4.10994002 -2.13407835 1.61676741 0.07692103
[697] -8.98517706 3.68303139 7.27645082 6.21921923 -8.27547941 -0.45087655 -5.65905363 -7.87916712
[705] 7.30992922 4.42734721 9.47533291 -8.80224266 2.12810672 -4.18362733 3.32237481 2.01907666
[713] 3.40208542 17.92273829 11.51997712 -1.06941469 -0.87078125 -0.23781399 -6.26558043 4.47654525
[721] 3.42970400 -8.10009005 -2.87803952 1.41393149 7.59341015 11.29377409 -6.25412859 -4.15597636
[729] 6.83968547 1.01639203 8.73674154 10.62758406 5.69176831 -2.27613128 10.93363175 -8.29558529
[737] -10.48303524 -3.30454643 -9.99156223 -10.73084961 -0.15566251 -9.64869871 13.45497180 -6.22418095
[745] 12.97240133 -10.94336750 3.83625592 7.05561567 5.64045504 -4.92660406 7.63121271 17.63196679
[753] 13.03408201 -4.37677981 10.63230833 1.69226861 -11.87405357 1.32362737 -2.54317929 15.62524329
[761] 9.00863426 3.99422129 1.94833908 8.22045873 10.79714962 9.34213588 2.03037560 -7.22218954
[769] 2.07118651 4.88631825 1.21861641 -9.18382471 2.57134484 -2.26840272 4.05635192 6.27406294
[777] 1.05493718 5.32240870 4.81765267 8.38202693 -9.15981930 -0.15178333 -1.23344099 -8.38711446
[785] 2.60067610 -9.67664863 1.50218409 2.21564642 5.90805944 7.62100737 -3.53669472 6.09086322
[793] -1.57680310 7.82898136 -1.23894453 5.32447452 4.55262864 11.04838765 -10.92217848 -3.61914315
[801] -1.56743580 0.47478694 -0.65019773 -2.50891345 -5.05025230 -6.95804117 13.76636616 -1.68847712
[809] -6.32430710 1.46909093 0.57130122 -10.34733316 8.76634580 0.29123415 7.96871930 5.24546564
[817] 6.65325243 0.55808494 8.80266570 4.49902980 -1.84770676 8.62810163 6.99692868 -4.85365465
[825] 0.83052143 1.45089184 -4.02632613 -4.30813781 2.97293870 -2.21330332 0.32192431 0.98152824
[833] 11.37447313 4.15934119 1.72628276 10.89963556 12.50330113 0.68229873 -13.07975534 -7.48761661
[841] -0.96777422 -13.39745331 3.28503440 11.82310520 -2.69874621 0.22163759 12.33967883 -11.96780682
[849] -8.00733058 0.54725979 13.08203836 -3.30420768 -16.88861036 1.98953958 -4.00865764 4.19521257
[857] -2.68452273 0.89075393 5.82322516 15.33832473 7.27087116 -12.24085930 -2.42111593 6.88106227
[865] -3.83945193 9.10039317 -11.79277799 8.20669045 -6.00758538 0.82644966 10.83315561 -2.18004012
[873] 3.65015284 -15.31763294 0.97273829 2.55679854 8.26181224 -1.91165324 -8.64084048 6.64817584
[881] 9.62235591 0.24307286 -4.27539379 -0.34162336 -2.80680752 3.07128833 12.62002629 11.67951660
[889] -5.75018726 -9.47505243 9.18658100 -15.30069032 -6.34093708 1.62257992 0.55361834 -1.52059412
[897] -0.99099398 0.37302770 13.08786332 2.72426236 -3.41592162 6.49617011 -6.63946448 7.33411276
[905] 11.05999902 -11.25884541 -7.21247828 10.03741969 11.15505475 6.63270894 2.10376819 -5.59970972
[913] 5.51266641 9.37971177 -3.62026436 9.35003260 3.67616133 0.51623050 -3.71921789 -5.06934035
[921] 0.51655800 -1.90036037 4.15476293 7.65904556 3.73896701 -2.67212876 -9.30221491 8.41671128
[929] 13.31916746 0.64912195 1.36959741 17.51175590 0.43640731 -6.79700969 3.57839119 1.50001785
[937] 7.92471900 0.71085119 8.87108965 8.38504859 -0.89892388 6.71333611 4.61010346 -1.06896003
[945] 3.19091571 -10.60160379 -3.95080508 -10.31614638 -2.94751200 -8.35453628 3.70880434 -4.26927971
[953] 12.06159547 0.68716443 7.05664210 4.36970757 9.09596325 10.63067485 6.02614779 -6.89001925
[961] 2.82154224 -3.19226021 5.65693271 24.88874424 8.48844268 -1.72452236 8.32993002 -9.58459807
[969] -3.99213787 7.56127647 2.14839841 3.15493757 1.58399242 -16.33807069 1.26360864 3.50265113
[977] 3.25993002 0.98683814 -3.86918732 6.11763202 7.89275037 6.62188718 6.82165740 2.02479599
[985] -4.27377603 -2.84256107 0.87996785 -6.99016871 4.60412896 -3.86796995 3.68061693 0.11297960
[993] -9.65797067 -0.41813531 -3.83106991 -13.97935872 10.03093830 2.34678933 14.25236568 5.59998646
hist(pd2)
Similarly we should be able to compute various probability senarios with our obtained normal distribution.
##### 1F) Calculate the probability that returns will be negative using the values for mean and standard deviation as in 1E
pnorm(0, mean = 1.2, sd =3.7)
[1] 0.3728463
##### 1G) Repeat the calculation in 1F using instead the standard Z-value. Share insights.
qnorm(0.37)
[1] -0.3318533
pnorm(-0.33)
[1] 0.3707
As noted from the calculations, the probability from mean and standard deviation yields 0.373, where from the z-score the probability is 0.371. It shows that the values yielded for the probability are relatively close.
Follow the Algorithm 5.2 example on p 167 (*) to calculate the price of a European option using a MC simulation. Note that the code in the book example is missing one detail and a correction. Those are left for your investigation.
##### 2A) Identify and explain the nature of the missing detail and the correction needed.
Between instructions 2 and 3, the stock price needs to be reset to 100. There needs to be a line that reads: S = S_0 = 100, so that the new simulated path starts on the initial value and not on the previously computed path’s final value.
Given the MC simulation we should be able to price a European option. Note the introduction of user defined function in the book. Below is an example of a user defined function and usage. The function returns the squared value.
myfunction <- function(x=2){
y=x^2
return(y)}
myfunction(x=5)
[1] 25
##### 2B) Use MC simulation to price a European Call option on a stock with initial price of $155, strike price $140, a time to expiration equal to six months, a risk-free interest rate of 2.5% and a volatility of 23%. Consider a number of periods n=100 and a number of simulations m=1000
stock=155
sigma=0.23
strike=140
TTM=0.5
rf=0.025
num.sim<-100000
R<-(rf-0.5*sigma^2)*TTM
SD<-sigma*sqrt(TTM)
TTM.price<-stock*exp(R+SD*rnorm(num.sim,0,1))
TTM.call<-pmax(0,TTM.price-strike)
PV.call<-TTM.call*(exp(-rf*TTM))
mean(PV.call)
[1] 20.15908
##### 2C) Write the mathematical representation of the discrete pricing equation modeled in the MC simulation. Explain what each variable in the equation represents, and provide the associated numerical value. \[V_{MC}(S,t) = e^{{-r_t}{T-t}}*1/M \sum_{i = 1}^{M}max[0, \phi(S_{T} -K)]\] where S_ T is attained after N time steps that coincide with the expiry time T. S_T is therefore simulated M times to obtain the average option value V_MC .N is the number of time steps and M the number of simulations.r_t is the risk free rate and phi is the volatility.
##### 2D) Compare the price obtained from the MC simulation to the option price using the Black-Scholes function pricing GBSOption(). Share insights.
library(fOptions)
Loading required package: timeDate
Loading required package: timeSeries
Loading required package: fBasics
GBSOption(TypeFlag = "c", S = 155, X = 140, Time = 1/2, r = 0.025, b = 0.025, sigma = 0.23)
Title:
Black Scholes Option Valuation
Call:
GBSOption(TypeFlag = "c", S = 155, X = 140, Time = 1/2, r = 0.025,
b = 0.025, sigma = 0.23)
Parameters:
Value:
TypeFlag c
S 155
X 140
Time 0.5
r 0.025
b 0.025
sigma 0.23
Option Price:
20.11899
Description:
Fri Feb 1 14:34:37 2019
As the above output shows, the Black-Scholes call option value is $20.12, which is pretty close to the MC call option value of $20. Both models yield fairly similar results.