コード例 #1
0
ファイル: my_option.py プロジェクト: athosprv/Monte-Carlo-HA
#   Our custom option for stock XXX.
def current_option(history,params):
    #   If within the 60 first days price has gone over $105 we return 3.
    for i in range(60):
        if(history[i]>105): return 3
    #   If the stock at expiration is between $101 and $105 we return 1.
    if 105>=history[-1]>=101: return 1
    #   If the stock at expiration is over $105 we return 2.
    elif history[-1]>105: return 2
    else: return 0

#   Variables are initialized here.
params=Storage()
params.mu = 0.03/300 # avg daily return.
params.sigma = 0.2/sqrt(300) # avg daily volatility.
params.S = 100.0 # today's stock price.
params.option=current_option
params.T = 120 # time to expiration.
params.r_free = 0.04/300 # avg daily risk free rate.

params.dt = 1.0 # simulation step.

#   StockSimulator Object is initialized.
s = StockSimulator(params)

# Plotting is disabled for the purpose of this program.
#plot(dict(data=[x for x in enumerate(r)]))

#  Simulating to get the price for different volatility values or absolute precision.
#   Run times for program are slightly faster when commented out.
コード例 #2
0
ファイル: fp.py プロジェクト: athosprv/Monte-Carlo-HA
                claim_chance = randint(1,3650)                
                if claim_chance==1:                
                    balance -= lognormvariate(mu,sigma)
                    self.num_claims+=1
                    drivers_claimed+=1
            drivers-=drivers_claimed
        
        #print total_balance
        #self.num_claims = 0
        self.u.append(balance);
       
        return balance

params=Storage()
params.mu = 5
params.sigma = 2.1
params.T = 365 # time to expiration.
params.dt = 1.0 # simulation step.
params.num_drivers = 10000 # Number of total drivers.
params.total_balance = params.num_drivers*150 # Value of the total Premiums.


h = HealthInsuranceSim(params)

print 'Problem 1: Average Total Annual profit', 1500000 - exp(5.0 + ((2.1)*(2.1))/2)*1000
print 'Problem 2:', h.simulate_many(absolute_precision = 0.1 , max_iterations= 2)
print 'Claims: ', h.num_claims

print 'Problem X: Better Average Total Annual profit', 1500000*2 - exp(5.0 + ((2.1)*(2.1))/2)*h.num_claims

#print (75000000 - 47318* exp(5.0 + ((2.1)*(2.1))/2))/50 # 226062.512079