Page 1 of 1

Hello, I need homework on Python, and please help me with the blanks under the picture. import numpy as np import math d

Posted: Fri Apr 29, 2022 6:34 am
by answerhappygod
Hello, I need homework on Python, and please help me with
the blanks under the picture.
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 1
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 1 (70.31 KiB) Viewed 20 times
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 2
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 2 (50.99 KiB) Viewed 20 times
import numpy as np
import math
def randomSum(averageClaimSize, j):

## Write your own code here

return sampleSum
## Test your function
randomSum(1500,20)
def simulatorConditional(averageClaimSize, j, M):
## Write your own code here

return samples
## Test your function
simulatorConditional(1500,20,10)
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 3
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 3 (61.71 KiB) Viewed 20 times
def simulator(averageClaimSize, Poissonparameter, M):
## Write your own code here

return samples
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 4
Hello I Need Homework On Python And Please Help Me With The Blanks Under The Picture Import Numpy As Np Import Math D 4 (56.55 KiB) Viewed 20 times
def MCprobEstimation(averageClaimSize, averageNumberOfClaims, K,
M):
## Write your own code here

return empiricalProb
## Test your function
MCprobEstimation(1500, 20, 20000, 10)
print(MCprobEstimation(1500, 20, 30000, 100))
print(MCprobEstimation(1500, 20, 30000, 1000))
print(MCprobEstimation(1500, 20, 30000, 10000))
print(MCprobEstimation(1500, 20, 45000, 100))
print(MCprobEstimation(1500, 20, 45000, 1000))
print(MCprobEstimation(1500, 20, 45000, 10000))
A stochastic model for a car insurance company's total cost of damages from traffic accidents goes back to the work by Van der Lann and Louter, "A statistical model for the costs of passenger car traffic accidents", Journal of the Royal Statistical Society (1986). For every k = 1.2, 3 ... We denote by the random variable X the US dollar amount of a damage from a policy holder's traffic accident which will occur during the year 2022 We assume that X1, X2.... is an i.i.d. (independent and identically distributed) sequence of exponentially distributed random variables with an average claim size of 1,500 USD. The (random) total number of accidents N in 2022 is assumed to be Poisson distributed with a claims on average It is assumed that the number of accidents is independent of the US dollar amount of damages for each accident. That is, the random variable N is independent of the random variables X1, X2... The total costs for the insurance company by the end of 2022 will thus be given by the random sum SN:= X1 + X2 + ... +XN= XX. Note that the total number N of accidents is random! The goal of the current exercise is to approximate via simulation: • the conditional expected total costs E[SNIN = 1] for the insurance company in 2022 given that the number of claims is equal to j, and • the expected total costs ETSN for the insurance company in 2022, and • the probabilities that the total cost will not exceed K USD, i.e. PISY SK] for K = $30,000, and K = $45.000 As usual, we start with loading some packages:
As usual, we start with loading some packages: In [ ]: import numpy as np import math Step 1: First, write a function randomSum() which simulates from the distribution of Sy given that N = /. The output should just be a single scalar! Hint: Use proper build-in functions from the NumPy-package in your code in order to sample from an Exponential distribution (check out the Getting Started python file): In [ ]: def randomSun( averageclaimSize, i): ## Write your own code here return sampleSum In [ ]: #* Test your function randomSum(1500,20) Step 2: Write a function simulatorConditional() which uses the function randomSum() to simulate ME \ samples from the distribution of Sy given that N = ; The output should be an array of length M. In [1]: def simulatorConditional(averageclaimsize, j, M): ## Write your own code here return samples In [ ]: # Test your function simulatorConditional(1500,20,10)
Step 3: Use your simulatorConditional() function to approximate the conditional expectation ELS IN = ] for j = 10 and j = 20 For this, you generate with your function simulatorConditional() a bunch of M = 1,000 independent realizations (samples) 5.5 ... ) with the distribution of Sn given N = 7. Then you can approximate: $j. 1,500 = E[SN|N = ] M 1 M =1 and check the accuracy of this approximation In [ ]: ## Here comes your code Step 4: Write another simulator function which again uses the function randomSum( ) to simulate M E N samples now from the unconditional distribution of Sy. You will need to write a function simulator() that passes Poisson distributed random numbers into the second argument of randomSum() now. The output of the function simulator() should be an array of length M. In [ ] Ndef simulator(averageclaimSize, Poissonparameter, M): ## Write your own code here return samples Step 5: We now assume that the average number of claims per year is 20 and therefore choose i. = 20. As you are seeing in the homework, it holds via the so-called Wald's Identity that the expectation of the random sum Sy is actually given by the formula E[SN] = E[N] · E[X]]= 20 - $1.500 = $30,000. Check via the empirical mean that
Check via the empirical mean that $30.000 = E[N] where S... an denote M independent realizations (samples) from the random variable Sp. Use M = 5000 simulations. In [ ]: ## Here comes your code Step 6: Recall from class that the desired probabilities P[SY SK]for K = $30,000, and $45,000can be computed as expectations via an indicator function P[SN <K] = E[14SxxK)] We use once more the empricial mean to approximate M 1 E[115eky P=1 with M independent realizations (samples) from the random variable Sy (again denoted by s. Write a function MCprobEstimation() which estimates the probabilities P[SN SK] for K = $30,000, and K = $45,000as described based on 11 simulations of Sn. The output should be a real number in [0,1] In [ ]: Ndef McprobEstimation(averageclaimSize, averageNumberOfClaims, K, M): ## Write your own code here return empiricalProb In [ ]: # Test your function MCprobEstimation(1500, 20, 20000, 10)
1 E[1 SEK) Σουβλάκι with M independent realizations (samples) from the random variable S (again denoted by ,,....) Write a function MCprobEstimation() which estimates the probabilities P[S'N SK]for K = $30,000, and K = $45,000as described based on M simulations of Sn. The output should be a real number in [0, 1]: In [ ]: def MCprobEstimation(averageclaimSize, averageNumberOfClaims, K, M): ## Write your own code here return empiricalProb In [ ]: ## Test your function MCprobEstimation(1500, 20, 20000, 10) Test your function with varying M = 100, 1000, 10000simulations: In [ ]: print(MCprobEstimation(1500, 20, 30000, 100)) print(MCprobEstimation(1500, 20, 30060, 1000)) print(MCprobEstimation(1500, 20, 30000, 10000)) In [ ]: N print(MCprobEstimation(1500, 20, 45000, 100)) print(MCprobEstimation(1500, 20, 45000, 1000)) print (MCprobEstimation(1500, 20, 45000, 10000))