Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows build and update to QuantLib 1.4 #63

Merged
merged 25 commits into from Sep 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3e285bf
updated for QL1.4 build
dpinte Aug 26, 2014
29a6e18
removed distutils pragma in source code
dpinte Aug 26, 2014
16ab1b2
allows CahsFlow.amount() to raise exceptions
dpinte Aug 26, 2014
10c6af1
simplified _thisptr structure
dpinte Aug 26, 2014
28b689a
somes fixes to swap methods and exposes debug builds in setup.py
dpinte Sep 3, 2014
531c673
removed ql/quantlib.hpp usage and adds a patched version of
dpinte Sep 4, 2014
72be7bc
symbols needed to create the QuantLib.dll
dpinte Sep 4, 2014
d9f5494
add DEBUG flag to control debugging on Windows
dpinte Sep 4, 2014
32a2f2e
added fixme and removed useless include
dpinte Sep 4, 2014
1573a84
updated namespace import
dpinte Sep 4, 2014
0f90b1e
moved quantlib.settings pyx file in the quantlib dir (removed
dpinte Sep 4, 2014
076f577
ignore the QL dll if present
dpinte Sep 4, 2014
1a61a44
adding notes about the windows build
dpinte Sep 5, 2014
cf164d5
add conditional include for the platform
dpinte Sep 5, 2014
8f9a0be
fix setup.py: QL_LIBRARY was defined only for windows
dpinte Sep 5, 2014
b64219b
stupid fix to an ifdef and added boost include path
dpinte Sep 5, 2014
6be7941
add info about copying the dll on the path
dpinte Sep 5, 2014
86ef5eb
helper script for def file generation based on .obj
dpinte Sep 11, 2014
469a25e
adding some pragam to ignore warnings on the local settings.hpp
dpinte Sep 11, 2014
e8d33c0
added some explanations on the skipped symbols
dpinte Sep 11, 2014
ecee16e
adding full instruction with .def file generation
dpinte Sep 11, 2014
6a77e60
adding reference to the getting started
dpinte Sep 11, 2014
32702f1
ignoring .def files
dpinte Sep 11, 2014
a4f5e84
removed manually created def file
dpinte Sep 11, 2014
aa05013
added changelog entry
dpinte Sep 11, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,6 +1,8 @@
build/*
docs/build
quantlib.egg-info/*
QuantLib.dll
symbol_win*.def
*.cpp
*.so
*.h
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.txt
@@ -1,6 +1,12 @@
PyQL CHANGELOG
==============

Pre 0.2
-------

Builds are finally usable on Windows 32 and 64 bit (two tests are failing due
to numerical issues but the Singleton problem is fixed)

Release 0.1
-----------

Expand Down
12 changes: 2 additions & 10 deletions README.md
Expand Up @@ -19,13 +19,5 @@ Prerequisites
Building the library
--------------------

The build and test suite can be run as follows::

make clean
make build
make tests

To build the library on Mac OS X 10.9, the QuantLib library must be linked
against libstdc++. To do so, set the environment variables `CXXFLAGS` and
`LDFLAGS` to `-stlib=libstdc++ -mmacosx-version-min=10.6` before building
from source.
See the getting_started.rst documentation in docs/source for the
full details!
4 changes: 3 additions & 1 deletion cpp_layer/mc_vanilla_engine_support_code.cpp
Expand Up @@ -6,8 +6,10 @@

#include <string>
#include <iostream>
#include <ql/quantlib.hpp>
#include <ql/pricingengines/vanilla/mceuropeanhestonengine.hpp>
#include <ql/processes/hestonprocess.hpp>
#include <ql/math/randomnumbers/rngtraits.hpp>
#include <ql/exercise.hpp>

namespace QuantLib {

Expand Down
3 changes: 2 additions & 1 deletion cpp_layer/mc_vanilla_engine_support_code.hpp
Expand Up @@ -5,8 +5,9 @@
*/

#include <string>
#include <ql/quantlib.hpp>
#include <ql/pricingengines/vanilla/mceuropeanhestonengine.hpp>
#include <ql/processes/hestonprocess.hpp>
#include <ql/math/randomnumbers/rngtraits.hpp>

namespace QuantLib {

Expand Down
12 changes: 11 additions & 1 deletion cpp_layer/ql_settings.cpp
@@ -1,8 +1,18 @@
#include <ql/time/date.hpp>

#ifdef WIN32
// using a custom settings.hpp that exposes the Setting class with dllimport
// This is required to make sure the Singleton is properly shared between the
// Cython pyd's.
#include <settings.hpp>
#else
#include <ql/settings.hpp>
#endif


using namespace QuantLib;

namespace QL {
namespace QuantLib {
void set_evaluation_date(Date& evaluation_date) {
Settings::instance().evaluationDate() = evaluation_date;
}
Expand Down
3 changes: 1 addition & 2 deletions cpp_layer/ql_settings.hpp
Expand Up @@ -5,9 +5,8 @@
*/

#include <ql/time/date.hpp>
#include <ql/settings.hpp>

namespace QL {
namespace QuantLib {
QuantLib::Date get_evaluation_date();
void set_evaluation_date(QuantLib::Date& evaluation_date);
}
193 changes: 193 additions & 0 deletions cpp_layer/settings.hpp
@@ -0,0 +1,193 @@
// !! Patched version of ql/settings.hpp doing a dllimport on Settings
#pragma warning(disable:4251)
#pragma warning(disable:4275)
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
Copyright (C) 2007, 2011 Ferdinando Ametrano
Copyright (C) 2007 Fran�ois du Vignaud
Copyright (C) 2004, 2005, 2007, 2009 StatPro Italia srl

This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/

QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/

/*! \file settings.hpp
\brief global repository for run-time library settings
*/

#ifndef quantlib_settings_hpp
#define quantlib_settings_hpp

#include <ql/patterns/singleton.hpp>
#include <ql/time/date.hpp>
#include <ql/utilities/observablevalue.hpp>
#include <boost/optional.hpp>

namespace QuantLib {

//! global repository for run-time library settings
class __declspec(dllimport) Settings : public Singleton<Settings> {
friend class Singleton<Settings>;
private:
Settings();
class DateProxy : public ObservableValue<Date> {
public:
DateProxy();
DateProxy& operator=(const Date&);
operator Date() const;
};
friend std::ostream& operator<<(std::ostream&, const DateProxy&);
public:
//! the date at which pricing is to be performed.
/*! Client code can inspect the evaluation date, as in:
\code
Date d = Settings::instance().evaluationDate();
\endcode
where today's date is returned if the evaluation date is
set to the null date (its default value;) can set it to a
new value, as in:
\code
Settings::instance().evaluationDate() = d;
\endcode
and can register with it, as in:
\code
registerWith(Settings::instance().evaluationDate());
\endcode
to be notified when it is set to a new value.
\warning a notification is not sent when the evaluation
date changes for natural causes---i.e., a date
was not explicitly set (which results in today's
date being used for pricing) and the current date
changes as the clock strikes midnight.
*/
DateProxy& evaluationDate();
const DateProxy& evaluationDate() const;

/*! Call this to prevent the evaluation date to change at
midnight (and, incidentally, to gain quite a bit of
performance.) If no evaluation date was previously set,
it is equivalent to setting the evaluation date to
Date::todaysDate(); if an evaluation date other than
Date() was already set, it has no effect.
*/
void anchorEvaluationDate();
/*! Call this to reset the evaluation date to
Date::todaysDate() and allow it to change at midnight. It
is equivalent to setting the evaluation date to Date().
This comes at the price of losing some performance, since
the evaluation date is re-evaluated each time it is read.
*/
void resetEvaluationDate();

/*! This flag specifies whether or not Events occurring on the reference
date should, by default, be taken into account as not happened yet.
It can be overridden locally when calling the Event::hasOccurred
method.
*/
bool& includeReferenceDateEvents();
bool includeReferenceDateEvents() const;

/*! \deprecated Use includeReferenceDateEvents() instead */
QL_DEPRECATED
bool& includeReferenceDateCashFlows() {
return includeReferenceDateEvents();
}
/*! \deprecated Use includeReferenceDateEvents() instead */
QL_DEPRECATED
bool includeReferenceDateCashFlows() const {
return includeReferenceDateEvents();
}

/*! If set, this flag specifies whether or not CashFlows
occurring on today's date should enter the NPV. When the
NPV date (i.e., the date at which the cash flows are
discounted) equals today's date, this flag overrides the
behavior chosen for includeReferenceDate. It cannot be overridden
locally when calling the CashFlow::hasOccurred method.
*/
boost::optional<bool>& includeTodaysCashFlows();
boost::optional<bool> includeTodaysCashFlows() const;

bool& enforcesTodaysHistoricFixings();
bool enforcesTodaysHistoricFixings() const;
private:
DateProxy evaluationDate_;
bool includeReferenceDateEvents_;
boost::optional<bool> includeTodaysCashFlows_;
bool enforcesTodaysHistoricFixings_;
};


// helper class to temporarily and safely change the settings
class SavedSettings {
public:
SavedSettings();
~SavedSettings();
private:
Date evaluationDate_;
bool includeReferenceDateEvents_;
boost::optional<bool> includeTodaysCashFlows_;
bool enforcesTodaysHistoricFixings_;
};


// inline

inline Settings::DateProxy::operator Date() const {
if (value() == Date())
return Date::todaysDate();
else
return value();
}

inline Settings::DateProxy& Settings::DateProxy::operator=(const Date& d) {
ObservableValue<Date>::operator=(d);
return *this;
}

inline Settings::DateProxy& Settings::evaluationDate() {
return evaluationDate_;
}

inline const Settings::DateProxy& Settings::evaluationDate() const {
return evaluationDate_;
}

inline bool& Settings::includeReferenceDateEvents() {
return includeReferenceDateEvents_;
}

inline bool Settings::includeReferenceDateEvents() const {
return includeReferenceDateEvents_;
}

inline boost::optional<bool>& Settings::includeTodaysCashFlows() {
return includeTodaysCashFlows_;
}

inline boost::optional<bool> Settings::includeTodaysCashFlows() const {
return includeTodaysCashFlows_;
}

inline bool& Settings::enforcesTodaysHistoricFixings() {
return enforcesTodaysHistoricFixings_;
}

inline bool Settings::enforcesTodaysHistoricFixings() const {
return enforcesTodaysHistoricFixings_;
}

}

#endif
9 changes: 7 additions & 2 deletions cpp_layer/simulate_support_code.cpp
@@ -1,12 +1,17 @@
#include<ql/quantlib.hpp>
#include <ql/math/randomnumbers/rngtraits.hpp>
#include <ql/methods/montecarlo/multipathgenerator.hpp>
#include <ql/stochasticprocess.hpp>
#include <ql/methods/montecarlo/path.hpp>

/*
* Multipath simulator. A multipath simulator is needed when the stochastic
* process involves more than 1 brownian. For example, Heston's model involves
* the simulation of the variance process and the simulation of the price process
*/

namespace QuantLib {
using namespace QuantLib;

namespace PyQL {

void simulateMP(const boost::shared_ptr<StochasticProcess>& process,
int nbPaths, int nbSteps, Time horizon, BigNatural seed,
Expand Down
11 changes: 8 additions & 3 deletions cpp_layer/simulate_support_code.hpp
@@ -1,12 +1,17 @@
#include<ql/quantlib.hpp>
#include <ql/math/randomnumbers/rngtraits.hpp>
#include <ql/methods/montecarlo/multipathgenerator.hpp>
#include <ql/stochasticprocess.hpp>
#include <ql/methods/montecarlo/path.hpp>

namespace QuantLib {
using namespace QuantLib;

namespace PyQL {

/*
* Multipath simulator
*/

void simulateMP(const boost::shared_ptr<StochasticProcess>& process,
void simulateMP(const boost::shared_ptr<QuantLib::StochasticProcess>& process,
int nbPaths, int nbSteps, Time horizon, BigNatural seed,
bool antithetic_variates, double *res);

Expand Down