@@ -2,20 +2,20 @@ import * as Plot from "@observablehq/plot";
2
2
import * as d3 from "d3" ;
3
3
4
4
export async function aaplBollinger ( ) {
5
- const AAPL = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
5
+ const aapl = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
6
6
return Plot . plot ( {
7
7
y : {
8
8
grid : true
9
9
} ,
10
10
marks : [
11
- Plot . bollingerY ( AAPL , { x : "Date" , y : "Close" , stroke : "blue" } ) ,
12
- Plot . line ( AAPL , { x : "Date" , y : "Close" , strokeWidth : 1 } )
11
+ Plot . bollingerY ( aapl , { x : "Date" , y : "Close" , stroke : "blue" } ) ,
12
+ Plot . line ( aapl , { x : "Date" , y : "Close" , strokeWidth : 1 } )
13
13
]
14
14
} ) ;
15
15
}
16
16
17
17
export async function aaplBollingerGridInterval ( ) {
18
- const AAPL = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
18
+ const aapl = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
19
19
return Plot . plot ( {
20
20
marks : [
21
21
Plot . frame ( { fill : "#eaeaea" } ) ,
@@ -25,14 +25,14 @@ export async function aaplBollingerGridInterval() {
25
25
Plot . gridX ( { tickSpacing : 40 , stroke : "#fff" , strokeOpacity : 1 , strokeWidth : 0.5 } ) ,
26
26
Plot . gridX ( { tickSpacing : 80 , stroke : "#fff" , strokeOpacity : 1 } ) ,
27
27
Plot . axisX ( { tickSpacing : 80 } ) ,
28
- Plot . bollingerY ( AAPL , { x : "Date" , y : "Close" , stroke : "blue" } ) ,
29
- Plot . line ( AAPL , { x : "Date" , y : "Close" , strokeWidth : 1 } )
28
+ Plot . bollingerY ( aapl , { x : "Date" , y : "Close" , stroke : "blue" } ) ,
29
+ Plot . line ( aapl , { x : "Date" , y : "Close" , strokeWidth : 1 } )
30
30
]
31
31
} ) ;
32
32
}
33
33
34
34
export async function aaplBollingerGridSpacing ( ) {
35
- const AAPL = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
35
+ const aapl = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
36
36
return Plot . plot ( {
37
37
marks : [
38
38
Plot . frame ( { fill : "#eaeaea" } ) ,
@@ -42,8 +42,29 @@ export async function aaplBollingerGridSpacing() {
42
42
Plot . gridX ( { interval : "3 months" , stroke : "#fff" , strokeOpacity : 1 , strokeWidth : 0.5 } ) ,
43
43
Plot . gridX ( { interval : "1 year" , stroke : "#fff" , strokeOpacity : 1 } ) ,
44
44
Plot . axisX ( { interval : "1 year" } ) ,
45
- Plot . bollingerY ( AAPL , { x : "Date" , y : "Close" , stroke : "blue" } ) ,
46
- Plot . line ( AAPL , { x : "Date" , y : "Close" , strokeWidth : 1 } )
45
+ Plot . bollingerY ( aapl , { x : "Date" , y : "Close" , stroke : "blue" } ) ,
46
+ Plot . line ( aapl , { x : "Date" , y : "Close" , strokeWidth : 1 } )
47
+ ]
48
+ } ) ;
49
+ }
50
+
51
+ export async function aaplBollingerCandlestick ( ) {
52
+ const aapl = await d3 . csv < any > ( "data/aapl.csv" , d3 . autoType ) ;
53
+ return Plot . plot ( {
54
+ x : { domain : [ new Date ( "2014-01-01" ) , new Date ( "2014-06-01" ) ] } ,
55
+ y : { domain : [ 68 , 92 ] , grid : true } ,
56
+ color : { domain : [ - 1 , 0 , 1 ] , range : [ "red" , "black" , "green" ] } ,
57
+ marks : [
58
+ Plot . bollingerY ( aapl , { x : "Date" , y : "Close" , stroke : "none" , clip : true } ) ,
59
+ Plot . ruleX ( aapl , { x : "Date" , y1 : "Low" , y2 : "High" , strokeWidth : 1 , clip : true } ) ,
60
+ Plot . ruleX ( aapl , {
61
+ x : "Date" ,
62
+ y1 : "Open" ,
63
+ y2 : "Close" ,
64
+ strokeWidth : 3 ,
65
+ stroke : ( d ) => Math . sign ( d . Close - d . Open ) ,
66
+ clip : true
67
+ } )
47
68
]
48
69
} ) ;
49
70
}
0 commit comments