财务中的DSL(领域特定语言)

时间:2022-04-29 12:39:40

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.

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

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.

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

5 个解决方案

#1


8  

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

Jay Fields和Obie Fernandez就这个问题进行了广泛的撰写和讨论。

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

您还可以在Martin Fowler的着作中找到有关实施DSL的一般内容(但不是专门针对财务)。

#2


13  

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.

Simon Peyton Jones和Jean-Marc-Erby将金融合约优雅地模仿为DSL。嵌入在Haskell中的DSL在“如何编写金融合同”一文中有所介绍。

#3


4  

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).

域特定语言(DSL)最常用于表示金融工具。规范性论文是Simon Peyton Jones的“撰写合同:金融工程中的冒险”,它代表了在Haskell中使用组合器库的合同。组合方法最突出的用途是LexiFi的MLFi语言,它建立在OCaml之上(他们的首席执行官Jean-Marc Eber是撰写合同文件的共同作者)。 Barclay一度抄袭了这种方法,并描述了一些额外的好处,例如能够生成人类可读的数学定价公式(商业用途:在异国交易中实现功能)。

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.

用于金融合同的DSL通常使用诸如Haskell,Scala或OCaml之类的功能语言嵌入来构建。金融行业中功能性编程语言的使用将继续使这种方法具有吸引力。

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

除了代表金融工具,DSL还用于金融:

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

我在http://www.dslfin.org/resources.html上保留了完整的金融DSL论文,会谈和其他资源清单。

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/

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

#4


0  

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

我们致力于利用Fairmat创建财务评估DSL(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

- 暴露可用于表示支付和支付依赖关系的DSL - 它包含一个扩展模型,用于使用.NET / C#和我们的基础数学库创建新类型的分析和理论动态实现(参见一些开源示例在https://github.com/fairmat

#5


0  

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".

我认为Simon Peyton Jones和Jean Marc Eber的作品是最令人印象深刻的,因为“撰写合同:金融工程的冒险”以及从中获得的一切:“LexiFi和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).

发现Shahbaz Chaudhary的Scala实现是最有吸引力的,因为MLFi通常不可用(并且因为Scala作为函数式语言比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.

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

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.

除了“DSL”范式之外,我建议我们需要来自其他一些强有力范例的贡献,以便在满足“大数据”现实的同时,有一种完整的方式来表示金融工具和金融合约的复杂语义。

  • Probabilistic programming: Figaro, Stan, etc
  • 概率编程:费加罗,斯坦等

  • Big data analytics: R, Spark, SparkR
  • 大数据分析:R,Spark,SparkR

  • Scalable "data fabric" ("off heap memory"; across commodity hardware but also across languages): "DataFrames in Spark for Large Scale Data Science" (works with R, Scala/Java and Python)
  • 可扩展的“数据结构”(“堆外存储器”;跨商用硬件,也可跨语言):“用于大规模数据科学的Spark中的DataFrames”(与R,Scala / Java和Python一起使用)

  • Semantic web: "Financial Topic Models" and ontologies.
  • 语义网:“财务主题模型”和本体。

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

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

#1


8  

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

Jay Fields和Obie Fernandez就这个问题进行了广泛的撰写和讨论。

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

您还可以在Martin Fowler的着作中找到有关实施DSL的一般内容(但不是专门针对财务)。

#2


13  

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.

Simon Peyton Jones和Jean-Marc-Erby将金融合约优雅地模仿为DSL。嵌入在Haskell中的DSL在“如何编写金融合同”一文中有所介绍。

#3


4  

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).

域特定语言(DSL)最常用于表示金融工具。规范性论文是Simon Peyton Jones的“撰写合同:金融工程中的冒险”,它代表了在Haskell中使用组合器库的合同。组合方法最突出的用途是LexiFi的MLFi语言,它建立在OCaml之上(他们的首席执行官Jean-Marc Eber是撰写合同文件的共同作者)。 Barclay一度抄袭了这种方法,并描述了一些额外的好处,例如能够生成人类可读的数学定价公式(商业用途:在异国交易中实现功能)。

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.

用于金融合同的DSL通常使用诸如Haskell,Scala或OCaml之类的功能语言嵌入来构建。金融行业中功能性编程语言的使用将继续使这种方法具有吸引力。

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

除了代表金融工具,DSL还用于金融:

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

我在http://www.dslfin.org/resources.html上保留了完整的金融DSL论文,会谈和其他资源清单。

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/

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

#4


0  

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

我们致力于利用Fairmat创建财务评估DSL(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

- 暴露可用于表示支付和支付依赖关系的DSL - 它包含一个扩展模型,用于使用.NET / C#和我们的基础数学库创建新类型的分析和理论动态实现(参见一些开源示例在https://github.com/fairmat

#5


0  

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".

我认为Simon Peyton Jones和Jean Marc Eber的作品是最令人印象深刻的,因为“撰写合同:金融工程的冒险”以及从中获得的一切:“LexiFi和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).

发现Shahbaz Chaudhary的Scala实现是最有吸引力的,因为MLFi通常不可用(并且因为Scala作为函数式语言比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.

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

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.

除了“DSL”范式之外,我建议我们需要来自其他一些强有力范例的贡献,以便在满足“大数据”现实的同时,有一种完整的方式来表示金融工具和金融合约的复杂语义。

  • Probabilistic programming: Figaro, Stan, etc
  • 概率编程:费加罗,斯坦等

  • Big data analytics: R, Spark, SparkR
  • 大数据分析:R,Spark,SparkR

  • Scalable "data fabric" ("off heap memory"; across commodity hardware but also across languages): "DataFrames in Spark for Large Scale Data Science" (works with R, Scala/Java and Python)
  • 可扩展的“数据结构”(“堆外存储器”;跨商用硬件,也可跨语言):“用于大规模数据科学的Spark中的DataFrames”(与R,Scala / Java和Python一起使用)

  • Semantic web: "Financial Topic Models" and ontologies.
  • 语义网:“财务主题模型”和本体。

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

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