-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstock_prices.juttle
64 lines (56 loc) · 1.61 KB
/
stock_prices.juttle
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
/*
* Reading stock quote data from Yahoo Finance via built-in http adapter
*
* $ juttle stock_prices.juttle --input symbol=goog
*/
input symbol: text -default 'IBM' -label 'Stock Ticker';
const start = :1 year ago:;
const end = :now:;
// Calculate the time span parameters
const a = Date.get(start, 'month') - 1;
const b = Date.get(start, 'day') - 1;
const c = Date.get(start, 'year');
const d = Date.get(end, 'month') - 1;
const e = Date.get(end, 'day') - 1;
const f = Date.get(end, 'year');
// Fetch either data (d) or dividends (v)
sub fetch(what) {
const url = 'http://real-chart.finance.yahoo.com/table.csv?s=${symbol}&a=${a}&b=${b}&c=${c}&d=${d}&e=${d}&f=${f}&g=${what}&ignore=.csv';
read http -url url
| put #Symbol = symbol
| put date = Date.new(#Date)
| sort date
| put time = date
}
sub prices() {
fetch -what 'd'
| keep time, Close, Volume
| split
| reduce -forget false -every :d: value=last(value) by name
| (
filter name = 'Volume'
| put value = Number.fromString(value ?? "0");
filter name = 'Close'
| filter value != null
| put value = Number.fromString(value);
)
| view timechart
-title '${symbol} closing price' -id 'chart'
-downsample false
-keyField 'name'
-valueField 'value'
-series [
{name: 'Close', geom: 'line', yScale: 'primary'},
{name: 'Volume', geom: 'bars', yScale: 'secondary'}
];
}
sub dividends() {
fetch -what 'v'
| put message = "Dividend of $${Dividends} per share"
|(
view table -title "Dividends paid";
view events -on 'chart' -messageField 'message'
)
}
prices;
dividends;