I wrote a function that uses Monte Carlo Simulation using flipping a coin to calculate the value of the call option in Mathematica. I want to apply the function to 63 rows of my dataset that contain the real data. In other words, I want the function uses the values of each row for its variables I can put values for variables of the function, but it takes time to do that for a large number of data
ClearAll[S, M, K, k, \[CurlyEpsilon], n, H, T, \[CapitalDelta]t]
Array[S, {365, 1000}]
Array[M, 1000]
For[k = 1, k < 1001, k++,
S[1, k] = S0; \[Mu] = 0.0168; \[CapitalDelta]t = T/n; T = 1/365;
n = 365; \[Sigma] = sigma;
For[n = 1, n < 365, n++, \[CurlyEpsilon] = 2 RandomInteger[] - 1;
S[n + 1, k] = 135.95
Sqrt[\[CapitalDelta]t] \[CurlyEpsilon] \[Sigma] S[n,
k] + \[CapitalDelta]t \[Mu] S[n, k] + \[CapitalDelta]t \[Mu] S[
n, k] + S[n, k]]; M[k] = S[365, k]]
Array[P, 1000]
P[1] = 0
For[k = 1, k < 1001, k++,
P[k + 1] =
P[k] + 1/((1 + \[Mu]*T/(365*365))^365)*1/1000*Max[M[k] - 140, 0]
]
Print[P[1000]]
The values that I want to use frequently are: K as my strike price(here is 140)
S0 as my price of stock here( S[1, k]= 135.95
tau as my time to maturity here as (T=1/365)
sigma as my volatility here as (sigma)
r as my risk-free rate here as([Mu=0.0168])
this is the data I want to use:
tau r sigma S0 K
0.00273973 0.0168 0.2564 135.59 140
0.00547945 0.016 0.3546 134.56 140
0.00821918 0.0165 0.2227 134.41 140
0.0109589 0.0154 0.225 134.22 140
0.0136986 0.0152 0.2043 134.13 140
0.0219178 0.0156 0.1747 134.21 140
0.0246575 0.0175 0.1626 135.32 140
0.0273973 0.0159 0.1717 133.76 140
0.0328767 0.0176 0.1659 133.91 140
0.0410959 0.0177 0.1599 133.92 140
0.0410959 0.0167 0.1472 133.22 140
0.0438356 0.0154 0.1628 131.91 140
0.0465753 0.0176 0.1625 131.99 140
0.0493151 0.0176 0.1701 132.12 140
0.0520548 0.0176 0.1628 132.91 140
0.060274 0.0178 0.1449 134.45 140
0.0657534 0.018 0.1421 133.77 140
0.0684932 0.0177 0.1387 135.09 140
0.0712329 0.0179 0.1423 135.97 140
0.0794521 0.018 0.1442 134.34 140
0.0821918 0.0185 0.1553 133.84 140
0.0849315 0.0177 0.1561 133.2 140
0.0876712 0.0178 0.1487 134.52 140
0.090411 0.0184 0.1452 134.31 140
0.0986301 0.0169 0.1422 134.4 140
0.10137 0.0173 0.1508 134 140
0.10411 0.0192 0.1548 134.48 140
0.106849 0.0182 0.1501 135.59 140
0.109589 0.0184 0.151 135.47 140
0.117808 0.0178 0.1548 137.61 140
0.120548 0.0183 0.1567 137.69 140
0.123288 0.0177 0.1174 138.78 140
0.126027 0.0177 0.1284 137.89 140
0.128767 0.0174 0.1281 137.67 140
0.136986 0.0192 0.1308 135.53 140
0.139726 0.0181 0.1411 133.73 140
0.142466 0.0181 0.1365 135.25 140
0.145205 0.0194 0.142 133.82 140
0.147945 0.0176 0.1315 135.97 140
0.156164 0.0177 0.133 135.44 140
0.158904 0.0193 0.1336 134.07 140
0.161644 0.0179 0.1414 134.38 140
0.164384 0.0188 0.1423 133.96 140
0.167123 0.0186 0.1411 132.58 140
0.175342 0.0177 0.1446 134.09 140
0.178082 0.0173 0.1377 134.26 140
0.180822 0.018 0.2 142.11 140
0.183562 0.0179 0.1975 143 140
0.186301 0.0184 0.2036 142.04 140
0.194521 0.019 0.208 142.76 140
0.19726 0.0183 0.219 141.13 140
0.2 0.0177 0.2242 139.67 140
0.20274 0.0172 0.2336 138.38 140
0.205479 0.0185 0.2188 141.28 140
0.213699 0.0192 0.2182 142.99 140
0.216438 0.0189 0.2313 142.02 140
0.219178 0.0189 0.2402 141.69 140
0.221918 0.0192 0.2246 143.66 140
0.224658 0.0192 0.2186 145.42 140
0.232877 0.0192 0.2214 143.24 140
0.235616 0.0192 0.2117 143.55 140
0.238356 0.0192 0.2108 143.16 140
0.241096 0.0182 0.2138 141.68 140