&gt; My idea is to write something like TradeStation [1] or NinjaTrader, only for the Mac.<br>&gt; It would be quite nifty to use SPJ&#39;s financial combinator approach<br><br>I was experimenting with a Haskell EDSL for financial trading not too long ago.&nbsp; My favorite strategy so far is the parallel parser combinator approach.&nbsp; It allows users to run many parallel trading strategies in a nice single-threaded way that&#39;s easy to reason about and straightforward to compose new trading strategies. 
<br><br>The idea is that the user composes an &#39;openPosition&#39; and &#39;closePosition&#39; trading strategies from a combinator library and gives them to the trading platform.&nbsp; The user&#39;s trading strategies are nothing more than a numeric parser combinators.&nbsp; With each incoming quote, the trading platform kicks off the user&#39;s &#39;openPosition&#39; trading strategy.&nbsp; When a strategy succeeds (a successful parse), the trading platform opens a position for the user.&nbsp; Once a position is opened, the platform starts running the user&#39;s &#39;closePosition&#39; strategy.&nbsp; The closePosition parser is run the same way and when it succeeds, the user&#39;s position is closed.
<br><br>To implement, I leveraged Twan van Laarhoven&#39;s ParseP library (<a href="http://twan.home.fmf.nl/parsep/">http://twan.home.fmf.nl/parsep/</a>), which at least for my
simple experiments, was incredibly complete and stable given its 0.1
version number.&nbsp;&nbsp; Why ParseP and not Parsec or ReadP?&nbsp; Parsec doesn&#39;t have an unbiased choice operator and ReadP only works on strings.<br><br>Implementing context-free trading strategies like limit orders is very easy (limitOrder price = satisfy (&gt;= price)), but context-sensitive strategies, such as &quot;match the longest string of increasing numbers&quot; is quite a bit more painful.&nbsp; Below are some of my experiments (also on hpaste: 
<a href="http://hpaste.org/3756">http://hpaste.org/3756</a>).&nbsp; If anybody could offer more elegant solutions, I&#39;d love to hear because this still feels overly complicated to me.&nbsp; &#39;testUpThenDown&#39; matches an input stream that increases then decreases.&nbsp; &#39;testNumericFib&#39; will try to match as much of the Fibonacci sequence as possible.
<br><br><br>import Text.ParserCombinators.ParseP<br>import qualified Text.ParserCombinators.ParseP.Greedy as Greedy<br>import Control.Applicative<br>import Data.Monoid<br><br>testUpThenDown = print $ runParser coaster [1, 2, 1]
<br>testNumericFib = print $ runParser (fib (Sum 1) (Sum 1)) (map Sum [2, 3, 5, 7, 1])<br>testAlphaFib = print $ runParser (fib &quot;a&quot; &quot;b&quot;) [&quot;ab&quot;, &quot;bab&quot;, &quot;cad&quot;]<br><br>fib :: (Eq a, Monoid a) =&gt; a -&gt; a -&gt; Parser a p [a]
<br>fib n1 n2 = Greedy.option [] (do<br>&nbsp;&nbsp; n3 &lt;- satisfy (== (n1 `mappend` n2)) <br>&nbsp;&nbsp; ns &lt;- fib n2 n3<br>&nbsp;&nbsp; return (n3:ns))<br><br>coaster :: Ord a =&gt; Parser a p ([a], [a])<br>coaster = do<br>&nbsp;&nbsp; seed &lt;- get<br>
&nbsp;&nbsp; up&nbsp;&nbsp; &lt;- increasing seed<br>&nbsp;&nbsp; down &lt;- decreasing (last up)<br>&nbsp;&nbsp; return (seed:up, down)<br><br>increasing seed = trend (&lt;) seed<br>decreasing seed = trend (&gt;) seed<br><br>trend :: (Monad (Parser a p)) =&gt; (a -&gt; a -&gt; Bool) -&gt; a -&gt; Parser a p [a]
<br>trend f = many1WithContext (satisfy . f)<br><br>manyWithContext p = Greedy.option [] . many1WithContext p<br><br>many1WithContext p seed = do<br>&nbsp;&nbsp; n&nbsp; &lt;- p seed<br>&nbsp;&nbsp; ns &lt;- manyWithContext p n<br>&nbsp;&nbsp; return (n:ns)
<br><br><br>Thanks,<br>Greg<br><br><br><br><br><div class="gmail_quote">On Nov 7, 2007 5:02 PM, Joel Reymont &lt;<a href="mailto:joelr1@gmail.com">joelr1@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I need to pick among the usual list of suspects for a commercial<br>product that I&#39;m writing. The suspects are OCaml, Haskell and Lisp and<br>the product is a trading studio. My idea is to write something like<br>TradeStation [1] or NinjaTrader, only for the Mac.
<br><br>It would be quite nifty to use SPJ&#39;s financial combinator approach<br>and, for example, embed Yi (Haskell editor).<br><br>One of the key features of the product would be the ability to model<br>your trading logic using a trading DSL. I&#39;m thinking that this DSL
<br>could well be Haskell but I&#39;m concerned about stepping into a minefield.<br><br>I will need to embed GHC into the app, for example, and I understand<br>that the GHC API does not offer unloading of code at the moment. I
<br>would prefer not to bundle GHC separately so I don&#39;t think the hs-<br>plugins approach would work for me. Maybe I&#39;m mistaken.<br><br>Most of all, I&#39;m concerned that my users will need to face the error<br>
reports from GHC and could get tripped by laziness, i.e. write<br>something that would make the app run out of memory. Off the top of my<br>head I can&#39;t figure out a way to limit what my users can do without<br>analyzing the Haskell AST within the GHC API and complaining if
<br>necessary.<br><br>Can someone with experience in offering a Haskell DSL to their users<br>please comment?<br><br>Notice that I&#39;m not even mentioning being concerned with the<br>unpredictable effects of laziness. There&#39;s probably a reason why Jane
<br>St Capital is using OCaml instead of Haskell. I&#39;m not going to play in<br>that league but my knee-jerk reaction is to use OCaml or Lisp and<br>avoid laziness altogether. I just can&#39;t see how laziness can help in
<br>processing real-time price data.<br><br> &nbsp; &nbsp; &nbsp; &nbsp;Thanks, Joel<br><br>[1] <a href="http://www.tradestation.com/default_2.shtm" target="_blank">http://www.tradestation.com/default_2.shtm</a><br>[2] <a href="http://www.ninjatrader.com/webnew/index.htm" target="_blank">
http://www.ninjatrader.com/webnew/index.htm</a><br><br>--<br><a href="http://wagerlabs.com" target="_blank">http://wagerlabs.com</a><br><br><br><br><br><br>_______________________________________________<br>Haskell-Cafe mailing list
<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></blockquote>
</div><br>