I am using Quantlib to perform calculations on historic data.
After setting up the required framework (curves etc), When I call option.ImpliedVolatility()
I get the following exception thrown (for options that have expired):
File "/usr/local/lib/python2.6/dist-packages/QuantLib/QuantLib.py", line 3683, in impliedVolatility
def impliedVolatility(self, *args): return _QuantLib.VanillaOption_impliedVolatility(self, *args)
RuntimeError: option expired
A snippet of the lines of code for setting up required curves etc is shown below:
dividend_yield = YieldTermStructureHandle(FlatForward(0, TARGET(), div_yield, Actual365Fixed()))
risk_free_rate = YieldTermStructureHandle(FlatForward(0, TARGET(), rf_rate, Actual365Fixed()))
volatility = BlackVolTermStructureHandle(BlackConstantVol(0, TARGET(), annualized_histvol, Actual360()))
I STRONGLY suspect that the TARGET()
macro used defaults to the current system date.
How may I set up the library to use a specific historic date?
The evaluation date is set by running, say,
Settings.instance().evaluationDate = Date(14,March,2010)
before the calculations. If not set, it defaults to the current date as you suspected.
The TARGET calendar just tells the curve what days are holidays, but has no effect on the evaluation date itself.