Last active
August 29, 2015 14:23
-
-
Save muxueqz/ae91ee1fe316207aa360 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2 | |
| try: | |
| year_input = int(raw_input('Please enter a 4-digit year: ')) | |
| except: | |
| exit('1st arg must be 4-digit year between 1926 and 2012') | |
| factor_input = raw_input('please enter a Fama-French factor: ') | |
| mylist = [] | |
| with open('F-F_Research_Data_Factors_daily.txt') as fh: | |
| lines = fh.readlines() | |
| slicedline = lines[6:-2] | |
| header = lines[5].split() | |
| if year_input >= 1926 and year_input <= 2012: | |
| print 'available factors: {0}'.format(header) | |
| else: | |
| exit('1st arg must be 4-digit year between 1926 and 2012') | |
| for element in slicedline: | |
| factor_index = header.index(factor_input) + 1 | |
| if year_input == int(element.split()[0][:4]): | |
| value = element.split()[factor_index] | |
| mylist.append(value) | |
| if factor_input in header: | |
| len_list = len(mylist) | |
| sumlist = sum([float(y) for y in mylist]) | |
| print '{0} values, avg {1}'.format(len_list,sumlist/len_list) | |
| else: | |
| print '2nd arg must be one of the four factors {0}'. format(header) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment