-
Notifications
You must be signed in to change notification settings - Fork 115
/
futurepricing.py
69 lines (45 loc) · 2.06 KB
/
futurepricing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import pandas as pd
from pandas_datareader import data as web
from datetime import datetime as dt
def generate_price_df(ticker,financialreportingdf,stockpricedf,discountrate,marginrate):
dfprice = pd.DataFrame(columns =['ticker','annualgrowthrate','lasteps','futureeps'])
pd.options.display.float_format = '{:20,.2f}'.format
# Find EPS Annual Compounded Growth Rate
# annualgrowthrate = financialreportingdf.epsgrowth.mean() #growth rate
try:
print(financialreportingdf.eps.iloc[0])
print(financialreportingdf.eps.iloc[-1])
annualgrowthrate = np.rate(5, 0, -1*financialreportingdf.eps.iloc[0], financialreportingdf.eps.iloc[-1])
print(annualgrowthrate)
# Non Conservative
lasteps = financialreportingdf.eps.tail(1).values[0] #presentvalue
# conservative
# lasteps = financialreportingdf.eps.mean()
years = 10 #period
futureeps = abs(np.fv(annualgrowthrate,years,0,lasteps))
dfprice.loc[0] = [ticker,annualgrowthrate,lasteps,futureeps]
except:
print('eps does not exist')
dfprice.set_index('ticker',inplace=True)
#conservative
dfprice['peratio'] = findMinimumEPS(stockpricedf,financialreportingdf)
dfprice['FV'] = dfprice['futureeps']*dfprice['peratio']
dfprice['PV'] = abs(np.pv(discountrate,years,0,fv=dfprice['FV']))
if dfprice['FV'].values[0] > 0:
dfprice['marginprice'] = dfprice['PV']*(1-marginrate)
else:
dfprice['marginprice'] = 0
dfprice['lastshareprice']=stockpricedf.Close.tail(1).values[0]
dfprice['decision'] = np.where((dfprice['lastshareprice']<dfprice['marginprice']),'BUY','SELL')
return dfprice
def findMinimumEPS (stockpricedf,financialreportingdf):
# Given the share price
finrepdf = financialreportingdf.set_index('index')
stockpricedf['year'] = pd.DatetimeIndex(stockpricedf.index).year
gframe = stockpricedf.groupby('year').head(1).set_index('year')
pricebyyear = pd.DataFrame()
pricebyyear['Close'] = gframe['Close']
pricebyyear['eps'] = finrepdf['eps']
pricebyyear['peratio'] = pricebyyear['Close']/pricebyyear['eps']
return pricebyyear['peratio'].min()