現在、次のようなデータがあります。
3-150
2-151
4-152
5-154
7-154
1-155
9-155
6-156
これは単なる人工的な「ティック」データであり、最初のデータはティックの値を表し、2 番目のデータは「午前 0 時からの秒数」を表します。
株式データの場合、このデータを「バー」に分類する必要があります。つまり、特定の時間のすべてのバーをグループ化する必要があります。
例として、4 秒バーがあります。真夜中の 0 ~ 3 秒後のティックは 1 つのバーになり、真夜中の 4 ~ 7 秒後のティックは別のバーになります。
1 つのバー サイズを計算する、次のようなコンジット/シンクがあります。
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe (isJust, fromJust)
import qualified Data.ByteString.Char8 as C
import Control.Applicative ((<$>), (<*>))
import Data.Conduit -- the core library
import qualified Data.Conduit.List as CL -- some list-like functions
import qualified Data.Conduit.Binary as CB -- bytes
import qualified Data.Conduit.Text as CT
data MyData = MyData Int Int
deriving (Show)
binaryToData :: C.ByteString -> Maybe MyData
binaryToData bn = do
let parts = C.split '-' bn
case parts of
(a:b:[]) -> MyData <$> (fst <$> (C.readInt a)) <*> (fst <$> (C.readInt b))
_ -> Nothing
streamGenerator =
CB.sourceFile "sample.txt" =$=
CB.lines =$=
CL.map binaryToData =$=
CL.filter isJust =$=
CL.map fromJust =$=
CL.groupBy (\(MyData _ x) (MyData _ y) -> (x `quot` 4) == (y `quot` 4))
main :: IO ()
main = do
mlines <- runResourceT $ streamGenerator $$ CL.consume
print mlines
ただし、ストリームから同時に複数のバー情報が必要です。たとえば、2 秒バーごとに 4 秒バーが必要です。呼び出されている 2 秒足が 4 秒足の途中にある場合、前の 4 秒足を出力したいと思います。
これが私が意味することです:
標準バー (数値は、バーに含める必要のある真夜中を過ぎた秒単位のティックを意味します):
2 second bar : 0-1, 2-3, 4-5, etc...
4 second bar : 0-3, 4-7, 8-11, etc...
combo: (0-1, null), (2-3, 0-3), (4-5, 0-3), (6-7, 4-7), etc...
したがって、2 秒と 4 秒のバーのグループ化の現在のコンジットの代わりに:
4 second bar : [[MyData 3 150,MyData 2 151],[MyData 4 152,MyData 5 154,MyData 7 154,MyData 1 155,MyData 9 155],[MyData 6 156]]
2 second bar : [[MyData 3 150,MyData 2 151],[MyData 4 152],[MyData 5 154,MyData 7 154,MyData 1 155,MyData 9 155],[MyData 6 156]]
このコンジット ストリームが必要です:
[([MyData 3 150,MyData 2 151], [MyData 3 150,MyData 2 151])
,([MyData 4 152], [MyData 3 150,MyData 2 151])
,([MyData 5 154,MyData 7 154,MyData 1 155,MyData 9 155], [MyData 4 152,MyData 5 154,MyData 7 154,MyData 1 155,MyData 9 155])
,([MyData 6 156],[MyData 4 152,MyData 5 154,MyData 7 154,MyData 1 155,MyData 9 155])]
しかし、私は醜いことをしない限り、それを完全に行うことはできないようです.