财务中的DSL（领域特定语言）DSLs (Domain Specific Languages) in Finance

5 个回复5

===============>>#1 票数：13

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

===============>>#2 票数：8 已采纳

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

===============>>#4 票数：0

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

===============>>#5 票数：0

``````  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＃的出色工作非常值得探索。

3回复

9回复

5回复

2回复

1回复

2回复

4回复

3回复

6回复

6回复