金融领域的 DSL(领域特定语言)

发布于 2024-07-04 11:12:34 字数 412 浏览 7 评论 0原文

有人使用过 DSL(领域特定语言) 在金融领域? 我计划在我正在开发的应用程序中引入某种 DSL 支持,并想分享一些想法。

我正处于确定哪些是最稳定的领域元素并选择可以通过 DSL 更好地实现的功能的阶段。 我还没有定义第一个功能的语法。

Has anyone worked with DSLs (Domain Specific Languages) in the finance domain? I am planning to introduce some kind of DSL support in the application that I am working on and would like to share some ideas.

I am in a stage of identifying which are the most stable domain elements and selecting the features which would be better implemented with the DSL. I have not yet defined the syntax for this first feature.

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

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

发布评论

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

评论(5

等风来 2024-07-11 11:12:34

Simon Peyton Jones 和 Jean-Marc-Erby 将金融合约优雅地建模为 DSL。 他们的 DSL 嵌入 Haskell,在论文 如何编写财务合同

Financial contracts have been modeled elegantly as a DSL by Simon Peyton Jones and Jean-Marc-Erby. Their DSL, embedded in Haskell, is presented in the paper How to write a financial contract.

倾城月光淡如水﹏ 2024-07-11 11:12:34

杰·菲尔兹 (Jay Fields) 和奥比·费尔南德斯 (Obie Fernandez) 就该主题撰写了大量文章并进行了广泛讨论。

您还可以在 Martin Fowler 的著作中找到有关实现 DSL 的一般内容(但不是专门针对金融的)。

Jay Fields and Obie Fernandez have written and talked extensively on the subject.

You'll also find general stuff on implementing DSL in Martin Fowler's writings (but not specific to finance).

友谊不毕业 2024-07-11 11:12:34

领域特定语言 (DSL) 最常用于表示金融工具。 规范的论文是 Simon Peyton Jones 的 撰写合约:金融工程中的一次冒险,它代表了使用Haskell 中的组合器库。 组合器方法最突出的用途是 LexiFi 的 MLFi 语言,它是构建在 OCaml 之上(他们的首席执行官 Jean-Marc Eber 是撰写合同论文的合著者)。 巴克莱一度复制了该方法并描述了一些额外的好处,例如生成人类可读的数学定价公式的能力(商业用途:在奇异贸易中发挥作用)。

金融合约的 DSL 通常是使用 Haskell、Scala 或 OCaml 等函数式语言的嵌入来构建的。 函数式编程语言在金融行业的采用将继续使这种方法具有吸引力。

除了表示金融工具之外,DSL 还用于金融领域:

我维护着完整的金融 DSL 论文、演讲和其他资源列表,位于 http://www.dslfin.org/resources.html

如果您想认识从事金融系统 DSL 工作的专业人士和研究人员,10 月 1 日将在佛罗里达州迈阿密举行的 MODELS 2013 会议上举办研讨会:http://www.dslfin.org/

Domain specific languages (DSLs) are most commonly used to represent financial instruments. The canonical paper is Simon Peyton Jones' Composing Contracts: an Adventure in Financial Engineering which represents contracts using a combinator library in Haskell. The most prominent use of the combinator approach is LexiFi's MLFi language, which is built on top of OCaml (their CEO, Jean-Marc Eber, is a co-author on the Composing Contracts paper). Barclay's at one point copied the approach and described some additional benefits, such as the ability to generate human-readable mathematical pricing formulas (Commercial Uses: Going Functional on Exotic Trades).

DSLs for financial contracts are typically built using an embedding in a functional language such as Haskell, Scala, or OCaml. The uptake of functional programming languages in the financial industry will continue to make this approach attractive.

In addition to representing financial instruments, DSLs are also used in finance for:

I maintain a complete list of financial DSLs papers, talks, and other resources at http://www.dslfin.org/resources.html.

If you'd like to meet professionals and researchers working with DSLs for financial systems, there's an upcoming workshop on October 1st at the MODELS 2013 conference in Miami, Florida: http://www.dslfin.org/

寄离 2024-07-11 11:12:34

我们致力于与 Fairmat ( http://www.fairmat.com ) 创建财务评估 DSL 的想法

-它公开了一个 DSL,可用于表达支付和支付依赖性
-它包含一个扩展模型,用于使用 .NET/C# 和我们的底层数学库创建新型分析和理论动力学实现(请参阅 https://github.com/fairmat

We worked on the idea of creating a financial valuation DSL with Fairmat ( http://www.fairmat.com )

-it exposes a DSL which can be used to express pay-offs and payment dependencies
-it contains an extension model for creating new types of analytic and implementations of theoretical dynamics using .NET/ C# with our underlying math library (see some open source examples at https://github.com/fairmat

森罗 2024-07-11 11:12:34

我认为 Simon Peyton Jones 和 Jean Marc Eber 的工作最令人印象深刻,因为“编写合约:金融工程的一次冒险”以及由此衍生的一切:“LexiFi 和 MLFi"。

发现 Shahbaz Chaudhary 的 Scala 实现最具吸引力,因为 MLFi 并不普遍可用(并且因为 Scala 作为函数式语言是比 Haskell 更容易访问)。

请参阅“金融和软件工程的冒险”以及引用的其他材料从那里。

我将敢于复制一个片段来了解这个实现可以做什么。

  object Main extends App {
  //Required for doing LocalDate comparisons...a scalaism
  implicit val LocalDateOrdering = scala.math.Ordering.fromLessThan[java.time.LocalDate]{case (a,b) => (a compareTo b) < 0}

  //custom contract
  def usd(amount:Double) = Scale(Const(amount),One("USD"))
  def buy(contract:Contract, amount:Double) = And(contract,Give(usd(amount)))
  def sell(contract:Contract, amount:Double) = And(Give(contract),usd(amount))
  def zcb(maturity:LocalDate, notional:Double, currency:String) = When(maturity, Scale(Const(notional),One(currency)))
  def option(contract:Contract) = Or(contract,Zero())
  def europeanCallOption(at:LocalDate, c1:Contract, strike:Double) = When(at, option(buy(c1,strike)))
  def europeanPutOption(at:LocalDate, c1:Contract, strike:Double) = When(at, option(sell(c1,strike)))
  def americanCallOption(at:LocalDate, c1:Contract, strike:Double) = Anytime(at, option(buy(c1,strike)))
  def americanPutOption(at:LocalDate, c1:Contract, strike:Double) = Anytime(at, option(sell(c1,strike)))

  //custom observable
  def stock(symbol:String) = Scale(Lookup(symbol),One("USD"))
  val msft = stock("MSFT")


  //Tests
  val exchangeRates = collection.mutable.Map(
    "USD" -> LatticeImplementation.binomialPriceTree(365,1,0),
    "GBP" -> LatticeImplementation.binomialPriceTree(365,1.55,.0467),
    "EUR" -> LatticeImplementation.binomialPriceTree(365,1.21,.0515)
    )
  val lookup = collection.mutable.Map(
    "MSFT" -> LatticeImplementation.binomialPriceTree(365,45.48,.220),
    "ORCL" -> LatticeImplementation.binomialPriceTree(365,42.63,.1048),
    "EBAY" -> LatticeImplementation.binomialPriceTree(365,53.01,.205)
  )
  val marketData = Environment(
    LatticeImplementation.binomialPriceTree(365,.15,.05), //interest rate (use a universal rate for now)
    exchangeRates, //exchange rates
    lookup
  )

  //portfolio test
  val portfolio = Array(
    One("USD")
    ,stock("MSFT")
    ,buy(stock("MSFT"),45)
    ,option(buy(stock("MSFT"),45))
    ,americanCallOption(LocalDate.now().plusDays(5),stock("MSFT"),45)
  )

  for(contract <- portfolio){
    println("===========")
    val propt = LatticeImplementation.contractToPROpt(contract)
    val rp = LatticeImplementation.binomialValuation(propt, marketData)
    println("Contract: "+contract)
    println("Random Process(for optimization): "+propt)
    println("Present val: "+rp.startVal())
    println("Random Process: \n"+rp)
  }

}

Tomas Petricek 在 F# 方面的出色工作非常值得探索。

除了“DSL”范式之外,我建议我们需要许多其他强大范式的贡献,才能有一个完整的方法来表示金融工具和金融合同的复杂语义,同时满足“大数据”现实。

值得回顾一下这里提到的一些语言: http://www.dslfin.org/resources.html

I think that the work of Simon Peyton Jones and Jean Marc Eber is the most impressive because of "Composing Contracts: an Adventure in Financial Engineering" and everything derived from that: "LexiFi and MLFi".

Found Shahbaz Chaudhary's Scala implementation the most attractive given that MLFi is not generally available (and because Scala as functional language is more accessible that Haskell).

See "Adventures in financial and software engineering" and the other material referenced from there.

I will dare to replicate a snipped for an idea of what this implementation can do.

  object Main extends App {
  //Required for doing LocalDate comparisons...a scalaism
  implicit val LocalDateOrdering = scala.math.Ordering.fromLessThan[java.time.LocalDate]{case (a,b) => (a compareTo b) < 0}

  //custom contract
  def usd(amount:Double) = Scale(Const(amount),One("USD"))
  def buy(contract:Contract, amount:Double) = And(contract,Give(usd(amount)))
  def sell(contract:Contract, amount:Double) = And(Give(contract),usd(amount))
  def zcb(maturity:LocalDate, notional:Double, currency:String) = When(maturity, Scale(Const(notional),One(currency)))
  def option(contract:Contract) = Or(contract,Zero())
  def europeanCallOption(at:LocalDate, c1:Contract, strike:Double) = When(at, option(buy(c1,strike)))
  def europeanPutOption(at:LocalDate, c1:Contract, strike:Double) = When(at, option(sell(c1,strike)))
  def americanCallOption(at:LocalDate, c1:Contract, strike:Double) = Anytime(at, option(buy(c1,strike)))
  def americanPutOption(at:LocalDate, c1:Contract, strike:Double) = Anytime(at, option(sell(c1,strike)))

  //custom observable
  def stock(symbol:String) = Scale(Lookup(symbol),One("USD"))
  val msft = stock("MSFT")


  //Tests
  val exchangeRates = collection.mutable.Map(
    "USD" -> LatticeImplementation.binomialPriceTree(365,1,0),
    "GBP" -> LatticeImplementation.binomialPriceTree(365,1.55,.0467),
    "EUR" -> LatticeImplementation.binomialPriceTree(365,1.21,.0515)
    )
  val lookup = collection.mutable.Map(
    "MSFT" -> LatticeImplementation.binomialPriceTree(365,45.48,.220),
    "ORCL" -> LatticeImplementation.binomialPriceTree(365,42.63,.1048),
    "EBAY" -> LatticeImplementation.binomialPriceTree(365,53.01,.205)
  )
  val marketData = Environment(
    LatticeImplementation.binomialPriceTree(365,.15,.05), //interest rate (use a universal rate for now)
    exchangeRates, //exchange rates
    lookup
  )

  //portfolio test
  val portfolio = Array(
    One("USD")
    ,stock("MSFT")
    ,buy(stock("MSFT"),45)
    ,option(buy(stock("MSFT"),45))
    ,americanCallOption(LocalDate.now().plusDays(5),stock("MSFT"),45)
  )

  for(contract <- portfolio){
    println("===========")
    val propt = LatticeImplementation.contractToPROpt(contract)
    val rp = LatticeImplementation.binomialValuation(propt, marketData)
    println("Contract: "+contract)
    println("Random Process(for optimization): "+propt)
    println("Present val: "+rp.startVal())
    println("Random Process: \n"+rp)
  }

}

The excellent work of Tomas Petricek in F# is very much worth exploring.

Beyond the "DSL" paradigm I suggest we'd need contributions from a number of other powerful paradigms to have a complete way to represent the complex semantics of financial instruments and financial contracts while meeting the "big data" realities.

Worth reviewing some languages mentioned here: http://www.dslfin.org/resources.html

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