2 import Control
.Applicative
((<$>))
3 import Data
.List
(intercalate
)
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
)
16 arbitrageability
:: (Ord a
, Floating b
) => ValueSimplex a b
-> b
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
28 , linkValueSquared vs XRP btcBitstamp
30 head <$> (sample
' $ arbitrarilyMultiUpdatedWithLinkOptimumAtNearPrice vs
)
34 flip (>>=*) (replicate 100000 printAndUpdate
) $ flip fromFunction
35 (Set
.fromList
[XRP
, btcBitstamp
, usdBitstamp
, cnyRippleCN
])
39 | fund
== XRP
= 717270000 :: Double
40 | fund
== btcBitstamp
= 0.0183
41 | fund
== usdBitstamp
= 22.22
42 | fund
== cnyRippleCN
= 132.58