PageRenderTime 28ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/QSTK/Examples/Validation.py

https://gitlab.com/gregas/Classwork
Python | 177 lines | 116 code | 21 blank | 40 comment | 23 complexity | b7000e9e7e0afd7a098c5fb6fe5f356f MD5 | raw file
  1. '''
  2. (c) 2011, 2012 Georgia Tech Research Corporation
  3. This source code is released under the New BSD license. Please see
  4. http://wiki.quantsoftware.org/index.php?title=QSTK_License
  5. for license details.
  6. Created on February, 9, 2013
  7. @author: Sourabh Bajaj
  8. @contact: sourabhbajaj@gatech.edu
  9. @summary: Python Validation Script
  10. '''
  11. # Printing what Python Version is installed : QSTK uses 2.7
  12. import sys
  13. import platform
  14. print "Python Details : "
  15. print sys.version
  16. print "Your Python Version is : ", platform.python_version()
  17. print "QSTK uses Python 2.7.X (2.7.3 recommended and supported)"
  18. print "Please make sure you're using the correct python version."
  19. print
  20. # Printing the directory you are in
  21. import os
  22. print "Current Directory : ", os.path.abspath('.')
  23. print
  24. # Printing files in the current directory.
  25. print "Files in the current directory"
  26. ls_files = os.listdir('.')
  27. for s_file in ls_files:
  28. print s_file
  29. print
  30. # Testing the dependencies
  31. # Testing numpy
  32. try:
  33. import numpy
  34. print "Numpy is installed and the version used is : ", numpy.__version__
  35. print "Please make sure you're using version >= 1.6.1"
  36. except ImportError:
  37. sys.exit("Error : Numpy can not be imported or not installed.")
  38. print
  39. # Testing matplotlib
  40. try:
  41. import matplotlib
  42. print "Matplotlib is installed and version is : ", matplotlib.__version__
  43. print "Please make sure you're using version >= 1.1.0"
  44. except ImportError:
  45. sys.exit("Error : Matplotlib can not be imported or not installed.")
  46. print
  47. # Testing Pandas
  48. try:
  49. import pandas
  50. print "Pandas is installed and the version used is : ", pandas.__version__
  51. print "Please make sure you're using version >= 0.7.3"
  52. except ImportError:
  53. sys.exit("Error : Pandas can not be imported or not installed.")
  54. print
  55. # Testing Scipy
  56. try:
  57. import scipy
  58. print "Scipy is installed and the version used is : ", scipy.__version__
  59. print "Please make sure you're using version >= 0.9.0"
  60. except ImportError:
  61. sys.exit("Error : Scipy can not be imported or not installed.")
  62. print
  63. # Testing Dateutil
  64. try:
  65. import dateutil
  66. print "Dateutil is installed and the version used is : ", dateutil.__version__
  67. print "Please make sure you're using version == 1.5"
  68. except ImportError:
  69. sys.exit("Error : Dateutil can not be imported or not installed.")
  70. print
  71. # Testing Setuptools
  72. try:
  73. import setuptools
  74. print "Setuptools is installed and the version used is : ", setuptools.__version__
  75. print "Please make sure you're using version >= 0.6"
  76. except ImportError:
  77. sys.exit("Error : Setuptools can not be imported or not installed.")
  78. print
  79. # # Testing CVXOPT
  80. # try:
  81. # import cvxopt
  82. # print "CVXOPT is installed and can be imported"
  83. # except ImportError:
  84. # sys.exit("Error : CVXOPT can not be imported or not installed.")
  85. # print
  86. # Testing datetime
  87. try:
  88. import datetime as dt
  89. print "datetime is installed and can be imported"
  90. except ImportError:
  91. sys.exit("Error : datetime can not be imported or not installed.")
  92. print
  93. # All dependencies are installed and working
  94. print "All dependencies are installed and working\n"
  95. # Testing import of QSTK
  96. # Testing QSTK
  97. try:
  98. import QSTK
  99. print "QSTK is installed and can be imported"
  100. except ImportError:
  101. sys.exit("Error : QSTK can not be imported or not installed.")
  102. print
  103. # Testing QSTK.qstkutil
  104. try:
  105. import QSTK.qstkutil.tsutil as tsu
  106. import QSTK.qstkutil.qsdateutil as du
  107. import QSTK.qstkutil.DataAccess as da
  108. print "QSTK.qstkutil is installed and can be imported"
  109. except ImportError:
  110. exit("Error : QSTK.qstkutil can not be imported.")
  111. print
  112. # Testing QSTK.qstkstudy
  113. try:
  114. import QSTK.qstkstudy.EventProfiler
  115. print "QSTK.qstkstudy is installed and can be imported"
  116. except ImportError:
  117. exit("Error : QSTK.qstkstudy can not be imported.")
  118. print
  119. # Checking that the data installed is correct.
  120. # Start and End date of the charts
  121. dt_start = dt.datetime(2012, 2, 10)
  122. dt_end = dt.datetime(2012, 2, 24)
  123. dt_timeofday = dt.timedelta(hours=16)
  124. # Get a list of trading days between the start and the end.
  125. ldt_timestamps = du.getNYSEdays(dt_start, dt_end, dt_timeofday)
  126. ls_symbols = ['MSFT', 'GOOG']
  127. # Creating an object of the dataaccess class with Yahoo as the source.
  128. c_dataobj = da.DataAccess('Yahoo', verbose=True)
  129. # Reading adjusted_close prices
  130. df_close = c_dataobj.get_data(ldt_timestamps, ls_symbols, "close")
  131. print df_close
  132. print
  133. print "\nCorrect Output using the Default Data should be : "
  134. print "Assignments use this data for grading"
  135. print " MSFT GOOG"
  136. print "2012-02-10 16:00:00 29.90 605.91"
  137. print "2012-02-13 16:00:00 29.98 612.20"
  138. print "2012-02-14 16:00:00 29.86 609.76"
  139. print "2012-02-15 16:00:00 29.66 605.56"
  140. print "2012-02-16 16:00:00 30.88 606.52"
  141. print "2012-02-17 16:00:00 30.84 604.64"
  142. print "2012-02-21 16:00:00 31.03 614.00"
  143. print "2012-02-22 16:00:00 30.86 607.94"
  144. print "2012-02-23 16:00:00 30.96 606.11"
  145. print
  146. dt_test = dt.datetime(2012, 2, 15, 16)
  147. print "Close price of MSFT on 2012/2/15 is : ", df_close['MSFT'].ix[dt_test]
  148. if df_close['MSFT'].ix[dt_test] == 29.66:
  149. print "Data looks correct as the close price in default data is 29.66"
  150. else:
  151. print "Default data used in the assisgnments has close price as 29.66"
  152. sys.exit("Error : Data has changed so does not match data used in Assignments")
  153. print
  154. print "Everything works fine: You're all set."