-
Notifications
You must be signed in to change notification settings - Fork 0
/
dosranks.ml
71 lines (60 loc) · 2.38 KB
/
dosranks.ml
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
(* compute starranks *)
open Common
open Getopt
let invert' = ref false
let minDays' = ref (Some 7)
let minCap' = ref 1e-35
let mark' = ref ""
let prefix' = ref "stars"
let outdir' = ref (Some !prefix')
let drepsInfix' = ref "dreps"
let dmentsInfix' = ref "dments"
let specs =
[
(noshort,"prefix",None,Some (fun x -> prefix' := x));
(noshort,"outdir",None,Some (fun x -> outdir' := Some x));
(noshort,"nodir", (set outdir' None), None);
(noshort,"dreps", None,Some (fun x -> drepsInfix' := x));
(noshort,"dments",None,Some (fun x -> dmentsInfix' := x));
('i',"invert",(set invert' (not !invert')),None);
('d',"mindays",None,Some (fun x -> minDays' := Some (int_of_string x)));
(noshort,"nomindays",(set minDays' None), None);
('c',"mincap",None,Some (fun x -> minCap' := float_of_string x));
('k',"mark", None,Some (fun x -> mark' := x))
]
let () =
let args = getOptArgs specs in
let invert, minDays, minCap =
!invert', !minDays', !minCap' in
let drepsInfix, dmentsInfix =
!drepsInfix', !dmentsInfix' in
let prefix, outdir, mark =
!prefix', !outdir', !mark' in
let drepsName,dcapsName,outdir =
match args with
| drepsName::dcapsName::outdir::restArgs -> drepsName,dcapsName,Some outdir
| drepsName::dcapsName::restArgs -> drepsName,dcapsName,outdir
| _ -> failwith "usage: dosranks drepsName dcapsName [outdir]"
in
let baseName = cutPathZ drepsName in
let ok,baseName =
if invert
then String.replace ~str:baseName ~sub:drepsInfix ~by:dmentsInfix
else true,baseName in
assert ok;
let starsName = sprintf "%s-%s%s" prefix mark baseName |> mayPrependDir outdir in
leprintfln "reading dreps from %s, dcaps from %s, storing stars in %s" drepsName dcapsName starsName;
begin match minDays with
| Some minDays -> leprintfln "applying minCap %e for maturities less than %d days" minCap minDays
| _ -> leprintfln "not using maturity at all"
end;
let dreps: dreps = loadData drepsName in
let dreps = if invert then Invert.invert2 dreps else dreps in
let dcaps: dcaps = loadData dcapsName in
let dcapsh,startsh = Dcaps.dcaps_hash dcaps in
let maturity = match minDays with
| Some minDays -> Some (startsh,minDays,minCap)
| _ -> None in
let stars: starrank = Starrank.starrank dreps dcapsh maturity in
mayMkDir outdir;
saveData stars starsName