Serving the Quantitative Finance Community

 
User avatar
rockinsquat
Topic Author
Posts: 1
Joined: March 20th, 2009, 6:51 pm

Payoff Languages

August 1st, 2011, 11:24 am

Hi all,Imagine that I have a let's say c++ monte-carlo engine which eats "pay-offs". (You could easily imagine what it means.)Now, many, if not most, of the product we're trying to price every are defined by the following setup :1) a tenor structures T_1 < ... < T_N2) cashflows C_i falling at time i, for i going from 1 to N3) C_{i+1} may be defined through C_i and or trigger, barrier etc conditions4) American/Bermudean rights to exercice, which kills the life of the product.Of course there's always an exception of a product which will not belong to the set E of products that the previous requierements defines, but that's not the question here. Ok, so now let's take a product from the set E, for instance a target redemption note, or a cliquet. Of course, I could write a class for the product that I'll give to my Monte-Carlo engine. I could do this for every product of the set E. But that would be, and that is very boring.So the idea is the following : first isolate all the "basic" algebraic operations that are needed to construct a product from E, for instance +,*,-,/,max,min,sum of list, reals numbers etc... Then try to build a "payoff langage" L with these operations that would allow you to code the product E, then compile this code through a compiler that will translate you code in language L in a C++ code, and that will give you (for instance) a class for your product, and then pass this to you monte carlo engine.That's what are using traders in many banks to code their payoffs in excel spread-sheets, and then they're pricing them with various pricing engines.My question is the following : has anyone of you ever heard about this, or seen examples of languages L, of compilers etc ? Actually I'm trying to build all this stuff alone, but without anything it's really challenging, which is cool, but quite hard. So i've first decided to skip the step of constructing the compiler myself.I'm using ANTLRworks for defining grammars of my "payoff language"-to be, ANTLR with Miscrosoft Visual Studio (in C# in fact, cause doing it in C++ is quite intricate) for generating a parser and a lexer for my language, and that's.If someone has a trivial example of doing this, I'm quite open to see it, cause I don't know how to design this optimally.Thank you all !
Last edited by rockinsquat on July 31st, 2011, 10:00 pm, edited 1 time in total.
 
User avatar
spv205
Posts: 1
Joined: July 14th, 2002, 3:00 am

Payoff Languages

August 1st, 2011, 8:53 pm

Haskell?haskell for contracts
 
User avatar
quantmeh
Posts: 0
Joined: April 6th, 2007, 1:39 pm

Payoff Languages

August 1st, 2011, 9:02 pm

everyone think of this, and nobody implements it there was an interesting idea to put regulatory requirement of releasing cash flow logic in Python from SEC.we created our own language for a similar purpose, and use it internally. DSL is a fashionable topic in s/w development these days
 
User avatar
rockinsquat
Topic Author
Posts: 1
Joined: March 20th, 2009, 6:51 pm

Payoff Languages

August 1st, 2011, 9:44 pm

It was a bad idea asking for it, cause with such a question on a forum, you always finish yourself with having to learn N langages L_1,...,L_N, where you will compile L_{i-1} code with L_i, and where L_0 = c, c or c# and where the final L_0 code will be what you're looking for... So it's better to stay to c for a parser/lexer. ;-) I don't want a new langage for doin it ; a parser/lexer generator outputing c# code (like ANTLR) helps, but at the end, the only thing to do it is doing it myself. Thanks anyway, folks.QuoteOriginally posted by: rockinsquatHi all,Imagine that I have a let's say c++ monte-carlo engine which eats "pay-offs". (You could easily imagine what it means.)Now, many, if not most, of the product we're trying to price every are defined by the following setup :1) a tenor structures T_1 < ... < T_N2) cashflows C_i falling at time i, for i going from 1 to N3) C_{i+1} may be defined through C_i and or trigger, barrier etc conditions4) American/Bermudean rights to exercice, which kills the life of the product.Of course there's always an exception of a product which will not belong to the set E of products that the previous requierements defines, but that's not the question here. Ok, so now let's take a product from the set E, for instance a target redemption note, or a cliquet. Of course, I could write a class for the product that I'll give to my Monte-Carlo engine. I could do this for every product of the set E. But that would be, and that is very boring.So the idea is the following : first isolate all the "basic" algebraic operations that are needed to construct a product from E, for instance +,*,-,/,max,min,sum of list, reals numbers etc... Then try to build a "payoff langage" L with these operations that would allow you to code the product E, then compile this code through a compiler that will translate you code in language L in a C++ code, and that will give you (for instance) a class for your product, and then pass this to you monte carlo engine.That's what are using traders in many banks to code their payoffs in excel spread-sheets, and then they're pricing them with various pricing engines.My question is the following : has anyone of you ever heard about this, or seen examples of languages L, of compilers etc ? Actually I'm trying to build all this stuff alone, but without anything it's really challenging, which is cool, but quite hard. So i've first decided to skip the step of constructing the compiler myself.I'm using ANTLRworks for defining grammars of my "payoff language"-to be, ANTLR with Miscrosoft Visual Studio (in C# in fact, cause doing it in C++ is quite intricate) for generating a parser and a lexer for my language, and that's.If someone has a trivial example of doing this, I'm quite open to see it, cause I don't know how to design this optimally.Thank you all !
Last edited by rockinsquat on July 31st, 2011, 10:00 pm, edited 1 time in total.
 
User avatar
Stutch
Posts: 0
Joined: October 30th, 2006, 10:16 am

Payoff Languages

August 2nd, 2011, 1:05 pm

Try lex and yacc, they generate C. Or used to, it's 15 years since I worked on a compiler.
 
User avatar
Polter
Posts: 1
Joined: April 29th, 2008, 4:55 pm

Payoff Languages

August 2nd, 2011, 6:07 pm

rockinsquat, the closest thing to what you're attempting to do are "public interfaces" ("public" as in for use by non-quants within a organization) described by a DSL/mark-up language used to generate C++ code, described in Chapter 3 of "Derivatives Algorithms: Bones" by Tom Hyer:http://books.google.com/books?id=5KyG9x ... ortunately, it's rather terse (the author is quite honest about it, the word "Bones" in the title is there for a reason), but it might still be useful to you as an initial list of design decisions / problems / solutions you might encounter in your project (e.g., how much to expose to non-quants and how to go about it).
 
User avatar
rockinsquat
Topic Author
Posts: 1
Joined: March 20th, 2009, 6:51 pm

Payoff Languages

August 3rd, 2011, 5:26 am

I've already used yacc for iPhone c code compiling, but now i want to parse myself, but thx anyway !QuoteOriginally posted by: StutchTry lex and yacc, they generate C. Or used to, it's 15 years since I worked on a compiler.
Last edited by rockinsquat on August 2nd, 2011, 10:00 pm, edited 1 time in total.
 
User avatar
rockinsquat
Topic Author
Posts: 1
Joined: March 20th, 2009, 6:51 pm

Payoff Languages

August 3rd, 2011, 5:29 am

Thx a lot, it's indeed a simple version of what I'm looking for, so that it's perfect for starting from !QuoteOriginally posted by: Polterrockinsquat, the closest thing to what you're attempting to do are "public interfaces" ("public" as in for use by non-quants within a organization) described by a DSL/mark-up language used to generate C++ code, described in Chapter 3 of "Derivatives Algorithms: Bones" by Tom Hyer:http://books.google.com/books?id=5KyG9x ... ortunately, it's rather terse (the author is quite honest about it, the word "Bones" in the title is there for a reason), but it might still be useful to you as an initial list of design decisions / problems / solutions you might encounter in your project (e.g., how much to expose to non-quants and how to go about it).
Last edited by rockinsquat on August 2nd, 2011, 10:00 pm, edited 1 time in total.
 
User avatar
rockinsquat
Topic Author
Posts: 1
Joined: March 20th, 2009, 6:51 pm

Payoff Languages

August 3rd, 2011, 8:08 am

Re, I was a bit optimistic in my first quote of your message after having browsed quickly through the book. In fact as you say it merely talks about design decisions / problems / solutions one might encounter in that king of project, but totally escapes from the technical part of the project... So, I'm force to the same conclusion as before : the best solution is to do it myself... QuoteOriginally posted by: Polterrockinsquat, the closest thing to what you're attempting to do are "public interfaces" ("public" as in for use by non-quants within a organization) described by a DSL/mark-up language used to generate C++ code, described in Chapter 3 of "Derivatives Algorithms: Bones" by Tom Hyer:http://books.google.com/books?id=5KyG9x ... ortunately, it's rather terse (the author is quite honest about it, the word "Bones" in the title is there for a reason), but it might still be useful to you as an initial list of design decisions / problems / solutions you might encounter in your project (e.g., how much to expose to non-quants and how to go about it).
Last edited by rockinsquat on August 2nd, 2011, 10:00 pm, edited 1 time in total.
 
User avatar
kimosabe
Posts: 4
Joined: November 25th, 2003, 12:24 pm

Payoff Languages

August 3rd, 2011, 9:11 pm

QuoteOriginally posted by: spv205Haskell?haskell for contractsThis guys seems to never heard of LexiFi. They are a little further along than he is.
 
User avatar
nwhitehe
Posts: 0
Joined: March 3rd, 2006, 6:57 am

Payoff Languages

August 3rd, 2011, 10:30 pm

They do mention LexiFi in the paper by Frankau et al referenced in the talk.QuoteLater work (Peyton Jones et al., 2000; Peyton Jones & Eber, 2003) used Haskellto allow payouts to be defined in an abstract functional language and to providemultiple interpretations of the products. This work was apparently commerciallyadopted and marketed (MLFi, 2004; LexiFi, n.d.). We considered that product asa cots alternative to fpf, but in the end the risks in integrating the product andloss of control in development meant that we instead opted for an in-house productdesigned from the start to integrate with existing systems.I would have liked to see more comparisons with the techniques in the SPJ papers.
 
User avatar
kimosabe
Posts: 4
Joined: November 25th, 2003, 12:24 pm

Payoff Languages

August 3rd, 2011, 11:04 pm

QuoteOriginally posted by: nwhiteheThey do mention LexiFi in the paper by Frankau et al referenced in the talk.QuoteLater work (Peyton Jones et al., 2000; Peyton Jones & Eber, 2003) used Haskellto allow payouts to be defined in an abstract functional language and to providemultiple interpretations of the products. This work was apparently commerciallyadopted and marketed (MLFi, 2004; LexiFi, n.d.). We considered that product asa cots alternative to fpf, but in the end the risks in integrating the product andloss of control in development meant that we instead opted for an in-house productdesigned from the start to integrate with existing systems.I would have liked to see more comparisons with the techniques in the SPJ papers.M3 t00.I would also like to see a post mortem on how much they actually spent developing the system in-house vs. the cost of LexiFi. My guess is they pre-decided they wanted to write some super cool Haskell code. Give a kid a hammer and he'll find something to fix.We no longer have Big Banks writing their own language: GoldC (guess where), Cmore (BT), A+ (Morgan Stanley), K (Credit Suisse). I thought the days of IT guys being able to pull the wool over the business lines eyes with the NIH line 'we can do it better than the market' were over. Several CIO's at large institutions have been fired recently because they could not keep IT costs in line with what the business was able to allocate. It's about time.
 
User avatar
rockinsquat
Topic Author
Posts: 1
Joined: March 20th, 2009, 6:51 pm

Payoff Languages

August 4th, 2011, 6:46 am

Indeed, I guess they never had ! :-) But Lexifi is enormously far-fetched for my purposes : for instance, after having checked all issues and so on, and after having wrote the grammar of my (very small and taylorized) payoff language, I've decide to write it in VBA for Excel, and to parse it and throw the result to my pricing engines at runtime. It's a "private" solution, and I think that it's the best for my purposes, which are esentially quickening the writing of the descriptions of the products I'm pricing now, and in the future. After, big banks not writing anymore their languages, it's not my problem QuoteOriginally posted by: kimosabeQuoteOriginally posted by: spv205Haskell?haskell for contractsThis guys seems to never heard of LexiFi. They are a little further along than he is.
Last edited by rockinsquat on August 3rd, 2011, 10:00 pm, edited 1 time in total.
 
