我应该如何构建金融 DSL?

发布于 2024-08-11 04:10:33 字数 422 浏览 6 评论 0原文

我决定建立一个数据库来跟踪我在邮件中收到的信用卡报价,而一个令人困惑的因素是如何表示这些报价。考虑到最低财务费用和可变利率以及最低可变利率,它会比“10.99%”更复杂一些。我决定,如果我有机会比较或分析这些报价的趋势,我需要构建一种语言来表示这些事物。

问题是,我该如何表示呢?这些公式太复杂,无法通过创建字段来建模,因此我只需将公式存储在数据库中即可。是的,这意味着模糊数据和执行之间的界限,但由于这是一个个人项目,我并不那么担心。

  1. 嵌入式python。将公式表示为Python,只需绑定相关变量并调用公式即可。
  2. 使用领域特定语言。我不是第一个想到以这种方式表示事物的人,事实上我知道我不是。有没有任何免费的公共语言可以代表这一点?

谁能就哪种方法更好提供建议?

I've decided to build a database tracking the credit card offers I get in the mail, and one confounding factor has been how to represent the offers. With minimum finance charges and variable rates and mimimum variable rates it gets a bit more complex than "10.99 percent". I've decided I need to construct a language to represent these things if I have a shot at comparing or trending these offers.

The question is, how do I represent this? The formulas are far too complex to model by creating fields, so I'll just store the formula in the DB in all it's glory. Yes, this means blurring the line between data and execution, but since this is a personal project I'm not so worried.

  1. Embedded python. Represent the formula as Python and just bind relevant variables and call the formula.
  2. Use a Domain Specific Language. I can't be the first person to think of representing things this way, and in fact I know I'm not. Are there any free, public languages that can represent this?

Can anyone offer advice on which approach is better?

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

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

发布评论

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

评论(3

怎言笑 2024-08-18 04:10:34

这听起来有点类似于西蒙·佩顿·琼斯等人的作品。 使用组合器表示金融合约库,包括 Haskell 中的实现,包括在其上运行评估函数以进行计算的能力给定某种模型的合同价值。我对金融的了解不够,无法告诉您这是否正是您正在寻找的,但听起来似乎是正确的。

至于你的具体问题,我通常更喜欢嵌入式领域特定语言(即嵌入在宿主语言中的类似 DSL 的结构,例如带有面向对象元编程的 Ruby、带有宏的Scheme 或 Haskell 组合器库),因为它给出了您可以免费使用宿主语言的全部功能;通常,当编写具有自己的语法、执行模型、运行时等的领域特定语言时,您会遇到一些事情,如果您有可用的现有语言,那么这些事情很容易做到,但由于您没有可用的语言,所以处理起来很痛苦。没有在 DSL 中实现一些东西。

This sounds somewhat similar to the work by Simon Peyton Jones et al. on representing financial contracts using combinator libraries, including an implementation in Haskell, including the ability to run evaluation functions over them to compute the value of the contract given some model. I don't know enough about finance to tell you if this is exactly what you're looking for, but it sounds like it's in the right ballpark.

As to your specific question, I generally prefer embedded domain specific languages (that is, DSL-like constructs embedded in a host language, such as Ruby with its object oriented metaprogramming, Scheme with its macros, or Haskell combinator libraries), since it give you the full power of the host language for free; usually when writing a domain specific language with its own syntax, execution model, runtime, and so on, you run into things that would be easy to do if you had an existing language available, but are a pain to deal with since you haven't implemented something in your DSL.

于我来说 2024-08-18 04:10:34

如果您觉得必须将公式存储在数据库中,我会投票支持嵌入式 Python。

DSL 似乎有点大材小用;您已经拥有了一种用于评估公式的完美语言。

My vote is for Embedded Python, if you feel you must store the formulas in the database.

A DSL seems like overkill; you already have a perfectly good language for evaluating formulas.

—━☆沉默づ 2024-08-18 04:10:34

另一种选择是使用 R。它有一个很好的公式表示;您将其存储为字符串,然后使用 eval() 函数对其进行评估。还有大量的金融图书馆(请参阅CRAN 金融视图),包括Rmetrics

R 还可以与其他语言很好地交互,包括 python、java 和 C++。您提到了Python:如果您想编写包装脚本,可以使用RPy。

Another option is to use R. It has a nice formula representation; you store it as a string and then evaluate it with the eval() function. There are also extensive financial libraries (see the CRAN finance view), including Rmetrics.

R also interacts very nicely with other languages, including python, java, and C++. You mentioned Python: you can use RPy if you want to write a wrapper script.

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