def get_delta_greeks(self, otype, round_digit=4):
        if otype == OptionType.CALL:
            delta = exp((self.cost_of_carry - self.rate) * self.expiry) * cdf(self.get_d1_d2()[0])
        elif otype == OptionType.PUT:
            delta = exp((self.cost_of_carry - self.rate) * self.expiry) * (cdf(self.get_d1_d2()[0]) - 1)
        else:
            raise OptionTypeError

        return round(delta, round_digit)
Example #2
0
    def get_option_price(self, otype, round_digit=4):

        # This is the generalized Black_Scholes formula
        d1, d2 = self.get_d1_d2()

        if otype == OptionType.CALL:
            price = self.spot * exp(
                (self.cost_of_carry - self.rate) * self.expiry) * cdf(
                    d1) - self.strike * exp(-self.rate * self.expiry) * cdf(d2)
            #price = self.spot * exp((self.cost_of_carry - self.rate) * self.expiry) * norm.cdf(d1) - self.strike * exp(- self.rate * self.expiry) * norm.cdf(d2)
        elif otype == OptionType.PUT:
            price = self.strike * exp(
                -self.rate * self.expiry) * cdf(-d2) - self.spot * exp(
                    (self.cost_of_carry - self.rate) * self.expiry) * cdf(-d1)
            #price = self.strike * exp(- self.rate * self.expiry) * norm.cdf(-d2) - self.spot * exp((self.cost_of_carry - self.rate) * self.expiry) * norm.cdf(-d1)
        else:
            raise OptionTypeError

        return round(price, round_digit)
Example #3
0
    def get_option_price(self, otype, round_digit=4):
 
        # This is the generalized Black_Scholes formula
        d1, d2 = self.get_d1_d2()
        
        if otype == OptionType.CALL:
            price = self.spot * exp((self.cost_of_carry - self.rate) * self.expiry) * cdf(d1) - self.strike * exp(- self.rate * self.expiry) * cdf(d2)
            #price = self.spot * exp((self.cost_of_carry - self.rate) * self.expiry) * norm.cdf(d1) - self.strike * exp(- self.rate * self.expiry) * norm.cdf(d2)
        elif otype == OptionType.PUT:
            price = self.strike * exp(- self.rate * self.expiry) * cdf(-d2) - self.spot * exp((self.cost_of_carry - self.rate) * self.expiry) * cdf(-d1)
            #price = self.strike * exp(- self.rate * self.expiry) * norm.cdf(-d2) - self.spot * exp((self.cost_of_carry - self.rate) * self.expiry) * norm.cdf(-d1)
        else:
            raise OptionTypeError
        
        return round(price, round_digit)
Example #4
0
    def _get_ABCDEF(self, ita, fi):

        A = fi * self.spot * exp((self.coc - self.rate) * self.expiry) * cdf(fi * self.x1) -    \
            fi * self.strike * exp(- self.rate * self.expiry) * cdf(fi * self.x1 - fi * self.vol * sqrt(self.expiry))
    
        B = fi * self.spot * exp((self.coc - self.rate) * self.expiry) * cdf(fi * self.x2) -    \
            fi * self.strike * exp(- self.rate * self.expiry) * cdf(fi * self.x2 - fi * self.vol * sqrt(self.expiry))
        
        C = fi * self.spot * exp((self.coc - self.rate) * self.expiry) * (self.bar / self.spot)**(2 * self.u + 2) * cdf(ita * self.y1) -    \
            fi * self.strike * exp(- self.rate * self.expiry) * (self.bar / self.spot)**(2 * self.u) * cdf(ita * self.y1 - ita * self.vol * sqrt(self.expiry))
        
        D = fi * self.spot * exp((self.coc - self.rate) * self.expiry) * (self.bar / self.spot)**(2 * self.u + 2) * cdf(ita * self.y2) -    \
            fi * self.strike * exp(- self.rate * self.expiry) * (self.bar / self.spot)**(2 * self.u) * cdf(ita * self.y2 - ita * self.vol * sqrt(self.expiry))
        
        E = self.rebate * exp(- self.rate * self.expiry) * ( cdf(ita * self.x2 - ita * self.vol * sqrt(self.expiry)) - 
                                                             (self.bar / self.spot)**(2 * self.u) * cdf(ita * self.y2 - ita * self.vol * sqrt(self.expiry)) )
        
        F = self.rebate * ( (self.bar / self.spot)**(self.u + self.la) * cdf(ita * self.z) + 
                            (self.bar / self.spot)**(self.u - self.la) * cdf(ita * self.z - 2 * ita * self.la * self.vol * sqrt(self.expiry)) )

        return A, B, C, D, E, F