<p>Has anyone worked with <a href="http://www.google.com.br/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FDomain-specific_programming_language&amp;ei=QyWvSIXcC4foebjSlHs&amp;usg=AFQjCNFsZOnJm-AGmi5sxai8YI-0Al6wfA&amp;sig2=6nX5EkUmNkEwiSKAkUeyZQ" rel="noreferrer">DSLs (Domain Specific Languages)</a> 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.</p>

<p>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.</p>

[{'answer_id': 24167, 'author': 'Christian Lescuyer', 'author_id': 341, 'author_profile': 'https://Stackoverflow.com/users/341', 'pm_score': 4, 'selected': True, 'text': '<p>Jay Fields and Obie Fernandez have written and talked extensively on the subject.</p>\n\n<ul>\n<li>Jay Fields intro on <a href="http://blog.jayfields.com/2008/02/designing-domain-specific-language.html" rel="noreferrer">Domain Specific Languages</a></li>\n<li>Jay Fields\' series on <a href="http://bnl.jayfields.com/01_introduction.html" rel="noreferrer">Business Natural Language</a></li>\n<li>Obie Fernandez <a href="http://www.jroller.com/obie/entry/expressing_contract_terms_in_a" rel="noreferrer">Expressing Contract Terms in a DSL</a></li>\n<li>A very good <a href="http://www.infoq.com/presentations/fields-business-natural-languages-ruby" rel="noreferrer">presentation</a> on infoQ by Jay Fields</li>\n</ul>\n\n<p>You\'ll also find general stuff on implementing DSL in Martin Fowler\'s writings (but not specific to finance).</p>\n\n<ul>\n<li><a href="http://martinfowler.com/dslwip/" rel="noreferrer">DSL</a></li>\n</ul>\n'}, {'answer_id': 282991, 'author': 'namin', 'author_id': 34596, 'author_profile': 'https://Stackoverflow.com/users/34596', 'pm_score': 4, 'selected': False, 'text': '<p>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 <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.7885" rel="noreferrer">How to write a financial contract</a>.</p>\n'}, {'answer_id': 14170839, 'author': 'matteot', 'author_id': 1178837, 'author_profile': 'https://Stackoverflow.com/users/1178837', 'pm_score': 1, 'selected': False, 'text': '<p>We worked on the idea of creating a financial valuation DSL with Fairmat ( <a href="http://www.fairmat.com" rel="nofollow">http://www.fairmat.com</a> )</p>\n\n<p>-it exposes a DSL which can be used to express pay-offs and payment dependencies\n-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 <a href="https://github.com/fairmat" rel="nofollow">https://github.com/fairmat</a></p>\n'}, {'answer_id': 15983164, 'author': 'Todd Schiller', 'author_id': 402560, 'author_profile': 'https://Stackoverflow.com/users/402560', 'pm_score': 3, 'selected': False, 'text': '<p>Domain specific languages (DSLs) are most commonly used to represent financial instruments. The canonical paper is Simon Peyton Jones\' <a href="http://doi.acm.org/10.1145/351240.351267" rel="noreferrer">Composing Contracts: an Adventure in Financial Engineering</a> which represents contracts using a combinator library in Haskell. The most prominent use of the combinator approach is <a href="http://www.lexifi.com/product/technology/contract-description-language" rel="noreferrer">LexiFi\'s MLFi language</a>, 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 (<a href="http://dx.doi.org/10.1017/S0956796808007016" rel="noreferrer">Commercial Uses: Going Functional on Exotic Trades</a>).</p>\n\n<p>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.</p>\n\n<p>In addition to representing financial instruments, DSLs are also used in finance for:</p>\n\n<ul>\n<li>Modeling financial entities with ontology languages (<a href="http://www.omgwiki.org/OMG-FDTF/doku.php" rel="noreferrer">Financial Industry Business Ontology</a>)</li>\n<li>Replacing computations typically described using spreadsheets (<a href="http://doi.acm.org/10.1145/1411204.1411236" rel="noreferrer">http://doi.acm.org/10.1145/1411204.1411236</a>)</li>\n<li>Modeling pension plans (<a href="http://www.intentsoft.com/overview/case-study-financial-services/" rel="noreferrer">Case Study: Financial Services</a>)</li>\n<li>Analyzing financial market data (<a href="https://www.youtube.com/watch?v=54Vv3Os3Ep4" rel="noreferrer">The Hedgehog Language</a>)</li>\n</ul>\n\n<p>I maintain a complete list of financial DSLs papers, talks, and other resources at <a href="http://www.dslfin.org/resources.html" rel="noreferrer">http://www.dslfin.org/resources.html</a>.</p>\n\n<p>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: <a href="http://www.dslfin.org/" rel="noreferrer">http://www.dslfin.org/</a></p>\n'}, {'answer_id': 31770859, 'author': 'SemanticBeeng', 'author_id': 4032515, 'author_profile': 'https://Stackoverflow.com/users/4032515', 'pm_score': 1, 'selected': False, 'text': '<p>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: "<a href="https://www.lexifi.com/product/technology/contract-description-language" rel="nofollow noreferrer">LexiFi and MLFi</a>".</p>\n\n<p>Found <a href="http://falconair.github.io/" rel="nofollow noreferrer">Shahbaz Chaudhary\'s</a> Scala implementation the most attractive given that MLFi is not generally available (and because Scala as functional language is more accessible that Haskell).</p>\n\n<p>See <a href="http://falconair.github.io/2015/01/30/composingcontracts.html" rel="nofollow noreferrer">"Adventures in financial and software engineering"</a> and the other material referenced from there. </p>\n\n<p>I will dare to replicate a snipped for an idea of what this implementation can do.</p>\n\n<pre><code>  object Main extends App {\n  //Required for doing LocalDate comparisons...a scalaism\n  implicit val LocalDateOrdering = scala.math.Ordering.fromLessThan[java.time.LocalDate]{case (a,b) =&gt; (a compareTo b) &lt; 0}\n\n  //custom contract\n  def usd(amount:Double) = Scale(Const(amount),One("USD"))\n  def buy(contract:Contract, amount:Double) = And(contract,Give(usd(amount)))\n  def sell(contract:Contract, amount:Double) = And(Give(contract),usd(amount))\n  def zcb(maturity:LocalDate, notional:Double, currency:String) = When(maturity, Scale(Const(notional),One(currency)))\n  def option(contract:Contract) = Or(contract,Zero())\n  def europeanCallOption(at:LocalDate, c1:Contract, strike:Double) = When(at, option(buy(c1,strike)))\n  def europeanPutOption(at:LocalDate, c1:Contract, strike:Double) = When(at, option(sell(c1,strike)))\n  def americanCallOption(at:LocalDate, c1:Contract, strike:Double) = Anytime(at, option(buy(c1,strike)))\n  def americanPutOption(at:LocalDate, c1:Contract, strike:Double) = Anytime(at, option(sell(c1,strike)))\n\n  //custom observable\n  def stock(symbol:String) = Scale(Lookup(symbol),One("USD"))\n  val msft = stock("MSFT")\n\n\n  //Tests\n  val exchangeRates = collection.mutable.Map(\n    "USD" -&gt; LatticeImplementation.binomialPriceTree(365,1,0),\n    "GBP" -&gt; LatticeImplementation.binomialPriceTree(365,1.55,.0467),\n    "EUR" -&gt; LatticeImplementation.binomialPriceTree(365,1.21,.0515)\n    )\n  val lookup = collection.mutable.Map(\n    "MSFT" -&gt; LatticeImplementation.binomialPriceTree(365,45.48,.220),\n    "ORCL" -&gt; LatticeImplementation.binomialPriceTree(365,42.63,.1048),\n    "EBAY" -&gt; LatticeImplementation.binomialPriceTree(365,53.01,.205)\n  )\n  val marketData = Environment(\n    LatticeImplementation.binomialPriceTree(365,.15,.05), //interest rate (use a universal rate for now)\n    exchangeRates, //exchange rates\n    lookup\n  )\n\n  //portfolio test\n  val portfolio = Array(\n    One("USD")\n    ,stock("MSFT")\n    ,buy(stock("MSFT"),45)\n    ,option(buy(stock("MSFT"),45))\n    ,americanCallOption(LocalDate.now().plusDays(5),stock("MSFT"),45)\n  )\n\n  for(contract &lt;- portfolio){\n    println("===========")\n    val propt = LatticeImplementation.contractToPROpt(contract)\n    val rp = LatticeImplementation.binomialValuation(propt, marketData)\n    println("Contract: "+contract)\n    println("Random Process(for optimization): "+propt)\n    println("Present val: "+rp.startVal())\n    println("Random Process: \\n"+rp)\n  }\n\n}\n</code></pre>\n\n<p>The <a href="https://stackoverflow.com/a/4707493/4032515">excellent work of Tomas Petricek</a> in F# is very much worth exploring.</p>\n\n<p>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.</p>\n\n<ul>\n<li>Probabilistic programming: <a href="https://www.cra.com/sites/default/files/pdf/Figaro_Tutorial.pdf" rel="nofollow noreferrer">Figaro</a>, Stan, etc</li>\n<li>Big data analytics: R, Spark, <a href="https://databricks.com/blog/2015/06/09/announcing-sparkr-r-on-spark.html" rel="nofollow noreferrer">SparkR</a></li>\n<li>Scalable "data fabric" ("off heap memory"; across commodity hardware but also <a href="http://amplab-extras.github.io/SparkR-pkg/" rel="nofollow noreferrer">across languages</a>): <a href="https://databricks.com/blog/2015/02/17/introducing-dataframes-in-spark-for-large-scale-data-science.html" rel="nofollow noreferrer">"DataFrames in Spark for Large Scale Data Science"</a> (works with R, Scala/Java and Python)</li>\n<li>Semantic web: "<a href="http://www.umiacs.umd.edu/~jbg/nips_tm_workshop/22.pdf" rel="nofollow noreferrer">Financial Topic Models</a>" and ontologies.</li>\n</ul>\n\n<p>Worth reviewing some languages mentioned here: <a href="http://www.dslfin.org/resources.html" rel="nofollow noreferrer">http://www.dslfin.org/resources.html</a></p>\n'}]
['https://Stackoverflow.com/questions/23448', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2015/']