如何绘制时间序列

时间:2019-06-08 14:47:31

标签: linqpad

我的理解是Linqpad 5岁以上支持图表。如何在Linqpad中绘制以下时间序列? Charts.combine似乎不起作用。也许我缺少程序集,或者LP中的方法不同?

// Use Math.NET for probability distributions
//#r "MathNet.Numerics.dll"
//open MathNet.Numerics.Distributions

let randomPrice seed drift volatility initial start span count =
  (*[omit: (Implementation omitted)]*) 
  let dist = Normal(0.0, 1.0, RandomSource = Random(seed))
  let dt = (span: TimeSpan).TotalDays / 250.0
  let driftExp = (drift - 0.5 * pown volatility 2) *dt
  let randExp = volatility * (sqrt dt)
  ((start: DateTimeOffset), initial) |> Seq.unfold(fun(dt, price)->
    let price = price * exp(driftExp + randExp * dist.Sample())

    Some((dt, price), (dt + span, price))) |> Seq.take count(*[/ omit] *)

// 12:00 AM today, in current time zone
let today = DateTimeOffset(DateTime.Today)
let stock1 = randomPrice 1 0.1 3.0 20.0 today 
let stock2 = randomPrice 2 0.2 1.5 22.0 today


(*** define-output: stocks ***)
Chart.Combine
  [ stock1 (TimeSpan(0, 1, 0)) 1000 |> Chart.FastLine
    stock2 (TimeSpan(0, 1, 0)) 1000 |> Chart.FastLine ]

0 个答案:

没有答案