Ejemplo n.º 1
0
	def analy(self,N_o):
		''' Analytical solution
		'''
		# --- portfolio loss distribution @ t = \tau via analytical formulas ---
		opt_val = lambda S: 5.*bp.blsprice(S,self.K,self.rfr,self.T-self.tau,self.sigma,'put') \
							+ 10.*bp.dnOutCall(S,self.K,self.rfr,self.T-self.tau,self.sigma,self.H)

		#ran1 = npr.multivariate_normal(np.zeros(self.D),np.eye(self.D),N_o)
		#ran1 = npr.standard_normal((N_o,self.D))
		ran1 = norm(loc=0,scale=1).ppf(lhs(self.D,samples=N_o))
		S1 = np.zeros((N_o,self.D))
		S1[:,:] = self.S0
		S1[:,:] = S1[:,:] * np.exp((self.mu - 0.5 * self.sigma**2) * self.tau\
				 + self.sigma * np.sqrt(self.tau) * ran1[:,:])

		ValueTau = np.zeros(N_o)
		for n in range(N_o):
			for d in range(self.D):
				ValueTau[n] += -opt_val(S1[n,d]) + S1[n,d] * self.delta[d]

		L_analy = np.sort(self.Value0 - ValueTau)
		#L_analy = np.sort(-ValueTau + self.Value0 * np.exp(self.rfr*self.tau))
		print L_analy
		var = scs.scoreatpercentile(L_analy, self.perc*100.)
		eel = np.mean(np.maximum(L_analy-var,0))
		return (var, eel)
Ejemplo n.º 2
0
from scipy import linalg
import tools_benchmark as fun
from tools_doe import trans
import doe_lhs

# Initialization of the problem
dim = 10
ndoe = 10 * dim

# Upper and lower bounds of the problem
xlimits = np.zeros((dim, 2))
xlimits[:, 0] = -10
xlimits[:, 1] = 10

# Construction of the DOE in [0,1]
xt = doe_lhs.lhs(dim, ndoe, 'm')

# Transform the DOE in [LB,UB]
xt = trans(xt, xlimits[:, 0], xlimits[:, 1])

# Compute the output (+ the gradient)
yt, yd = fun.carre(xt)

# Construction of the validation points
ntest = 500
xtest = doe_lhs.lhs(dim, ntest)
xtest = trans(xtest, xlimits[:, 0], xlimits[:, 1])
ytest, ydtest = fun.carre(xtest)

########### The LS model
Ejemplo n.º 3
0
import MOE.function as fct
import numpy as np
import csv
import doe_lhs as doe


func = lambda x:fct.test_1D(x)

dim = 1
n_train = 20

## Training points

Max = 1*np.ones(dim)
Min = 0*np.ones(dim)


X_train = doe.lhs(dim,samples=n_train)
X_train = doe.lhs_maximinESE(X_train)
for i in range(len(X_train)):
    for j in range(len(X_train[0])):
        X_train[i][j] = Min[j]+X_train[i][j]*(Max[j]-Min[j])
    print i
Y_train = func(X_train)
fichier = open("DONNEES/test_1D_20.csv",'a')
csvwriter = csv.writer(fichier)
val = np.c_[X_train,Y_train]
csvwriter.writerows(val)
fichier.close()