通过 SWIG 为 C# 编译 Quantlib

发布于 2024-09-11 09:16:38 字数 826 浏览 4 评论 0原文

有人有使用 SWIG 的经验吗?我目前正在研究 QuantLib 并发现可以使用 SWIG 生成 C# 代码。我们正在探索使用 QuantLib 和专有闭源库(可能以 .Net dll 形式提供)创建财务函数组合库的选项。我们的想法是将这两者结合起来创建一个统一的超级库。我已经看到了 QuantLib 的.Net 端口,但似乎它没有得到积极维护(并且不完全确定实际移植了多少),所以我避免它。

第 1 步是评估生成可在“任何地方”使用的库的难度,即 MS Office 应用程序(通过 VBA)、控制台应用程序以及服务器端(例如 Web 应用程序)。我认为这涉及 COM 互操作,但我不知道从哪里开始,也不知道我是否走在正确的轨道上。

我没有 C++ 经验; COM 是我一直关注的东西(目前对我来说是一个流行词)。我知道与此主题相关的相关 MSDN 文章。

我正在寻求以下方面的帮助:

  1. 是否有在 C# 中使用 QuantLib 的替代方案?
  2. 对于我的开发环境,我需要什么?
  3. 有谁知道通过 SWIG 编译的即用型 QuantLib C# 库? (一等奖=对我来说更少的工作)

有什么帮助吗?

编辑:我已接受我的答案作为正确的答案,除非提供了更好的答案。

Anyone have any experience using SWIG? I am currently researching QuantLib and saw that C# code can be generated using SWIG. We are exploring options to create a combined library of financial functions using QuantLib and a proprietary closed source library (which will probably be made available as .Net dlls). The idea is to combine both of these to create a unified super library. I have seen the .Net port of QuantLib, but it seems that it is not actively maintained (and not entirely sure of how much was actually ported), so I am avoiding it.

Step 1 of this is to evaluate the difficulty in producing a library that can be used 'anywhere' i.e. MS office applications ( via VBA), console apps as well server-side (eg web apps). I assume that this involves COM Interop, but I have no clue where to start or if I am even on the right track.

I have no experience with C++; and COM is something (a buzzword to me at the moment) that I have glazed over. I am aware of the relevant MSDN articles related to this topic.

I am looking for help along the following lines:

  1. Are there alternatives to using QuantLib in C#?
  2. With respect to my development environment, what would I need?
  3. Does anyone know of a ready-to-use QuantLib C# library compiled via SWIG? (first prize = less work for me)

Any help appreciated?

Edit: I have accepted my answer as the correct one unless there is a better one provided.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好听的两个字的网名 2024-09-18 09:16:38

因此,SWIG 的 C# 绑定似乎可用。需要浏览SVN 存储库或列表SouceForge 上的文件 来查找它们。

SWIG 文件夹包含多个子文件夹,具体取决于您选择的语言,在我的例子中,C# 是我感兴趣的一个。您需要首先下载 SWIG 并将其可执行文件添加到系统 PATH 变量中。

请务必阅读 Readme.txt,因为它包含有关还需要创建的 QL_DIR 环境变量的详细信息。

这可能是 VS Express 的限制 - 但解决方案文件同时包含 C# 项目和 C++ 项目,其中任何时候只能打开其中的 C# 或 C++ 部分。我的建议是为 C++ 和 C# 项目创建单独的解决方案文件。

来自 .Net 背景的 lib 文件、obj 文件以及所有其他与 c++ 相关的爵士乐需要一些时间来适应。

获取可用的 C# 库所采取的步骤

  1. 按照此处的说明下载 QuantLib 和 Boost
  2. 下载SourceForge 中的 QuantLib-SWIG 文件夹编辑:有一个主页上提供了 zip 下载。它在子文件夹中列出。检查 Bindings 下的 v1.0 文件夹
  3. 运行位于 QuantLib-SWIG\CSharp 文件夹中的 swig.cmd 文件(需要先下载 SWIG) () --> 这会生成 Quantlib 的 cs 包装文件。
  4. 构建 C++ 项目 NQuantLibc - 请注意,此处创建的 dll 需要始终与 NQuantlib C# 构建的 dll 一起放置。位于可由 DLLImport 属性读取的位置(请参阅 动态链接库 在 MSDN 上的搜索顺序 获取位置列表)
  5. 构建 C# 项目 NQuantLib

就我的开发环境而言,什么会我需要吗?
<罢工>
当前版本的 QuantLib 似乎只能使用 VS 2008 构建。VS 2010 发生了一些更改,导致编译出现一些问题。 C# 项目构建良好,但请记住将目标框架从 v4 更改为 v3.5 并降低版本。

注意:在撰写本文时,QL_HEX_VERSION 数字存在问题在 C++ SWIG 项目的源文件中。运行swig.cmd后打开VS项目,并将quantlib_wrap.cpp第344行更改为

#if QL_HEX_VERSION < 0x010001f0//0x010100f0

我已向项目作者发送电子邮件,并等待反馈。 编辑: Luigi,正确地告诉我这是 SVN(我使用的)中代码的任何问题。他建议 QuantLib-SWIG-1.0应使用 .zip 绑定。

Quantlib 还基于最新版本的 VC++ 2010 构建。

So it would seem that the C# bindings for SWIG are available. One needs to browse the SVN repository or list of files on SouceForge to find them.

The SWIG folder contains several subfolders, depending on your language of choice, in my case C# was the one that interested me. You will need to download SWIG first and it the executable to system PATH variable.

Make sure to read the Readme.txt as it contains details about the QL_DIR environment variable that also needs to be created.

This may be a limitation of VS Express - but the solution file contains both the C# project and C++ project, of which only either the C# or C++ portions can be opened at any time. My suggestion would be to created separate solution files for the C++ and the C# projects.

Coming from a .Net background, lib files, obj files and the all the other jazz associated with c++ takes some time to getting use to.

Steps taken to get a working C# library

  1. Download QuantLib and Boost as described here
  2. Download the tar ball of the QuantLib-SWIG folder from SourceForge. Edit: There is a download of the zip available on the home page. Its listed within the subfolders. Check the v1.0 folders under Bindings
  3. Run the swig.cmd file located in QuantLib-SWIG\CSharp folder (you need to download SWIG first() --> this generates the cs wrapper files for Quantlib.
  4. Build the c++ project NQuantLibc - note the dll created here needs to be always shipped with the NQuantlib C# built dll. It needs to be placed in a location that is readable by the DLLImport attribute. (See Dynamic-Link Library Search Order on MSDN for list of locations)
  5. Build the C# project NQuantLib

With respect to my development environment, what would I need?

It seems that the current version of QuantLib only builds with VS 2008. There have been some changes to VS 2010 which causes some issues with compilation. The C# project builds fine, however just remember to change the Target Framework from v4 to v3.5 to lower.

Note: As the time of writing this there was an issue with the QL_HEX_VERSION number in the source files of the C++ SWIG project. After running the swig.cmd open the VS project, and change Line 344 of quantlib_wrap.cpp to

#if QL_HEX_VERSION < 0x010001f0//0x010100f0

I have emailed the project author, and awaiting feedback. Edit: Luigi, correctly informed me that this is any issue with the code in SVN (which I used). He suggested that the QuantLib-SWIG-1.0.zip bindings should be used.

Quantlib also build on VC++ 2010 with the latest release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文