-
Notifications
You must be signed in to change notification settings - Fork 0
/
Validation.py
182 lines (159 loc) · 5.38 KB
/
Validation.py
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
'''
(c) 2011, 2012 Georgia Tech Research Corporation
This source code is released under the New BSD license. Please see
http://wiki.quantsoftware.org/index.php?title=QSTK_License
for license details.
Created on February, 9, 2013
@author: Sourabh Bajaj
@contact: sourabhbajaj@gatech.edu
@summary: Python Validation Script
'''
# Printing what Python Version is installed : QSTK uses 2.7
import sys
import platform
print "Python Details : "
print sys.version
print "Your Python Version is : ", platform.python_version()
print "QSTK uses Python 2.7.X (2.7.3 recommended and supported)"
print "Please make sure you're using the correct python version."
print
# Printing the directory you are in
import os
print "Current Directory : ", os.path.abspath('.')
print
# Printing files in the current directory.
print "Files in the current directory"
ls_files = os.listdir('.')
for s_file in ls_files:
print s_file
print
# Testing the dependencies
# Testing numpy
try:
import numpy
print "Numpy is installed and the version used is : ", numpy.__version__
print "Please make sure you're using version >= 1.6.1"
except:
sys.exit("Error : Numpy can not be imported or not installed.")
print
# Testing matplotlib
try:
import matplotlib
print "Matplotlib is installed and version is : ", matplotlib.__version__
print "Please make sure you're using version >= 1.1.0"
except:
sys.exit("Error : Matplotlib can not be imported or not installed.")
print
# Testing Pandas
try:
import pandas
print "Pandas is installed and the version used is : ", pandas.__version__
print "Please make sure you're using version == 0.7.3"
print "IMPORTANT: No other pandas version is supported except 0.7.3"
s_pd_version = pandas.__version__
if s_pd_version[:5] != '0.7.3':
sys.exit("Error : Pandas version should be 0.7.3")
except:
print "Error : Please install Pandas 0.7.3"
sys.exit("Error : Pandas can not be imported or not installed.")
print
# Testing Scipy
try:
import scipy
print "Scipy is installed and the version used is : ", scipy.__version__
print "Please make sure you're using version >= 0.9.0"
except:
sys.exit("Error : Scipy can not be imported or not installed.")
print
# Testing Dateutil
try:
import dateutil
print "Dateutil is installed and the version used is : ", dateutil.__version__
print "Please make sure you're using version == 1.5"
except:
sys.exit("Error : Dateutil can not be imported or not installed.")
print
# Testing Setuptools
try:
import setuptools
print "Setuptools is installed and the version used is : ", setuptools.__version__
print "Please make sure you're using version >= 0.6"
except:
sys.exit("Error : Setuptools can not be imported or not installed.")
print
# Testing CVXOPT
try:
import cvxopt
print "CVXOPT is installed and can be imported"
except:
sys.exit("Error : CVXOPT can not be imported or not installed.")
print
# Testing datetime
try:
import datetime as dt
print "datetime is installed and can be imported"
except:
sys.exit("Error : datetime can not be imported or not installed.")
print
# All dependencies are installed and working
print "All dependencies are installed and working\n"
# Testing import of QSTK
# Testing QSTK
try:
import QSTK
print "QSTK is installed and can be imported"
except:
sys.exit("Error : QSTK can not be imported or not installed.")
print
# Testing QSTK.qstkutil
try:
import QSTK.qstkutil.tsutil as tsu
import QSTK.qstkutil.qsdateutil as du
import QSTK.qstkutil.DataAccess as da
print "QSTK.qstkutil is installed and can be imported"
except:
exit("Error : QSTK.qstkutil can not be imported.")
print
# Testing QSTK.qstkstudy
try:
import QSTK.qstkstudy.EventProfiler
print "QSTK.qstkstudy is installed and can be imported"
except:
exit("Error : QSTK.qstkstudy can not be imported.")
print
# Checking that the data installed is correct.
# Start and End date of the charts
dt_start = dt.datetime(2012, 2, 10)
dt_end = dt.datetime(2012, 2, 24)
dt_timeofday = dt.timedelta(hours=16)
# Get a list of trading days between the start and the end.
ldt_timestamps = du.getNYSEdays(dt_start, dt_end, dt_timeofday)
ls_symbols = ['MSFT', 'GOOG']
# Creating an object of the dataaccess class with Yahoo as the source.
c_dataobj = da.DataAccess('Yahoo')
# Reading adjusted_close prices
df_close = c_dataobj.get_data(ldt_timestamps, ls_symbols, "close")
print df_close
print
print "\nCorrect Output using the Default Data should be : "
print "Assignments use this data for grading"
print " MSFT GOOG"
print "2012-02-10 16:00:00 29.90 605.91"
print "2012-02-13 16:00:00 29.98 612.20"
print "2012-02-14 16:00:00 29.86 609.76"
print "2012-02-15 16:00:00 29.66 605.56"
print "2012-02-16 16:00:00 30.88 606.52"
print "2012-02-17 16:00:00 30.84 604.64"
print "2012-02-21 16:00:00 31.03 614.00"
print "2012-02-22 16:00:00 30.86 607.94"
print "2012-02-23 16:00:00 30.96 606.11"
print
dt_test = dt.datetime(2012, 2, 15, 16)
print "Close price of MSFT on 2012/2/15 is : ", df_close['MSFT'].ix[dt_test]
if df_close['MSFT'].ix[dt_test] == 29.66:
print "Data looks correct as the close price in default data is 29.66"
else:
print "Default data used in the assisgnments has close price as 29.66"
sys.exit("Error : Data has changed so does not match data used in Assignments")
print
print "Everything works fine: You're all set."