-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSeries.fsx
39 lines (30 loc) · 1.08 KB
/
Series.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#load "packages/FsLab/Themes/DefaultWhite.fsx"
#load "packages/FsLab/FsLab.fsx"
#r "MathNet.Numerics.dll"
open System
open System.IO
open Deedle
open FSharp.Data
open XPlot.GoogleCharts
open XPlot.GoogleCharts.Deedle
open MathNet.Numerics
let DAYS = 30
let dates = [for x in 0..DAYS -> System.DateTime(2017,1,1).AddDays(float x)]
let randomWalk =
Random.Random.doubleSeq()
|> Seq.scan (+) 100.0
|> Seq.take DAYS
let daily = Seq.zip dates randomWalk |> series
let firstFriday = System.DateTime(2017,1,6)
let nextDay dt =
firstFriday.AddDays(1.0)
let firstSaturday = nextDay firstFriday
(*
Sets the cut-off to start a new interval every Saturday.
Since we use Lookup.Smaller this means that the weekly observation is up to and including the Fridays.
The last value of the previous week is registered on the cut-off day (Saturday)
*)
let weeklyUpToAndIncludingFriday =
daily |> Series.lookupTimeAt firstSaturday (TimeSpan.FromDays(7.0)) Direction.Backward Lookup.Smaller
// Show the data side-by-side
frame ["Daily" => daily; "Weekly" => weeklyUpToAndIncludingFriday]