-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdump-dolt.rkt
148 lines (134 loc) · 4.82 KB
/
dump-dolt.rkt
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#lang racket/base
(require db
gregor
racket/cmdline
racket/string
racket/system)
(define base-folder (make-parameter "/var/tmp/dolt/options"))
(define start-date (make-parameter (~t (today) "yyyy-MM-dd")))
(define end-date (make-parameter (~t (today) "yyyy-MM-dd")))
(define db-user (make-parameter "user"))
(define db-name (make-parameter "local"))
(define db-pass (make-parameter ""))
(command-line
#:program "racket dump-dolt.rkt"
#:once-each
[("-b" "--base-folder") folder
"Base dolt folder. Defaults to /var/tmp/dolt/options"
(base-folder folder)]
[("-e" "--end-date") end
"Final date for history retrieval. Defaults to today"
(end-date end)]
[("-n" "--db-name") name
"Database name. Defaults to 'local'"
(db-name name)]
[("-p" "--db-pass") password
"Database password"
(db-pass password)]
[("-s" "--start-date") start
"Earliest date for history retrieval. Defaults to today"
(start-date start)]
[("-u" "--db-user") user
"Database user name. Defaults to 'user'"
(db-user user)])
(define dbc (postgresql-connect #:user (db-user) #:database (db-name) #:password (db-pass)))
; option-chain
(for-each (λ (date)
(define option-chain-file (string-append (base-folder) "/option-chain-" date ".csv"))
(call-with-output-file* option-chain-file
(λ (out)
(displayln "date,act_symbol,expiration,strike,call_put,bid,ask,vol,delta,gamma,theta,vega,rho" out)
(for-each (λ (row)
(displayln (string-join (vector->list row) ",") out))
(query-rows dbc "
select
date::text,
act_symbol::text,
expiration::text,
strike::text,
call_put::text,
bid::text,
ask::text,
vol::text,
delta::text,
gamma::text,
theta::text,
vega::text,
rho::text
from
oic.option_chain
where
date = $1::text::date
order by
act_symbol, expiration, strike, call_put;
"
date)))
#:exists 'replace)
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt table import -u --continue option_chain option-chain-" date ".csv")))
(query-list dbc "
select distinct
date::text
from
oic.option_chain
where
date >= $1::text::date and
date <= $2::text::date
order by
date;
"
(start-date)
(end-date)))
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt add option_chain; "
"/usr/local/bin/dolt commit -m 'option_chain " (end-date) " update'; /usr/local/bin/dolt push --silent"))
; volatility-history
(for-each (λ (date)
(define volatility-history-file (string-append (base-folder) "/volatility-history-" date ".csv"))
(call-with-output-file* volatility-history-file
(λ (out)
(displayln "date,act_symbol,hv_current,hv_week_ago,hv_month_ago,hv_year_high,hv_year_high_date,hv_year_low,hv_year_low_date,iv_current,iv_week_ago,iv_month_ago,iv_year_high,iv_year_high_date,iv_year_low,iv_year_low_date" out)
(for-each (λ (row)
(displayln (string-join (vector->list row) ",") out))
(query-rows dbc "
select
date::text,
act_symbol::text,
coalesce(hv_current::text, ''),
coalesce(hv_week_ago::text, ''),
coalesce(hv_month_ago::text, ''),
coalesce(hv_year_high::text, ''),
coalesce(hv_year_high_date::text, ''),
coalesce(hv_year_low::text, ''),
coalesce(hv_year_low_date::text, ''),
coalesce(iv_current::text, ''),
coalesce(iv_week_ago::text, ''),
coalesce(iv_month_ago::text, ''),
coalesce(iv_year_high::text, ''),
coalesce(iv_year_high_date::text, ''),
coalesce(iv_year_low::text, ''),
coalesce(iv_year_low_date::text, '')
from
oic.volatility_history
where
date = $1::text::date
order by
act_symbol;
"
date)))
#:exists 'replace)
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt table import -u --continue volatility_history volatility-history-" date ".csv")))
(query-list dbc "
select distinct
date::text
from
oic.volatility_history
where
date >= $1::text::date and
date <= $2::text::date
order by
date;
"
(start-date)
(end-date)))
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt add volatility_history; "
"/usr/local/bin/dolt commit -m 'volatility_history " (end-date) " update'; /usr/local/bin/dolt push --silent"))
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt gc"))