mirror of
https://github.com/andrewkdinh/fund-indicators.git
synced 2024-11-24 08:14:17 -08:00
Update StockReturn.py
This commit is contained in:
parent
61e0cd0d91
commit
7f675e25ae
@ -55,19 +55,19 @@ class Return:
|
|||||||
if firstDateExists == False:
|
if firstDateExists == False:
|
||||||
print("Could not find first date. Changing first date to closest date")
|
print("Could not find first date. Changing first date to closest date")
|
||||||
tempDate = Functions.stringToDate(firstDate) # Change to datetime
|
tempDate = Functions.stringToDate(firstDate) # Change to datetime
|
||||||
print('Original first date: ', tempDate)
|
print('Original first date:', tempDate)
|
||||||
#tempDate = datetime.date(2014,1,17)
|
#tempDate = datetime.date(2014,1,17)
|
||||||
newFirstDate = Functions.getNearest(finalDatesAndClose2[0], tempDate)
|
newFirstDate = Functions.getNearest(finalDatesAndClose2[0], tempDate)
|
||||||
print('New first date: ', newFirstDate)
|
print('New first date:', newFirstDate)
|
||||||
firstDate = str(newFirstDate)
|
firstDate = str(newFirstDate)
|
||||||
|
|
||||||
if lastDateExists == False:
|
if lastDateExists == False:
|
||||||
print("Could not find final date. Changing final date to closest date")
|
print("Could not find final date. Changing final date to closest date")
|
||||||
tempDate2 = Functions.stringToDate(lastDate) # Change to datetime
|
tempDate2 = Functions.stringToDate(lastDate) # Change to datetime
|
||||||
print('Original final date: ', tempDate2)
|
print('Original final date:', tempDate2)
|
||||||
#tempDate2 = datetime.date(2014,1,17)
|
#tempDate2 = datetime.date(2014,1,17)
|
||||||
newLastDate = Functions.getNearest(finalDatesAndClose2[0], tempDate2)
|
newLastDate = Functions.getNearest(finalDatesAndClose2[0], tempDate2)
|
||||||
print('New final date: ', newLastDate)
|
print('New final date:', newLastDate)
|
||||||
lastDate = str(newLastDate)
|
lastDate = str(newLastDate)
|
||||||
|
|
||||||
firstLastDates = []
|
firstLastDates = []
|
||||||
@ -81,6 +81,19 @@ class Return:
|
|||||||
firstDate = self.firstLastDates[0]
|
firstDate = self.firstLastDates[0]
|
||||||
lastDate = self.firstLastDates[1]
|
lastDate = self.firstLastDates[1]
|
||||||
finalDates = finalDatesAndClose[0]
|
finalDates = finalDatesAndClose[0]
|
||||||
|
finalClose = finalDatesAndClose[1]
|
||||||
|
|
||||||
|
for i in range(0, len(finalDates), 1):
|
||||||
|
if finalDates[i] == str(firstDate):
|
||||||
|
firstClose = finalClose[i]
|
||||||
|
elif finalDates[i] == lastDate:
|
||||||
|
lastClose = finalClose[i]
|
||||||
|
i = len(finalDates)
|
||||||
|
|
||||||
|
print('Close values:', firstClose, '...', lastClose)
|
||||||
|
unadjustedReturn = float(lastClose/firstClose)
|
||||||
|
unadjustedReturn = unadjustedReturn * 100
|
||||||
|
return unadjustedReturn
|
||||||
|
|
||||||
# def getBeta(self, timeFrame):
|
# def getBeta(self, timeFrame):
|
||||||
|
|
||||||
@ -89,6 +102,8 @@ class Return:
|
|||||||
def main(self, stock):
|
def main(self, stock):
|
||||||
# Find date to start from and last date
|
# Find date to start from and last date
|
||||||
self.timeFrame = []
|
self.timeFrame = []
|
||||||
|
self.listOfReturn = []
|
||||||
|
|
||||||
print("\nPlease enter a time frame in years: ", end='')
|
print("\nPlease enter a time frame in years: ", end='')
|
||||||
#timeFrameYear = int(input())
|
#timeFrameYear = int(input())
|
||||||
timeFrameYear = 5
|
timeFrameYear = 5
|
||||||
@ -107,7 +122,9 @@ class Return:
|
|||||||
print('New dates: ', self.firstLastDates)
|
print('New dates: ', self.firstLastDates)
|
||||||
|
|
||||||
print('\nGetting unadjusted return')
|
print('\nGetting unadjusted return')
|
||||||
Return.getUnadjustedReturn(self, stock)
|
unadjustedReturn = Return.getUnadjustedReturn(self, stock)
|
||||||
|
self.listOfReturn.append(unadjustedReturn)
|
||||||
|
print(self.listOfReturn[0], '%')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
stockName = 'spy'
|
stockName = 'spy'
|
||||||
|
Loading…
Reference in New Issue
Block a user