コード例 #1
0
def test_american_call():
    call_option = EquityAmericanOption(expiry_date, strike_price,
                                       OptionTypes.AMERICAN_CALL)

    value = call_option.value(valuation_date, stock_price, discount_curve,
                              dividend_curve, model)

    assert round(value, 4) == 8.0556
コード例 #2
0
def test_american_put():
    put_option = EquityAmericanOption(expiry_date, strike_price,
                                      OptionTypes.AMERICAN_PUT)

    value = put_option.value(valuation_date, stock_price, discount_curve,
                             dividend_curve, model)

    assert round(value, 4) == 7.2583
コード例 #3
0
def testBlackScholes():

    valuation_date = Date(8, 5, 2015)
    expiry_date = Date(15, 1, 2016)

    strike_price = 130.0
    stock_price = 127.62
    volatility = 0.20
    interest_rate = 0.001
    dividend_yield = 0.0163

    option_type = OptionTypes.AMERICAN_CALL
    euOptionType = OptionTypes.EUROPEAN_CALL

    amOption = EquityAmericanOption(expiry_date, strike_price, option_type)

    ameuOption = EquityAmericanOption(expiry_date, strike_price, euOptionType)

    euOption = EquityVanillaOption(expiry_date, strike_price, euOptionType)

    discount_curve = DiscountCurveFlat(valuation_date, interest_rate,
                                       FrequencyTypes.CONTINUOUS,
                                       DayCountTypes.ACT_365F)

    dividend_curve = DiscountCurveFlat(valuation_date, dividend_yield,
                                       FrequencyTypes.CONTINUOUS,
                                       DayCountTypes.ACT_365F)

    num_steps_per_year = 400

    modelTree = BlackScholes(volatility, BlackScholesTypes.CRR_TREE,
                             num_steps_per_year)

    v = amOption.value(valuation_date, stock_price, discount_curve,
                       dividend_curve, modelTree)
    #    print(v)

    modelApprox = BlackScholes(volatility, BlackScholesTypes.BARONE_ADESI)

    v = amOption.value(valuation_date, stock_price, discount_curve,
                       dividend_curve, modelApprox)

    #    print(v)

    v = ameuOption.value(valuation_date, stock_price, discount_curve,
                         dividend_curve, modelTree)

    #    print(v)

    v = euOption.value(valuation_date, stock_price, discount_curve,
                       dividend_curve, modelTree)

    #    print(v)

    amTreeValue = []
    amBAWValue = []
    euTreeValue = []
    euAnalValue = []
    volatility = 0.20
