Bitcoin Forum

Economy => Trading Discussion => Topic started by: daybyter on December 15, 2012, 01:59:11 PM



Title: Formal definition of a trading language
Post by: daybyter on December 15, 2012, 01:59:11 PM
Hi!

I thought about a way to describe trading strategies in a well-defined language. Still working on the concept, but here is a simple example, what it could look like:

Code:
rule "Compare btc-e sma"
     when
( BTCe.btc<=>usd.ticker.buy * 110% > BTCe.btc<=>usd.sma(6h) ) && ( BTCe.btc.balance() > 1.0 )
     then
BTCe.btc<=>usd.sell( BTCe.btc.balance() - 1.0)
end

The overall structure is taken from drools (that's what I want to translate it to).

Most of these expressions follow the scheme

<tradesite>.<currency pair>.<method>
or
<tradesite>.<currency>.<method>

which is quite easy to parse because the '<=>' indicates a currency pair in my app. laSeek already contributed the first construct, namely the '%' suffix. Times are always handled as microseconds here, which gives you sometimes numbers, that are not very convenient to read. So I wanted to use suffixes, like 's', 'm' and 'h' (maybe even 'd' for days) to make the numbers more readable. So 1s just translates to 1000000 here.

This structure would be simple enough to translate it automatically, which is important to me. My idea so far was to write an Antlr grammar to parse the language, because it has a non.restrictive license and everyone could add his own productions.

Is there any interested in such a definition? People willing to collaborate to create one?

Ciao,
Andreas


Title: Re: Formal definition of a trading language
Post by: kakobrekla on December 15, 2012, 02:03:30 PM
Perhaps take a look at http://book.mql4.com/ / http://www.mql5.com/en/docs


Title: Re: Formal definition of a trading language
Post by: daybyter on December 15, 2012, 02:16:04 PM
Well, I wasn't thinking about a full-blown OO language. Just simple if ... then .... rules. So even non-coders can write their traders.


Title: Re: Formal definition of a trading language
Post by: laSeek on December 15, 2012, 04:21:39 PM

The first step is clearly defining what you're trying to achieve & why - who the target audience is for the proposal and who the userbase is for the rules (they're not the usually the same people).

This will help drive the DSL and start providing some structure to the design of the DSL.

For instance - if you're looking at the core of the DSL and won't be allowing the reference of one rule from another, or your outlining a rule without worrying about rules being portable between systems - then rule-names aren't needed.

If you're designing the DSL for coder then the type of syntax you're outlining would be familiar to them - but this type of syntax isn't intuitive to Joe off the street.

So a few questions to help get your started:
Who is this outline targeted at - implementers? Site Owners, Currency exchange or Stock trading boards?
Who will be writing the rule syntax? People currently day trading with some kind of bot already? People without bots? Techies or home-makers?
Why a common language at all? Do you think the current service layer is mature enough to warrant a common standard?

Look at the more recent HTML standards - one reason they exist (one of many) is that they help ensure there's a common definition for implementers so that there's common behaviour across different browsers for content creators.

I'm playing devils advocate with some of them - but it helps ensure people reading and those working on it have a common frame of reference.


Title: Re: Formal definition of a trading language
Post by: daybyter on December 15, 2012, 04:29:17 PM
I thought about users of a trading site, allowing people to upload such scripts for trading.


Title: Re: Formal definition of a trading language
Post by: Kettenmonster on December 15, 2012, 05:03:37 PM
So you want to provide a site with a configurable/programmable trading bot?  ???

Don't forget to exploit the strategy hidden in those uploaded scripts. Best business model ever! ;D


Title: Re: Formal definition of a trading language
Post by: daybyter on December 15, 2012, 06:36:58 PM
I'm too honest to do that..  ::)


Title: Re: Formal definition of a trading language
Post by: Stephen Gornick on December 16, 2012, 12:49:00 PM
Is there any interested in such a definition? People willing to collaborate to create one?

Related:

Towards a unified exchange protocol
 - http://polimedia.us/trilema/2012/towards-a-unified-exchange-protocol/


Title: Re: Formal definition of a trading language
Post by: bluemeanie1 on November 15, 2013, 09:48:13 PM
also an interesting web search find:  "Describing, manipulating and pricing financial contracts: The MLFi language"

http://www.lexifi.com/files/resources/Cambridge_lexifi.pdf