Beispiel #1
0
def testConvergence():

    valueDate = FinDate(2014, 1, 1)
    startAveragingDate = FinDate(2014, 6, 1)
    expiryDate = FinDate(2015, 1, 1)
    stockPrice = 100.0
    volatility = 0.20
    interestRate = 0.30
    dividendYield = 0.10
    numObservations = 120  # daily as we have a half year
    accruedAverage = None
    K = 100
    seed = 1976

    model = FinEquityModelBlackScholes(volatility)
    discountCurve = FinDiscountCurveFlat(valueDate, interestRate)

    asianOption = FinEquityAsianOption(startAveragingDate, expiryDate, K,
                                       FinOptionTypes.EUROPEAN_CALL,
                                       numObservations)

    testCases.header("K", "Geometric", "Turnbull_Wakeman", "Curran", "FastMC",
                     "FastMC_CV")

    valuesTurnbull = []
    valuesCurran = []
    valuesGeometric = []
    valuesMC_fast = []
    valuesMC_CV = []

    numPathsList = [5000]

    for numPaths in numPathsList:

        accruedAverage = stockPrice * 1.1

        valueMC_fast = asianOption._valueMC_fast(valueDate, stockPrice,
                                                 discountCurve, dividendYield,
                                                 model, numPaths, seed,
                                                 accruedAverage)

        valueMC_CV = asianOption.valueMC(valueDate, stockPrice, discountCurve,
                                         dividendYield, model, numPaths, seed,
                                         accruedAverage)

        valueGeometric = asianOption.value(
            valueDate, stockPrice, discountCurve, dividendYield, model,
            FinAsianOptionValuationMethods.GEOMETRIC, accruedAverage)

        valueTurnbullWakeman = asianOption.value(
            valueDate, stockPrice, discountCurve, dividendYield, model,
            FinAsianOptionValuationMethods.TURNBULL_WAKEMAN, accruedAverage)

        valueCurran = asianOption.value(valueDate, stockPrice, discountCurve,
                                        dividendYield, model,
                                        FinAsianOptionValuationMethods.CURRAN,
                                        accruedAverage)

        valuesGeometric.append(valueGeometric)
        valuesTurnbull.append(valueTurnbullWakeman)
        valuesCurran.append(valueCurran)
        valuesMC_fast.append(valueMC_fast)
        valuesMC_CV.append(valueMC_CV)

        testCases.print(numPaths, valueGeometric, valueTurnbullWakeman,
                        valueCurran, valueMC_fast, valueMC_CV)
Beispiel #2
0
def testTimeEvolution():

    startAveragingDate = FinDate(2015, 1, 1)
    expiryDate = FinDate(2016, 1, 1)
    stockPrice = 100.0
    volatility = 0.20
    interestRate = 0.30
    dividendYield = 0.10
    numObservations = 100  # weekly as we have a year
    accruedAverage = None
    K = 100
    seed = 1976

    model = FinEquityModelBlackScholes(volatility)

    asianOption = FinEquityAsianOption(startAveragingDate, expiryDate, K,
                                       FinOptionTypes.EUROPEAN_CALL,
                                       numObservations)

    testCases.header("Date", "Geometric", "Turnbull_Wakeman", "Curran",
                     "FastMC", "FastMC_CV")

    valuesTurnbull = []
    valuesCurran = []
    valuesGeometric = []
    valuesMC_fast = []
    valuesMC_CV = []

    valueDates = []
    valueDates.append(FinDate(2014, 4, 1))
    valueDates.append(FinDate(2014, 6, 1))
    valueDates.append(FinDate(2014, 8, 1))
    valueDates.append(FinDate(2015, 2, 1))
    valueDates.append(FinDate(2015, 4, 1))
    valueDates.append(FinDate(2015, 6, 1))
    valueDates.append(FinDate(2015, 8, 1))

    numPaths = 10000

    for valueDate in valueDates:

        accruedAverage = stockPrice * 0.9

        discountCurve = FinDiscountCurveFlat(valueDate, interestRate)

        valueMC_fast = asianOption._valueMC_fast(valueDate, stockPrice,
                                                 discountCurve, dividendYield,
                                                 model, numPaths, seed,
                                                 accruedAverage)

        valueMC_CV = asianOption.valueMC(valueDate, stockPrice, discountCurve,
                                         dividendYield, model, numPaths, seed,
                                         accruedAverage)

        valueGeometric = asianOption.value(
            valueDate, stockPrice, discountCurve, dividendYield, model,
            FinAsianOptionValuationMethods.GEOMETRIC, accruedAverage)

        valueTurnbullWakeman = asianOption.value(
            valueDate, stockPrice, discountCurve, dividendYield, model,
            FinAsianOptionValuationMethods.TURNBULL_WAKEMAN, accruedAverage)

        valueCurran = asianOption.value(valueDate, stockPrice, discountCurve,
                                        dividendYield, model,
                                        FinAsianOptionValuationMethods.CURRAN,
                                        accruedAverage)

        valuesGeometric.append(valueGeometric)
        valuesTurnbull.append(valueTurnbullWakeman)
        valuesCurran.append(valueCurran)
        valuesMC_fast.append(valueMC_fast)
        valuesMC_CV.append(valueMC_CV)

        testCases.print(str(valueDate), valueGeometric, valueTurnbullWakeman,
                        valueCurran, valueMC_fast, valueMC_CV)