-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.fsharp
80 lines (70 loc) · 3.75 KB
/
input.fsharp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#light "off"
nalysisEngine() = begin
interface IAnalysisEngine with
member x.DoSequentialAnalysis2() =
let rec engine =
{ new AnalysisProcess() with
member x.Start() = Task.Factory.StartNew(analysis) |> ignore
member x.TryCancel() = () end }
and analysis() =
let nyseData = loadNyseData() in
engine.TriggerLoadNyseData(nyseData);
let nasdaqData = loadNasdaqData() in
engine.TriggerLoadNasdaqData(nasdaqData);
let mergedMarketData = mergeMarketData [ nyseData; nasdaqData ] in
engine.TriggerMergeMarketData(mergedMarketData);
let normalizedMarketData = normalizeData mergedMarketData in
engine.TriggerNormalizeMarketData(normalizedMarketData);
let analyzedStockData = analyzeData normalizedMarketData in
engine.TriggerAnalyzeMarketData(analyzedStockData);
let fedHistoricalData = loadFedHistoricalData() in
engine.TriggerLoadFedHistoricalData(fedHistoricalData);
let normalizedHistoricalData = normalizeData fedHistoricalData in
engine.TriggerNormalizeHistoricalData(normalizedHistoricalData);
let analyzedHistoricalData = analyzeData normalizedHistoricalData in
engine.TriggerAnalyzeHistoricalData(analyzedHistoricalData);
let modeledMarketData = runModel analyzedStockData in
engine.TriggerModelMarketData(modeledMarketData);
let modeledHistoricalData = runModel analyzedHistoricalData in
engine.TriggerModelHistoricalData(modeledHistoricalData);
let recommendation = compareModels [ modeledMarketData; modeledHistoricalData ] in
engine.TriggerCompareModels(Some recommendation) in
engine
member x.DoAsyncAnalysis() =
let cts = new CancellationTokenSource() in
let rec engine =
{ new AnalysisProcess() with
member x.Start() =
Async.Start(compare, cancellationToken = cts.Token)
member x.TryCancel() = cts.Cancel() end }
and marketModel = async {
let! nyse =
asyncLoadNyseData()
|> Async.WithResult engine.TriggerLoadNyseData |> Async.StartChild in
let! nasdaq =
asyncLoadNasdaqData()
|> Async.WithResult engine.TriggerLoadNasdaqData |> Async.StartChild in
let! nyseData = nyse in
let! nasdaqData = nasdaq in
let merged = mergeMarketData [ nyseData; nasdaqData ] in
engine.TriggerMergeMarketData(merged);
let! normalized = asyncNormalizeData merged in
engine.TriggerNormalizeMarketData(normalized);
let! analyzed = asyncAnalyzeData normalized in
engine.TriggerAnalyzeMarketData(analyzed);
let! res = asyncRunModel analyzed in
engine.TriggerModelMarketData(res);
return res }
and historicalModel = async {
let! fed = asyncLoadFedHistoricalData() in
engine.TriggerLoadFedHistoricalData(fed);
let! normalized = asyncNormalizeData fed in
engine.TriggerNormalizeHistoricalData(normalized);
let! analyzed = asyncAnalyzeData normalized in
engine.TriggerAnalyzeHistoricalData(analyzed);
let! res = asyncRunModel analyzed in
engine.TriggerModelHistoricalData(res);
return res } in
engine
end
end