0

我正在尝试使用 python 将 SQL Server 2017 或 2019 与 Qunatlib 集成。我可以运行 Quantlib 代码,在这种特殊情况下,它返回一个 Qunatlib 调度对象,它是一个 Quantlib.Date 类型的枚举列表。代码看起来像这样

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''])'

但是我收到以下错误

INTERNAL ERROR: should have tag
error while running BxlServer: caught exception: Error communicating between BxlServer and client: 0x000000e9

如果我删除最后一行

OutputDataSet  = PD.DataFrame(list(enumerate(schedule)),  columns=[''index'',''RollDate''])'

脚本运行没有错误。我也可以在其他 python 环境中运行脚本而不会出错。我怀疑这个问题与数据转换有关,但该错误并不是特别有用。我需要将数据放入数据框中,以便在 SQL Server 中使用。

4

1 回答 1

1

解决了。需要将数据类型转换为日期时间并将其添加到熊猫。

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())
于 2020-12-07T00:55:46.637 回答