forked from evdubs/chart-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.rkt
More file actions
65 lines (56 loc) · 1.59 KB
/
structs.rkt
File metadata and controls
65 lines (56 loc) · 1.59 KB
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
#lang racket/base
(require racket/list
racket/stream) ; needed for gen:stream
(provide (struct-out dv)
(struct-out dohlc)
(struct-out test)
test-timeframe-minus-1
(struct-out trade)
(struct-out position)
(struct-out history))
(struct dv (date value)
#:transparent
#:methods gen:stream
[(define (stream-empty? stream)
(cond
[(dv? stream) #f]
[else (empty? stream)]))
(define (stream-first stream)
(cond
[(dv? stream) (dv-date stream)]
[else (first stream)]))
(define (stream-rest stream)
(cond
[(dv? stream) (list (dv-value stream))]
[else (rest stream)]))])
(struct dohlc (date open high low close)
#:transparent
#:methods gen:stream
[(define (stream-empty? stream)
(cond
[(dohlc? stream) #f]
[else (empty? stream)]))
(define (stream-first stream)
(cond
[(dohlc? stream) (dohlc-date stream)]
[else (first stream)]))
(define (stream-rest stream)
(cond
[(dohlc? stream) (list (dohlc-open stream)
(dohlc-high stream)
(dohlc-low stream)
(dohlc-close stream))]
[else (rest stream)]))])
(struct test (timeframe entry stop target)
#:transparent)
(define (test-timeframe-minus-1 t)
(test (- (test-timeframe t) 1)
(test-entry t)
(test-stop t)
(test-target t)))
(struct trade (date price amount test)
#:transparent)
(struct position (price amount)
#:transparent)
(struct history (test trade)
#:transparent)