Created
June 28, 2015 15:54
-
-
Save muxueqz/9671f827bd94999de2b1 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
year_input = raw_input('Please enter a 4-digit year: ') | |
mylist = [] | |
with open('F-F_Research_Data_Factors_daily.txt') as fh: | |
lines = fh.readlines() | |
slicedline = lines[6:-2] | |
header = lines[5].split() | |
for element in slicedline: | |
yearstr = element.split()[0] | |
print type(year_input), type(yearstr[:4]), yearstr[:4] | |
if year_input == yearstr[:4]: | |
print 'available factors: {0}'.format(header) | |
factor_input = raw_input('please enter a Fama-French factor: ') | |
factor_index = header.index(factor_input) + 1 | |
value = element.split()[factor_index] | |
mylist.append(value) | |
if len(mylist) == 0: | |
exit('1st arg must be 4-digit year between 1926 and 2012') | |
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