Skip to content

Instantly share code, notes, and snippets.

@MustafaCoder2022
Created October 21, 2022 13:35
Show Gist options
  • Save MustafaCoder2022/9a0d410fb0994737a95ec4c4edb3bcfd to your computer and use it in GitHub Desktop.
Save MustafaCoder2022/9a0d410fb0994737a95ec4c4edb3bcfd to your computer and use it in GitHub Desktop.
11.12. Chapter Assessment
with open('SP500.txt','r') as fileref:
total_sp = 0
count_sp = 0
max_interest = None
for idx,line in enumerate(fileref):
if idx == 0:
continue
columns = line.strip().split(',')
#print('columns',columns)
date = columns[0]
#print(date)
month_date = int(date.split('/')[0])
#print(month_date)
year_date = int(date.split('/')[2])
if (year_date == 2016 and month_date >= 6) or (year_date == 2017 and month_date <= 5):
#print(columns[:])
current_sp = float(columns[1])
interest_rate =float(columns[5])
#print(current_sp)
#print(interest_rate)
total_sp += current_sp
count_sp +=1
#print(total_sp)
#print(count_sp)
if max_interest is None or max_interest < interest_rate:
max_interest = interest_rate
mean_SP = total_sp / count_sp
print(mean_SP)
print(max_interest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment