Git Product home page Git Product logo

Comments (13)

thrasibule avatar thrasibule commented on September 17, 2024 1

Regarding your contributions, once you're happy with, you should definitely submit a pull request to this repo. @dpinte is very responsive and will be happy to merge it I'm sure.

from pyql.

thrasibule avatar thrasibule commented on September 17, 2024

Do you have just one constructor defined in _ois_rate_helper.pxd for OISRateHelper? Sometimes cython gets confused when there are multiple. If you just have one, then it should just be a matter of making sure the parameters match like you said. I don't know of an easy way to know the offending parameter unfortunately.

from pyql.

AUK1939 avatar AUK1939 commented on September 17, 2024

Yes I only have one constructor defined.

Is it just me or this the hard part of programming these cython wrappers? (was going well before this issue). Is there any way to narrow down the offending parameters? I have a feeling I'm not handling the enum types correctly (BusinessDayConvention). But I haven't had much luck tinkering with it.

I've been at it a few hours now. Maybe it's time to give up and go back to the swig wrappers :( Not out of choice ofcourse I much prefer pyql if it exposed more of the library.

Maybe when somebody does decide to expose the OIS helpers I can see where I went wrong

from pyql.

thrasibule avatar thrasibule commented on September 17, 2024

I've found the error: in _ois_rate_helper.pxd, OISRateHelper needs to derive from RelativeDateRateHelper not RelativeDateBootstrapHelper. Next time please push what you have in a branch on your own fork, that will make it easier for me to reproduce what you're seeing.

from pyql.

AUK1939 avatar AUK1939 commented on September 17, 2024

Thanks that solved the issue (not sure how I missed that). Subsequently I was able to build the EONIA discount curve in pyql.

However I think there might be a bug in the wrapper, Here's a simple example of how to reproduce

from quantlib.settings import Settings
from quantlib.time.date import October
from quantlib.time.api import Date, Annual, Period, Unadjusted, Thirty360, Actual360
from quantlib.quotes import SimpleQuote
from quantlib.time.calendars.target import TARGET
from quantlib.termstructures.yields.api import SwapRateHelper
from quantlib.indexes.api import Euribor6M
from quantlib.termstructures.yields.api import ( PiecewiseYieldCurve, BootstrapTrait, Interpolator )

# Note the evaluation date
Settings.instance().evaluation_date = Date(3, October, 2014)

# create some swap helpers 
helpers = [SwapRateHelper.from_tenor(SimpleQuote(rate/100.),
                          Period(*tenor),
                          TARGET(),
                          Annual,
                          Unadjusted,
                          Thirty360(),
                          Euribor6M())
           for tenor, rate in [((2, Years), 0.201),
                               ((3, Years), 0.258),
                               ((5, Years), 0.464),
                               ((10, Years), 1.151),
                               ((15, Years), 1.588)]]

# build the curve
curve = PiecewiseYieldCurve(BootstrapTrait.ForwardRate, Interpolator.Linear, 0, TARGET(), helpers, Actual360())

# For some reason the reference date of the curve is 2018-10-11 (which is todays date)
curve.reference_date
>> Date('2018-10-11T00:00:00,000000')

The equivalent swig wrapper based code is below which gives the correct reference date to the curve. Thus either I'm either not converting the code correctly to pyql or there is a bug in the wrapper.

from QuantLib import *
Settings.instance().evaluationDate = Date(3, October, 2014)
helpers = [SwapRateHelper(QuoteHandle(SimpleQuote(rate/100.)),
                          Period(*tenor),
                          TARGET(),
                          Annual,
                          Unadjusted,
                          Thirty360(),
                          Euribor6M())
           for tenor, rate in [((2, Years), 0.201),
                               ((3, Years), 0.258),
                               ((5, Years), 0.464),
                               ((10, Years), 1.151),
                               ((15, Years), 1.588)]]
curve1 = PiecewiseFlatForward(0, TARGET(), helpers, Actual360())
print(curve1.referenceDate())
# >> October 3rd, 2014

Thanks for the suggestion regarding forking. This is my first github interaction; shall I submit my code to the main repo or keep it in a fork? And for what it's worth, great work on the pyql wrapper. It truely is a much nicer experience to work with quantlib than the swig version. For example meaningful error messages make it a breeze to fix client code.

from pyql.

thrasibule avatar thrasibule commented on September 17, 2024

This is a bug with Settings. Depending on how you compiled pyql Settings is not really a singleton. so even though you set the evaluationDate to Date(3, October, 2014), there is another Settings object that get initialized in the curve. I don't understand it very well, so it might be hard to fix. There was a bug with python 3.7 if it was compiled with lto, but I've submitted a fix. Where are you running this code? It should work on Linux. For instance your code works fine for me on Arch linux. It might be helfpful if you could report the command line incantation that gets generated when you compile pyql. For instance this is what I have

g++ -pthread -shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto=4 -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now build/temp.linux-x86_64-3.7/quantlib/time/schedule.o -L/usr/local/lib -L/usr/lib -L/usr/lib -lQuantLib -lpython3.7m -o /home/guillaume/projects/pyql/quantlib/time/schedule.cpython-37m-x86_64-linux-gnu.so -Wl,--strip-all

from pyql.

AUK1939 avatar AUK1939 commented on September 17, 2024

I'm working on a Windows 10 box with Anaconda x64 (Python 3.6.5).

The command line incantation used to build was:

building 'quantlib.cashflow' extension
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -D__WIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNOMINMAX -DWINNT -D_WINDLL -D_SCL_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -IC:\libraries\ORE_2015\QuantLib -IC:\libraries\boost_1_68_0 -I. -I./cpp_layer -IC:\ProgramData\Anaconda3\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda3\include -IC:\ProgramData\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpquantlib\cashflow.cpp /Fobuild\temp.win-amd64-3.6\Release\quantlib\cashflow.obj /GR /FD /Zm250 /EHsc
cashflow.cpp

Note I needed to comment out the following line in the setup.py file for this to build (msvc does not know what an .so is and I wasn't sure what the equivalent flags would be for that compiler). Maybe that's where the problem lies.
self.compiler.compiler_so = [f for f in self.compiler.compiler_so if f not in lto_flags]

from pyql.

thrasibule avatar thrasibule commented on September 17, 2024

I was afraid of that... I couldn't make it work on windows, but we can try! I assume the tests are not working either? If you do "make tests" I suspect you will have other issues with the date being moved inside Settings.

from pyql.

thrasibule avatar thrasibule commented on September 17, 2024

Oh and how did you compile quantlib on windows?

from pyql.

AUK1939 avatar AUK1939 commented on September 17, 2024

I built Quantlib from the visual studio IDE (x64 release version with Boost 1.68). The only user config I changed was QL_HIGH_RESOLUTION_DATE. I haven't tried "make tests", will probably need to use nmake or cmake.

from pyql.

dpinte avatar dpinte commented on September 17, 2024

Windows has been a nightmare with the Singleton problem. I had found a working solution for Python2 which did not work on Python 3. We had to patch QL, generate a dll, etc. I unfortunately does not have the time to look into this issue.

from pyql.

AUK1939 avatar AUK1939 commented on September 17, 2024

I guess it doesn't suprise me, it wouldn't be the only python module that doesn't work on windows :) Thanks for your input.

from pyql.

thrasibule avatar thrasibule commented on September 17, 2024

OISRateHelpers have been added.

from pyql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.