예제 #1
0
    def testEuropeanThetaFixedRandomNumbers(self, mock_np_random):

        # This test, uses patch to fix the random numbers generated for
        # the monte carlo, hence ensureing a fixed theta and then ensures
        # the result received is consistent.   The theta isn't very
        # accurate because we only use 200 points in the list but the result
        # should be stable (unlike testEuropeanThetavsExternal)

        # Convert the spot into an array
        npStock = np.asarray(ED.EO_spot, dtype=np.float32)

        # Get the price
        (npC, stdDevC) = self.__objEuropeanMonteCallFN.getOptionTheta(npStock)
        (npP, stdDevP) = self.__objEuropeanMontePutFN.getOptionTheta(npStock)

        lstCall = list(npC)
        lstPut = list(npP)

        lstCall = [
            abs(lstCall[i] - ED.FN_CALL_THETA[i])
            for i in range(0, len(lstCall))
        ]
        lstPut = [
            abs(lstPut[i] - ED.FN_PUT_THETA[i]) for i in range(0, len(lstPut))
        ]

        for Z in lstCall:
            self.assertLess(Z, ED.FN_ACCURACY)
        for Z in lstPut:
            self.assertLess(Z, ED.FN_ACCURACY)
예제 #2
0
    def testEuropeanRhovsExternal(self):

        # These values have been generated externally via the following
        # website:
        # https://www.math.drexel.edu/~pg/fin/VanillaCalculator.html

        # Convert the spot into an array
        npStock = np.asarray(ED.EO_spot, dtype=np.float32)

        # Get the price
        (npC, stdDevC) = self.__objEuropeanMonteCall.getOptionRho(npStock)
        (npP, stdDevP) = self.__objEuropeanMontePut.getOptionRho(npStock)

        # This is a very approximate comparison, because we are using a
        # monte carlo method
        for i in range(0, len(ED.EO_spot)):
            # Call - I change my rho by 0.01, (1%) so adjust here
            diffCall = abs(npC[i] - 0.01 * ED.EO_callRho[i])
            self.assertLess(diffCall, 0.1 * stdDevC[i])
            # Put - I change my rho by 0.01, (1%) so adjust here
            diffPut = abs(npP[i] - 0.01 * ED.EO_putRho[i])
            self.assertLess(diffPut, 0.1 * stdDevP[i])
예제 #3
0
    def testEuropeanThetavsExternal(self):

        # These values have been generated externally via the following
        # website:
        # https://www.math.drexel.edu/~pg/fin/VanillaCalculator.html

        # Convert the spot into an array
        npStock = np.asarray(ED.EO_spot, dtype=np.float32)

        # Get the price
        (npC, stdDevC) = self.__objEuropeanMonteCall.getOptionTheta(npStock)
        (npP, stdDevP) = self.__objEuropeanMontePut.getOptionTheta(npStock)

        # This is a very approximate comparison, because we are using a
        # monte carlo method
        for i in range(0, len(ED.EO_spot)):
            # Call - I express theta in 365 day terms and as a largely
            # negative value so change here
            diffCall = abs(npC[i] + ED.EO_callTheta[i] / 365)
            self.assertLess(diffCall, 0.1 * stdDevC[i])
            # Put - I express theta in 365 day terms and as a largely
            # negative value so change here
            diffPut = abs(npP[i] + ED.EO_putTheta[i] / 365)
            self.assertLess(diffPut, 0.1 * stdDevP[i])