Assume the dollar amount of damage involved in an automobile accident is an exponential random variable with a mean of 1000. Of this, the insurance company only pays the amount exceeding the deductible of 400. If X is a random variable representing the dollar amount of damage, then the insurance payout is max(X-400,0).
I am trying to use scipy's quad function to evaluate the integral between 0 and infinity of max(x-400)
Here is the link to better visualize : https://i.sstatic.net/SRFae.jpg
I need to verify the answer of 670.32 using Monte carlo simulation, and I believe I need to use numpy's .random.exponential function to draw 10,000,000 samples of X.
As mentioned, I am trying to use scipy's quad to define the integral, but where I am struggling is how to incorporate the repeated number of loops such that X is drawn 10,000,000 times. I would expect a for loop to be extremely inefficient, so believe broadcasting using matrix manipulation may be a more efficient solution. Unfortunately, this is beyond my level of programming experience and could really use some help with how to one: efficiently gather samples of X, and then 2, incorporate it into a function that is evaluating the integral of X, storing it in some data structure, and repeating the process 10,000,000 times
from scipy.integrate import quad
from numpy import exp, log, inf
import numpy as np
exponential_var=np.random.exponential(1,10000000)
def Expected_Payout(x):
return max(exponential_var - 400,0)
v,b = quad(Expected_Payout, 0 ,inf )
How do I define my function to take an exponential number of variables and store them to repeat the process?
The result should be ~= 670.32
I think your doing too much.
import numpy as np
a = np.random.exponential(1000., size=10000000)
np.maximum(a-400, 0).mean()
Out[13]: 670.3739442241515
If you are doing the sampling I don't think you need to integrate.