User avatar
kimosabe
Posts: 4
Joined: November 25th, 2003, 12:24 pm

Payoff Languages

August 4th, 2011, 11:29 am

QuoteOriginally posted by: rockinsquatIndeed, I guess they never had ! :-) But Lexifi is enormously far-fetched for my purposes : for instance, after having checked all issues and so on, and after having wrote the grammar of my (very small and taylorized) payoff language, I've decide to write it in VBA for Excel, and to parse it and throw the result to my pricing engines at runtime. ...LexiFi would be overkill for you. Have a look at this library. It is not a cash flow language, but it makes writing C++ add-ins as easy as VBA. My technique is to keep pushing the functionality developed in Excel down into C++ code. You are doing it right when every function just takes arguments from Excel, calls your C++ function, and returns the results to Excel. If you intend for your code to be used with other systems, C++ is a tiny bit more portable than VBA.One rookie mistake people make when writing cash flow languages is not incorporating the inherint asymmetry of a contract. There is a buyer and there is a seller. They have very different perspectives even though it is the same contract.Post some example code of what you are doing rockinsquat. There are too many people that just talk about code instead of actually writing code.
 
User avatar
spv205
Posts: 1
Joined: July 14th, 2002, 3:00 am

Payoff Languages

August 4th, 2011, 7:39 pm

If you are going to use VBA then you ought first to check how fast it is to just use VBA "callbacks" (NAG has a good write up and examples - showing how they call their optimisation routine with VBA target function) VBA callbacks AddressOf function