No longer require largeword < 1.2 to compile on GHC 7.4.1
[rootstock.git] / longrun-test.hs
blob177f98dc37d853c2f3161ccb193ac53dc085073c
1 module Main where
2 import Control.Applicative ((<$>))
3 import Data.List (intercalate)
4 import Data.Set (Set)
5 import qualified Data.Set as Set
6 import Fund (Fund(XRP), btcBitstamp, usdBitstamp, cnyRippleCN)
7 import Numeric.Matrix (MatrixElement)
8 import System.Exit (exitSuccess)
9 import Test.QuickCheck (sample')
10 import Test.ValueSimplex (arbitrarilyMultiUpdatedWithLinkOptimumAtNearPrice)
11 import Util.Foldable (sumWith)
12 import Util.Monad ((>>=*))
13 import Util.Set (distinctTriplesOneWay)
14 import ValueSimplex
16 arbitrageability :: (Ord a, Floating b) => ValueSimplex a b -> b
17 arbitrageability vs =
18 flip sumWith (distinctTriplesOneWay $ nodes vs) $ \(x, y, z) ->
19 let s = vsLookup vs in
20 abs $ log $ s x y * s y z * s z x / (s z y * s y x * s x z)
22 printAndUpdate :: (Ord b, Floating b, MatrixElement b, Show b)
23 => ValueSimplex Fund b -> IO (ValueSimplex Fund b)
24 printAndUpdate vs = do
25 putStrLn $ intercalate "," $ map show
26 [ arbitrageability vs
27 , nodeValue vs XRP
28 , linkValueSquared vs XRP btcBitstamp
30 head <$> (sample' $ arbitrarilyMultiUpdatedWithLinkOptimumAtNearPrice vs)
32 main :: IO ()
33 main = do
34 flip (>>=*) (replicate 100000 printAndUpdate) $ flip fromFunction
35 (Set.fromList [XRP, btcBitstamp, usdBitstamp, cnyRippleCN])
36 $ \left _ ->
37 let
38 total fund
39 | fund == XRP = 717270000 :: Double
40 | fund == btcBitstamp = 0.0183
41 | fund == usdBitstamp = 22.22
42 | fund == cnyRippleCN = 132.58
43 | otherwise = 0
45 total left / 3
46 exitSuccess