Skip to content

Instantly share code, notes, and snippets.

@fbehrens
Created November 11, 2015 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbehrens/6034fc5971ec416c8b45 to your computer and use it in GitHub Desktop.
Save fbehrens/6034fc5971ec416c8b45 to your computer and use it in GitHub Desktop.
Hourly filtering
module wba.csv
open FSharp.Data
open System
type Stocks = CsvProvider<"ES.csv", Schema = "Date(string),Time(string),Open,High,Low,Close,Volume">
let getTime (row:Stocks.Row) =
let iC = Globalization.CultureInfo.InvariantCulture
let s = row.Date + " " + row.Time
DateTime.ParseExact(s, "MM/dd/yyyy HHmm",iC)
let filterStep s fn first =
// only when fn s gives a new value
s
|> Seq.append (seq {yield first})
|> Seq.pairwise
|> Seq.filter (fun (s0,s1)
-> fn s0 <> fn s1 )
|> Seq.map snd
//filterStep ([1;3;11;13;21;23;25]) (fun a -> a /10) -1000 |> List.ofSeq
let filterHourly baseName =
let hours (dt : DateTime) = dt.Ticks / 36000000000L
let file = sprintf @"c:\temp\%s.txt" baseName
let fileT = sprintf @"c:\temp\%sHourly.txt" baseName
let s = Stocks.Load file
let first = Stocks.Row("12/12/1000","0000",0.0m,0.0m,0.0m,0.0m,1)
let seqHourly =
filterStep s.Rows (fun row -> hours (getTime row) ) first
let sT = new Stocks( seqHourly)
sT.Save(fileT)
filterHourly "NQ"
filterHourly "QM"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment