简体   繁体   English

将QuantLib导入为ql错误

[英]import QuantLib as ql ERROR

I downloaded and installed pyql using python setup.py install 我使用python setup.py install下载并安装了pyql

If I import things I need one by one from pyql , it works, eg, 如果我从pyql导入我需要的东西,它可以工作,例如,

from quantlib.instruments.api import AmericanExercise,EuropeanExercise, EuropeanOption, \
     VanillaOption, Put, Call
from quantlib.instruments.payoffs import PlainVanillaPayoff

However, if I try 但是,如果我尝试

import QuantLib as ql


[idf@mail python]$ python bootstrap_yc.py 
Traceback (most recent call last):
  File "bootstrap_yc.py", line 1, in <module>
    import QuantLib as ql
ImportError: No module named QuantLib
[idf@mail python]$ 

I added the directory of the quantlib egg file in anaconda to PYTHONPATH to no avail. 我在anaconda中将quantlib egg文件的目录添加到了PYTHONPATH ,但无济于事。

[idf@mail python]$ echo $PYTHONPATH
/home/idf/anaconda2/lib/python2.7/site-packages/quantlib-0.1-py2.7-linux-x86_64.egg/quantlib
[idf@mail python]$ 

EDIT 编辑

I am able to say 我可以说

from quantlib import *

import quantlib as ql

But then things like 但是然后像

# Deposit rates
depo_maturities = [ql.Period(6,ql.Months), ql.Period(12, ql.Months)]
depo_rates = [5.25, 5.5]

return an error: 返回错误:

[idf@mail python]$ python bootstrap_yc.py 
Traceback (most recent call last):
  File "bootstrap_yc.py", line 18, in <module>
    depo_maturities = [ql.Period(6,ql.Months), ql.Period(12, ql.Months)]
AttributeError: 'module' object has no attribute 'Period'
[idf@mail python]$ 

I think you're confusing pyql with the Python bindings provided by the QuantLib project. 我认为您将pyql与QuantLib项目提供的Python绑定混淆了。 pyql is a separate project, and gives you a quantlib module with a more idiomatic interface but with fewer features at this time. pyql是一个单独的项目,它为您提供了一个具有更多惯用语界面但功能较少的quantlib模块。

If you want the QuantLib Python bindings, you can get them from the QuantLib download page (look in the "other languages" folder inside any of the listed versions); 如果需要QuantLib Python绑定,则可以从QuantLib下载页面获取它们(在列出的任何版本中的“其他语言”文件夹中查看); installation instructions are at http://quantlib.org/install.shtml . 安装说明位于http://quantlib.org/install.shtml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM