I am trying to integrate SQL Server 2017 or 2019 with Qunatlib using python. I can run Quantlib code which in this particular case is returning a Qunatlib schedule object which is an enumerated list of type Quantlib.Date. The code look like this
EXECUTE sp_execute_external_script
@language = N'Python',
@script = N'
import QuantLib as QL
import pandas as PD
effective_date = QL.Date(1, 1, 2015)
termination_date = QL.Date(1, 1, 2016)
tenor = QL.Period(QL.Monthly)
calendar = QL.UnitedStates()
business_convention = QL.Following
termination_business_convention = QL.Following
date_generation = QL.DateGeneration.Forward
end_of_month = False
schedule = QL.Schedule(effective_date,termination_date,tenor,calendar,business_convention,termination_business_convention,date_generation,end_of_month)
OutputDataSet = PD.DataFrame(list(enumerate(schedule)), columns=[''index'',''RollDate''])'
However I get the following error
INTERNAL ERROR: should have tag
error while running BxlServer: caught exception: Error communicating between BxlServer and client: 0x000000e9
If i remove the last line
OutputDataSet = PD.DataFrame(list(enumerate(schedule)), columns=[''index'',''RollDate''])'
the script runs without error. I can also run the script in other python environments without error. I suspect that the issue is something to do with data casting, but the error is not particularly helpful. I need to get the data into a data frame for use with in SQL Server.
Worked it out. Needed to convert the data type to datetime and add it to a pandas.
import QuantLib as QL
import pandas as PD
import datetime
effective_date = QL.Date(1, 1, 2015)
termination_date = QL.Date(1, 1, 2016)
tenor = QL.Period(QL.Monthly)
calendar = QL.UnitedStates()
business_convention = QL.Following
termination_business_convention = QL.Following
date_generation = QL.DateGeneration.Forward
end_of_month = False
schedule = QL.Schedule(effective_date,termination_date,tenor,calendar,business_convention,termination_business_convention,date_generation,end_of_month)
OutputDataSet=PD.DataFrame(columns=[''RollDate''])
for i, d in enumerate(schedule):
OutputDataSet.loc[i]=datetime.datetime(d.year(), d.month(), d.dayOfMonth())
User contributions licensed under CC BY-SA 3.0