Apakaļ pie Kurss

Monte Carlo Methods in Finance Engineering

0% Pabeigts
0/0 Soļi
  1. Course Introduction

    Introduction
    2 Topics
    |
    1 Tests
  2. Lesson 1. Linear Congruental Generator
    2 Topics
    |
    1 Tests
  3. Lesson 2. Normally Distributed Random Variables and Vectors Generation
    2 Topics
    |
    1 Tests
  4. Lesson 3. Integral Estimation.
    2 Topics
    |
    1 Tests
  5. Lesson 4. Expected Present Value
    1 Tests
  6. Lesson 5. Brownian motion. Geometric Brownian motion
    2 Topics
    |
    1 Tests
  7. Lesson 6. GBM. Path-Dependent Options
    1 Tēma
  8. Lesson 7. The effectiveness of simulation evaluation
    2 Topics
    |
    1 Tests
  9. Lesson 8. Variance reduction methods
    3 Topics
    |
    1 Tests
  10. Lesson 9. Introduction to RTU High Performance Computing (HPC) Environment
Nodarbība Progress
0% Pabeigts

Please try to solve all the integrals in the presentation tasks and draw conclusions about the required number of simulation runs:

from numpy import random, sqrt
from scipy.integrate import tplquad

b1=11/10
a1=0

b2=1
a2=0

b3=9/10
a3=0


def integrand(z, y, x):
    return 4-x**2-y**2-z**2

parbaude=(tplquad(integrand, a1, b1, a2, b2, a3, b3))

def integret(n):

    RND1=random.rand(n)

    RND2=random.rand(n)

    RND3=random.rand(n)

    y=[]
    m=0
    for u in RND1:
        u1=u*b1
        u2=RND2[m]*b2
        u3=RND3[m]*b3
        y.append(4-u1**2-u2**2-u3**2)
        m+=1



    REZ=((b1-a1)*(b2-a2)*(b3-a3)/n)*sum(y)

    sn=[]
    m=0
    for u in RND1:
        u1=u*b1
        u2=RND2[m]*b2
        u3=RND3[m]*b3
        sn.append(((4-u1**2-u2**2-u3**2)-REZ)**2)
        m+=1

    Sd=sqrt(sum(sn) / (n * (n - 1))) * ((b1 - a1) * (b2 - a2) * (b3 - a3))
    print("\n")
    print('%-50s %-17.i' % ("Genereto punktu skaits", n))
    print('%-50s %-17.8f' % ("Integrala aprekinata vertiba:    ", REZ))
    print('%-50s %-17.8f' % ("Aprekinata integrala standartnovirze:    ", Sd))
    print('%-50s %-17.8f' % ("Scipy ieguta integrala vertiba:  " ,parbaude[0]))
    print('%-50s %-17.8f' % ("Starpiba starp aprekinato un scipy ieguto:   ", abs(REZ-parbaude[0])))
    stat=[n, abs(REZ-parbaude[0])]
    return stat


salidz=[]
salidz.append(integret(1000000))

salidz.append(integret(10000))

salidz.append(integret(100))

print("\n")
print('%-20s %-17s' % ("n", "Atskiriba no scipy"))
for dati in salidz:
    print('%-20.i' % dati[0], '%-17.8f' % dati[1])