{-# LANGUAGE OverloadedStrings #-} module Test.RoboCom.Utils ( unitTests ) where import Test.Tasty import Test.Tasty.HUnit import ATrade.Types import qualified Data.Text as T import Data.Time.Calendar import Data.Time.Clock import ATrade.RoboCom.Utils unitTests = testGroup "RoboCom.Indicators" [ testRescaleToDaily, testRescaleToDaily2 ] testRescaleToDaily = testCase "Rescale to daily" $ assertEqual "Incorrect rescale" dailyBars $ rescaleToDaily min15Bars where dailyBars = reverse [ yesterdayBar, todayBar ] min15Bars = reverse [ Bar { barSecurity = "foo", barTimestamp = UTCTime (fromGregorian 2017 2 28) (18 * 3600), barOpen = 10, barHigh = 12, barLow = 9, barClose = 11, barVolume = 100 }, Bar { barSecurity = "foo", barTimestamp = UTCTime (fromGregorian 2017 2 28) (18 * 3600 + 15 * 60), barOpen = 10.95, barHigh = 12, barLow = 9, barClose = 11.3, barVolume = 200 }, Bar { barSecurity = "foo", barTimestamp = UTCTime (fromGregorian 2017 3 1) (10 * 3600 + 0.1), barOpen = 15, barHigh = 15, barLow = 14, barClose = 14.2, barVolume = 40 } ] yesterdayBar = Bar { barSecurity = "foo", barTimestamp = UTCTime (fromGregorian 2017 2 28) (18 * 3600 + 15 * 60), barOpen = 10, barHigh = 12, barLow = 9, barClose = 11.3, barVolume = 300 } todayBar = Bar { barSecurity = "foo", barTimestamp = UTCTime (fromGregorian 2017 3 1) (10 * 3600 + 0.1), barOpen = 15, barHigh = 15, barLow = 14, barClose = 14.2, barVolume = 40 } testRescaleToDaily2 = testCase "Rescale to daily 2" $ assertEqual "Incorrect rescale" dailyBars $ rescaleToDaily min30Bars where dailyBars = reverse [ ibar 1 17 3.6065000 3.6740000 3.5670000 3.6740000 47398000, ibar 2 17 3.6760000 3.6980000 3.6350000 3.6980000 32643000, ibar 3 17 3.7000000 3.7090000 3.6545000 3.6800000 35727000, ibar 4 17 3.6800000 3.6865000 3.5950000 3.6855000 117477000 ] min30Bars = reverse [ ibar 1 0 3.6065000 3.6065000 3.5670000 3.5985000 2058000, ibar 1 1 3.5995000 3.6275000 3.5990000 3.6200000 2208000, ibar 1 2 3.6200000 3.6300000 3.6130000 3.6300000 3132000, ibar 1 3 3.6290000 3.6300000 3.6215000 3.6285000 1296000, ibar 1 4 3.6280000 3.6365000 3.6205000 3.6365000 1956000, ibar 1 5 3.6350000 3.6500000 3.6350000 3.6470000 4126000, ibar 1 6 3.6460000 3.6560000 3.6440000 3.6555000 3656000, ibar 1 7 3.6555000 3.6570000 3.6485000 3.6560000 2076000, ibar 1 8 3.6565000 3.6590000 3.6530000 3.6590000 1891000, ibar 1 9 3.6585000 3.6695000 3.6580000 3.6695000 1951000, ibar 1 10 3.6680000 3.6700000 3.6620000 3.6690000 2220000, ibar 1 11 3.6690000 3.6695000 3.6470000 3.6485000 5865000, ibar 1 12 3.6485000 3.6600000 3.6485000 3.6585000 2692000, ibar 1 13 3.6585000 3.6670000 3.6565000 3.6650000 1348000, ibar 1 14 3.6645000 3.6695000 3.6625000 3.6675000 1259000, ibar 1 15 3.6675000 3.6695000 3.6490000 3.6520000 2554000, ibar 1 16 3.6525000 3.6660000 3.6375000 3.6655000 4529000, ibar 1 17 3.6655000 3.6740000 3.6595000 3.6740000 2581000, ibar 2 0 3.6760000 3.6790000 3.6450000 3.6455000 3248000, ibar 2 1 3.6450000 3.6510000 3.6400000 3.6510000 1357000, ibar 2 2 3.6505000 3.6530000 3.6400000 3.6400000 1458000, ibar 2 3 3.6410000 3.6435000 3.6350000 3.6365000 1667000, ibar 2 4 3.6365000 3.6425000 3.6350000 3.6405000 1889000, ibar 2 5 3.6395000 3.6440000 3.6390000 3.6410000 579000, ibar 2 6 3.6425000 3.6445000 3.6400000 3.6420000 414000, ibar 2 7 3.6420000 3.6420000 3.6380000 3.6385000 301000, ibar 2 8 3.6385000 3.6430000 3.6360000 3.6415000 402000, ibar 2 9 3.6425000 3.6500000 3.6405000 3.6500000 1855000, ibar 2 10 3.6500000 3.6500000 3.6390000 3.6440000 1286000, ibar 2 11 3.6435000 3.6465000 3.6400000 3.6410000 1260000, ibar 2 12 3.6410000 3.6840000 3.6410000 3.6795000 5554000, ibar 2 13 3.6800000 3.6825000 3.6700000 3.6790000 1980000, ibar 2 14 3.6790000 3.6825000 3.6720000 3.6795000 1782000, ibar 2 15 3.6775000 3.6795000 3.6720000 3.6720000 693000, ibar 2 16 3.6720000 3.6825000 3.6710000 3.6810000 2432000, ibar 2 17 3.6810000 3.6980000 3.6800000 3.6980000 4486000, ibar 3 0 3.7000000 3.7050000 3.6810000 3.6845000 2517000, ibar 3 1 3.6860000 3.7090000 3.6840000 3.7025000 3201000, ibar 3 2 3.7035000 3.7040000 3.6945000 3.6975000 947000, ibar 3 3 3.6975000 3.7000000 3.6870000 3.6910000 1272000, ibar 3 4 3.6885000 3.6965000 3.6805000 3.6920000 2710000, ibar 3 5 3.6885000 3.6985000 3.6885000 3.6935000 932000, ibar 3 6 3.6920000 3.6930000 3.6630000 3.6690000 4562000, ibar 3 7 3.6690000 3.6740000 3.6640000 3.6670000 663000, ibar 3 8 3.6670000 3.6715000 3.6600000 3.6690000 2189000, ibar 3 9 3.6700000 3.6745000 3.6605000 3.6725000 880000, ibar 3 10 3.6725000 3.6775000 3.6695000 3.6740000 1544000, ibar 3 11 3.6755000 3.6790000 3.6640000 3.6660000 1264000, ibar 3 12 3.6655000 3.6710000 3.6655000 3.6680000 484000, ibar 3 13 3.6680000 3.6780000 3.6680000 3.6740000 1178000, ibar 3 14 3.6735000 3.6800000 3.6735000 3.6770000 919000, ibar 3 15 3.6785000 3.6830000 3.6600000 3.6655000 3961000, ibar 3 16 3.6655000 3.6805000 3.6545000 3.6795000 4080000, ibar 3 17 3.6795000 3.6840000 3.6685000 3.6800000 2424000, ibar 4 0 3.6800000 3.6865000 3.6610000 3.6665000 1406000, ibar 4 1 3.6635000 3.6770000 3.6550000 3.6660000 1184000, ibar 4 2 3.6650000 3.6800000 3.6600000 3.6685000 3210000, ibar 4 3 3.6685000 3.6710000 3.6610000 3.6610000 1525000, ibar 4 4 3.6610000 3.6720000 3.6600000 3.6650000 2849000, ibar 4 5 3.6615000 3.6650000 3.6535000 3.6540000 2027000, ibar 4 6 3.6535000 3.6670000 3.6420000 3.6500000 3892000, ibar 4 7 3.6465000 3.6600000 3.6350000 3.6520000 4267000, ibar 4 8 3.6515000 3.6720000 3.6500000 3.6535000 5878000, ibar 4 9 3.6535000 3.6640000 3.6435000 3.6435000 3047000, ibar 4 10 3.6435000 3.6490000 3.6395000 3.6395000 2217000, ibar 4 11 3.6395000 3.6395000 3.6105000 3.6255000 4354000, ibar 4 12 3.6260000 3.6400000 3.5950000 3.6135000 6811000, ibar 4 13 3.6145000 3.6600000 3.6140000 3.6550000 5101000, ibar 4 14 3.6550000 3.6600000 3.6380000 3.6570000 2624000, ibar 4 15 3.6570000 3.6595000 3.6305000 3.6400000 4906000, ibar 4 16 3.6400000 3.6435000 3.6195000 3.6400000 8638000, ibar 4 17 3.6435000 3.6855000 3.6275000 3.6855000 53541000 ] ibar d ibn o h l c v = Bar { barSecurity = "", barTimestamp = UTCTime (fromGregorian 2017 2 d) (10 * 3600 + ibn * 30 * 60), barOpen = o, barHigh = h, barLow = l, barClose = c, barVolume = v}