Any QuantLib experts here?

Discussion in 'Hook Up' started by earth_imperator, Sep 7, 2023.

  1. Any QuantLib (C++ and/or Python) experts here?
     
  2. M.W.

    M.W.

    Been using it a while ago for some fixed income implementations (C++). What you wanna know?

     
  3. 2rosy

    2rosy

    blast from the past. design patterns heavy
     
    M.W. likes this.
  4. traider

    traider

    GPT is an expert


    import QuantLib as ql

    # Setting the evaluation date
    calculation_date = ql.Date(1, 1, 2022)
    ql.Settings.instance().evaluationDate = calculation_date

    # Bond parameters
    face_value = 100
    coupon_rate = 0.05
    coupon_type = ql.Annual
    bond_maturity = 10

    # Create a flat yield term structure
    interest_rate = ql.SimpleQuote(0.03)
    rate_handle = ql.QuoteHandle(interest_rate)
    day_count = ql.ActualActual()
    term_structure = ql.FlatForward(calculation_date, rate_handle, day_count)
    ts_handle = ql.YieldTermStructureHandle(term_structure)

    # Construct the bond schedule
    issue_date = calculation_date
    maturity_date = issue_date + ql.Period(bond_maturity, ql.Years)
    schedule = ql.Schedule(issue_date, maturity_date, ql.Period(coupon_type),
    ql.TARGET(), ql.Unadjusted, ql.Unadjusted,
    ql.DateGeneration.Backward, False)

    # Construct the bond
    bond = ql.FixedRateBond(0, face_value, schedule, [coupon_rate], day_count)

    # Get the bond's present value
    bond_engine = ql.DiscountingBondEngine(ts_handle)
    bond.setPricingEngine(bond_engine)
    print("Bond's present value:", bond.NPV())
     
  5. I'm looking for a QuantLib code that simulates stock prices by using GBM (Geometric Brownian Motion),
    for example daily prices for a year.
    I found the following old code from 2013, but I am not sure whether it's correct:
    https://mhittesdorf.wordpress.com/2...-asset-prices-with-geometric-brownian-motion/
    I'm not sure whether this Box-Muller method for getting normal distribution is correct.
    Why is it not simply using the built-in (in C++11 and higher) std::normal_distribution instead?
    What do you folks think about this?
    Do you have got a better GBM code in QuantLib?
     
    Last edited: Sep 7, 2023
    blueraincap likes this.
  6. It's indeed not easy to use this library :) Maybe over-engineered.
     
  7. 2rosy

    2rosy

    so you're looking for a gbm generator? what does this have to do with quantlib?
     
    blueraincap likes this.
  8. Yes, a GBM generator in QuantLib. GBM usually is part of any such financial library.
    As said, I need a GBM example code in QuantLib. I'm not sure wthether the above linked GBM code is correct as it's very old, therefore asking some QuantLib experts here for their expertise.
     
    Last edited: Sep 7, 2023
  9. M.W.

    M.W.

    blueraincap likes this.
  10. 2rosy

    2rosy

    #10     Sep 7, 2023
    M.W. likes this.