コード例 #4
0
def testEquityAmericanOption():

    valuation_date = Date(1, 1, 2016)
    expiry_date = Date(1, 1, 2017)
    stock_price = 50.0
    interest_rate = 0.06
    dividend_yield = 0.04
    volatility = 0.40
    strike_price = 50.0

    discount_curve = DiscountCurveFlat(valuation_date, interest_rate)
    dividend_curve = DiscountCurveFlat(valuation_date, dividend_yield)

    testCases.banner("================== EUROPEAN PUT =======================")

    put_option = EquityAmericanOption(expiry_date, strike_price,
                                      FinOptionTypes.EUROPEAN_PUT)

    model = BlackScholes(volatility, BlackScholesTypes.CRR_TREE, 100)

    value = put_option.value(valuation_date, stock_price, discount_curve,
                             dividend_curve, model)
    delta = put_option.delta(valuation_date, stock_price, discount_curve,
                             dividend_curve, model)
    gamma = put_option.gamma(valuation_date, stock_price, discount_curve,
                             dividend_curve, model)
    theta = put_option.theta(valuation_date, stock_price, discount_curve,
                             dividend_curve, model)

    testCases.header("OPTION_TYPE", "VALUE", "DELTA", "GAMMA", "THETA")
    testCases.print("EUROPEAN_PUT_BS", value, delta, gamma, theta)

    option = EquityAmericanOption(expiry_date, strike_price,
                                  FinOptionTypes.EUROPEAN_PUT)

    testCases.header("OPTION_TYPE", "NUMSTEPS", "VALUE DELTA GAMMA THETA",
                     "TIME")

    num_steps_list = [100, 200, 500, 1000, 2000]

    for num_steps in num_steps_list:

        model = BlackScholes(volatility, BlackScholesTypes.CRR_TREE, num_steps)

        start = time.time()
        results = option.value(valuation_date, stock_price, discount_curve,
                               dividend_curve, model)
        end = time.time()
        duration = end - start
        testCases.print("EUROPEAN_PUT_TREE", num_steps, results, duration)

    testCases.banner("================== AMERICAN PUT =======================")

    option = EquityAmericanOption(expiry_date, strike_price,
                                  FinOptionTypes.AMERICAN_PUT)

    testCases.header("OPTION_TYPE", "NUMSTEPS", "VALUE DELTA GAMMA THETA",
                     "TIME")

    for num_steps in num_steps_list:

        model = BlackScholes(volatility, BlackScholesTypes.CRR_TREE, num_steps)

        start = time.time()
        results = option.value(valuation_date, stock_price, discount_curve,
                               dividend_curve, model)
        end = time.time()
        duration = end - start
        testCases.print("AMERICAN_PUT", num_steps, results, duration)

    testCases.banner(
        "================== EUROPEAN CALL =======================")

    call_option = EquityAmericanOption(expiry_date, strike_price,
                                       FinOptionTypes.EUROPEAN_CALL)

    value = call_option.value(valuation_date, stock_price, discount_curve,
                              dividend_curve, model)
    delta = call_option.delta(valuation_date, stock_price, discount_curve,
                              dividend_curve, model)
    gamma = call_option.gamma(valuation_date, stock_price, discount_curve,
                              dividend_curve, model)
    theta = call_option.theta(valuation_date, stock_price, discount_curve,
                              dividend_curve, model)

    testCases.header("OPTION_TYPE", "VALUE", "DELTA", "GAMMA", "THETA")
    testCases.print("EUROPEAN_CALL_BS", value, delta, gamma, theta)

    option = EquityAmericanOption(expiry_date, strike_price,
                                  FinOptionTypes.EUROPEAN_CALL)

    testCases.header("OPTION_TYPE", "NUMSTEPS", "VALUE DELTA GAMMA THETA",
                     "TIME")

    for num_steps in num_steps_list:

        model = BlackScholes(volatility, BlackScholesTypes.CRR_TREE, num_steps)
        start = time.time()
        results = option.value(valuation_date, stock_price, discount_curve,
                               dividend_curve, model)
        end = time.time()
        duration = end - start
        testCases.print("EUROPEAN_CALL_TREE", num_steps, results, duration)

    testCases.banner(
        "================== AMERICAN CALL =======================")
    testCases.header("OPTION_TYPE", "NUMSTEPS", "VALUE DELTA GAMMA THETA",
                     "TIME")

    option = EquityAmericanOption(expiry_date, strike_price,
                                  FinOptionTypes.AMERICAN_CALL)

    for num_steps in num_steps_list:

        model = BlackScholes(volatility, BlackScholesTypes.CRR_TREE, num_steps)

        start = time.time()

        results = option.value(valuation_date, stock_price, discount_curve,
                               dividend_curve, model)

        end = time.time()
        duration = end - start
        testCases.print("AMERICAN_CALL", num_steps, results, duration)
コード例 #5
0
from financepy.utils.frequency import FrequencyTypes
from financepy.utils.date import Date

valuation_date = Date(8, 5, 2015)
expiry_date = Date(15, 1, 2016)

strike_price = 130.0
stock_price = 127.62
volatility = 0.20
interest_rate = 0.001
dividend_yield = 0.0163

option_type = OptionTypes.AMERICAN_CALL
euOptionType = OptionTypes.EUROPEAN_CALL

amOption = EquityAmericanOption(expiry_date, strike_price, option_type)

ameuOption = EquityAmericanOption(expiry_date, strike_price, euOptionType)

euOption = EquityVanillaOption(expiry_date, strike_price, euOptionType)

discount_curve = DiscountCurveFlat(valuation_date, interest_rate,
                                   FrequencyTypes.CONTINUOUS,
                                   DayCountTypes.ACT_365F)

dividend_curve = DiscountCurveFlat(valuation_date, dividend_yield,
                                   FrequencyTypes.CONTINUOUS,
                                   DayCountTypes.ACT_365F)

num_steps_per_year = 400