> My idea is to write something like TradeStation [1] or NinjaTrader, only for the Mac.
> It would be quite nifty to use SPJ's financial combinator approach I was experimenting with a Haskell EDSL for financial trading not too long ago. My favorite strategy so far is the parallel parser combinator approach. It allows users to run many parallel trading strategies in a nice single-threaded way that's easy to reason about and straightforward to compose new trading strategies. The idea is that the user composes an 'openPosition' and 'closePosition' trading strategies from a combinator library and gives them to the trading platform. The user's trading strategies are nothing more than a numeric parser combinators. With each incoming quote, the trading platform kicks off the user's 'openPosition' trading strategy. When a strategy succeeds (a successful parse), the trading platform opens a position for the user. Once a position is opened, the platform starts running the user's 'closePosition' strategy. The closePosition parser is run the same way and when it succeeds, the user's position is closed. To implement, I leveraged Twan van Laarhoven's ParseP library (http://twan.home.fmf.nl/parsep/), which at least for my simple experiments, was incredibly complete and stable given its 0.1 version number. Why ParseP and not Parsec or ReadP? Parsec doesn't have an unbiased choice operator and ReadP only works on strings. Implementing context-free trading strategies like limit orders is very easy (limitOrder price = satisfy (>= price)), but context-sensitive strategies, such as "match the longest string of increasing numbers" is quite a bit more painful. Below are some of my experiments (also on hpaste: http://hpaste.org/3756). If anybody could offer more elegant solutions, I'd love to hear because this still feels overly complicated to me. 'testUpThenDown' matches an input stream that increases then decreases. 'testNumericFib' will try to match as much of the Fibonacci sequence as possible. import Text.ParserCombinators.ParseP import qualified Text.ParserCombinators.ParseP.Greedy as Greedy import Control.Applicative import Data.Monoid testUpThenDown = print $ runParser coaster [1, 2, 1] testNumericFib = print $ runParser (fib (Sum 1) (Sum 1)) (map Sum [2, 3, 5, 7, 1]) testAlphaFib = print $ runParser (fib "a" "b") ["ab", "bab", "cad"] fib :: (Eq a, Monoid a) => a -> a -> Parser a p [a] fib n1 n2 = Greedy.option [] (do n3 <- satisfy (== (n1 `mappend` n2)) ns <- fib n2 n3 return (n3:ns)) coaster :: Ord a => Parser a p ([a], [a]) coaster = do seed <- get up <- increasing seed down <- decreasing (last up) return (seed:up, down) increasing seed = trend (<) seed decreasing seed = trend (>) seed trend :: (Monad (Parser a p)) => (a -> a -> Bool) -> a -> Parser a p [a] trend f = many1WithContext (satisfy . f) manyWithContext p = Greedy.option [] . many1WithContext p many1WithContext p seed = do n <- p seed ns <- manyWithContext p n return (n:ns) Thanks, Greg On Nov 7, 2007 5:02 PM, Joel Reymont <[hidden email]> wrote: I need to pick among the usual list of suspects for a commercial _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Greg,
Can you post a couple of examples of what the trading strategies look like? Thanks, Joel On Nov 8, 2007, at 7:32 PM, Greg Fitzgerald wrote: >> The idea is that the user composes an 'openPosition' and >> 'closePosition' > trading strategies from a combinator library and gives them to the > trading > platform. The user's trading strategies are nothing more than a > numeric > parser combinators. -- http://wagerlabs.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Hi Joel,
> Can you post a couple of examples of what the trading strategies look like? Here are some very simple strategies, which are written in the context of just one stock. If these aren't very convincing, could you post some more complex strategies that you'd like to see built using this library? -- open long when price drops to 109.34 myOpenStrategy = limitOrder 109.34 -- close after done increasing or price drops below 105.12 myCloseStrategy openPrice = increasing openPrice <|> limitOrder 105.12 -- succeed when the current price reaches or drops below the given price limitOrder price = satisfy (<= price) Thanks, Greg _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Free forum by Nabble | Edit this page |