Sure! There are many resources available online that provide examples of how to use QuantLib. For instance, Gouthaman Balaraman has a collection of tutorials on his website that cover various topics, including modeling fixed rate bonds, bootstrapping yield curves, and valuing interest rate swaps using QuantLib and Python². You can also find documentation and examples on the official QuantLib website¹.
Here is an example of how to create a Geometric Brownian Motion (GBM) model using QuantLib and Python:
Code:
```python
from QuantLib import *
# Set up the model parameters
riskFreeRate = 0.05
dividendYield = 0.02
volatility = 0.2
initialValue = 100
# Set up the time grid
maturity = 1.0
dt = 0.01
timeSteps = int(maturity / dt)
# Set up the random number generator
seed = 42
rng = GaussianRandomSequenceGenerator(UniformRandomSequenceGenerator(timeSteps, UniformRandomGenerator(seed)))
seq = GaussianPathGenerator(GBMProcess(QuoteHandle(SimpleQuote(initialValue)), YieldTermStructureHandle(FlatForward(0, TARGET(), riskFreeRate, Actual360())), YieldTermStructureHandle(FlatForward(0, TARGET(), dividendYield, Actual360())), BlackVolTermStructureHandle(BlackConstantVol(0, TARGET(), volatility, Actual360()))), maturity, timeSteps, rng)
# Generate the path
path = seq.next().value()
# Print the path values
for i in range(len(path)):
print(f"Time: {i * dt:.2f}, Value: {path[i]:.2f}")
```
This code sets up a GBM model with specified parameters for the risk-free rate, dividend yield, volatility, and initial value of the asset. It then uses QuantLib's `GaussianPathGenerator` class to generate a sample path of the asset price over time. The resulting path is printed to the console.
I hope this example helps you get started with using QuantLib to create GBM models! Let me know if you have any further questions or if there's anything else I can help with.
Source: Conversation with Bing, 9/7/2023
(1) QuantLib Python Tutorials With Examples - G B.
http://gouthamanbalaraman.com/blog/quantlib-python-tutorials-with-examples.html.
(2) QuantLib Documentation.
https://www.quantlib.org/docs.shtml.
(3) Modeling assets with QuantLib | modelx.
https://modelx.io/blog/2022/02/13/modeling-assets-with-quantlib/.
(4) Writing Your First QuantLib Program in C++.
https://benjaminwhiteside.com/2018/12/07/writing-your-first-quantlib-program-in-c/.
(5) QuantLib Installation in Visual C++.
https://www.quantlib.org/install/vc10.shtml.
(6) Introduction to Selected Classes of the QuantLib Library I.
https://www.quantlib.org/slides/dima-ql-intro-1.pdf.