This is the first time I'm using quantlib, and I wanted to compare the velocity of quantlib with my own Python code.
I found a tutorial about Hull and White to generate the short rate paths with quantlib: (Tutorial about Hull and White)
The author seems to say that it is very simple to change the future instantaneous rate, which is a constant in the example... But when I replace it with an array of 361 values corresponding to the values of the future rate for the differents dates defined by the time step, I get the following error: TypeError: in method 'new_SimpleQuote', argument 1 of type 'Real'
I tried to investigate and search in the quantlib library how to fix this, but I havn't learned to code in C++ yet so I may need a little help
Thank you, and have a good day
PS: My input data is the zero-coupon curve at a certain time, so if it possible to use it directly instead of converting it to a future rate curve first, I'm interesed to know how to do it
Edit: This is my code
import QuantLib as ql
import matplotlib.pyplot as plt
import numpy as np
sigma = 0.1
a = 0.1
timestep = 360
length = 30 # in years
#forward_rate = 0.05 I replaced this line by an random array and it doesn't work
forward_rate=np.random.randn(361)
day_count = ql.Thirty360()
todays_date = ql.Date(15, 1, 2015)
print(ql.QuoteHandle(ql.SimpleQuote(forward_rate)))
ql.Settings.instance().evaluationDate = todays_date
spot_curve = ql.FlatForward(todays_date,
ql.QuoteHandle(ql.SimpleQuote(forward_rate)), day_count)
spot_curve_handle = ql.YieldTermStructureHandle(spot_curve)
hw_process = ql.HullWhiteProcess(spot_curve_handle, a, sigma)
rng = ql.GaussianRandomSequenceGenerator(
ql.UniformRandomSequenceGenerator(timestep, ql.UniformRandomGenerator()))
seq = ql.GaussianPathGenerator(hw_process, length, timestep, rng, False)
def generate_paths(num_paths, timestep):
arr = np.zeros((num_paths, timestep+1))
for i in range(num_paths):
sample_path = seq.next()
path = sample_path.value()
time = [path.time(j) for j in range(len(path))]
value = [path[j] for j in range(len(path))]
arr[i, :] = np.array(value)
return np.array(time), arr
num_paths = 10
time, paths = generate_paths(num_paths, timestep)
for i in range(num_paths):
plt.plot(time, paths[i, :], lw=0.8, alpha=0.6)
plt.title("Hull-White Short Rate Simulation")
plt.show()