-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicTest.py
More file actions
executable file
·65 lines (53 loc) · 2.75 KB
/
dynamicTest.py
File metadata and controls
executable file
·65 lines (53 loc) · 2.75 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
#!/usr/bin/python
import argparse, sys, os, subprocess
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
#following from Python cookbook, #475186
def has_colours(stream):
if not hasattr(stream, "isatty"):
return False
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
# guess false in case of error
return False
has_colours = has_colours(sys.stdout)
def printout(text, colour=WHITE):
if has_colours:
seq = "\x1b[1;%dm" % (30+colour) + text + "\x1b[0m"
sys.stdout.write(seq)
else:
sys.stdout.write(text)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Tests for Pricer 2014')
subparsers = parser.add_subparsers()
# Price option
parser_price_option = subparsers.add_parser('price_option', help='Test the option pricer')
parser_price_option.set_defaults(which='parser_price_option')
parser_price_option.add_argument('-f','--file', required=True, type=argparse.FileType('r'))
parser_price_option.add_argument('-t','--time', type = float, default = '-1')
# Compute delta
parser_compute_delta = subparsers.add_parser('compute_delta', help='Compute the delta of an option')
parser_compute_delta.set_defaults(which='parser_compute_delta');
parser_compute_delta.add_argument('-f','--file', required=True, type=argparse.FileType('r'))
parser_compute_delta.add_argument('-t','--time', required=True, type = float, default = '-1')
# Profit & Loss
parser_profit_and_loss = subparsers.add_parser('profit_and_loss', help='Test monte carlo')
parser_profit_and_loss.set_defaults(which='parser_profit_and_loss');
parser_profit_and_loss.add_argument('-f','--file', required=True, type=argparse.FileType('r'))
args = parser.parse_args()
if (args.which == 'parser_price_option'):
if (not os.path.exists("build/price-option")):
printout('Could not find build/price-option, build the project before using this script\n', RED);
subprocess.call(['build/price-option',args.file.name, str(args.time)])
elif (args.which == 'parser_compute_delta'):
if (not os.path.exists("build/compute-delta")):
printout('Could not find build/compute-delta, build the project before using this script\n', RED);
subprocess.call(['build/compute-delta',args.file.name, str(args.time)])
elif (args.which == 'parser_profit_and_loss'):
if (not os.path.exists("build/profit-and-loss")):
printout('Could not find build/profit-and-loss, build the project before using this script\n', RED);
subprocess.call(['build/profit-and-loss',args.file.name])