forked from Nikkitaseth/ProjectAlpha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
155 lines (141 loc) · 6.28 KB
/
utils.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
"""
@author: Christopher
"""
# FOR BACKTESTING IN 2015 HIDE COMPANIES:
DATA_DIR = "data"
companies = [
'MMM', 'AOS', 'ABT', 'ABBV', 'ACN', 'ATVI', 'AYI', 'ADBE',
#'AAP',
'AMD', 'AES',
#'AET',
#'AMG',
'AFL', 'A', 'APD', 'AKAM', 'ALK', 'ALB', #'ARE',
'ALXN', 'ALGN', 'ALLE', 'AGN', 'ADS', 'LNT', 'ALL', 'GOOGL', #'GOOG',
'MO', 'AMZN', 'AEE', 'AAL', 'AEP', #'AXP',
'AIG', 'AMT', 'AWK', 'AMP', 'ABC', 'AME', 'AMGN', 'APH', 'APC', 'ADI', #'ANDV',
'ANSS', 'ANTM', 'AON', 'APA', 'AIV', 'AAPL', 'AMAT', #'APTV',
'ADM', 'ARNC', 'AJG', 'AIZ', #'T',
'ADSK', 'ADP', 'AZO', 'AVB', 'AVY', #'BHGE',
'BLL', 'BAC', 'BAX', 'BBT', 'BDX', #'BRK.B',
'BBY', 'BIIB', 'BLK', 'HRB', 'BA', 'BKNG', 'BWA', 'BXP', 'BSX', #'BHF',
'BMY', 'AVGO', #'BF.B',
'CHRW', #'CA',
'COG', 'CDNS', 'CPB', 'COF', 'CAH', 'KMX', 'CCL', 'CAT', 'CBOE', 'CBRE', 'CBS',
'CELG', 'CNC', 'CNP', 'CTL', 'CERN', 'CF', 'SCHW', 'CHTR', 'CVX', #'CMG',
'CB', 'CHD', 'CI', 'XEC', 'CINF', 'CTAS', 'CSCO', 'C', 'CFG', 'CTXS', 'CME',
'CMS', 'KO', 'CTSH', 'CL', 'CMCSA', 'CMA', 'CAG', #'CXO',
'COP', 'ED', 'STZ', 'GLW', 'COST', 'COTY', 'CCI', #'CSRA',
'CSX', 'CMI', 'CVS', 'DHI', 'DHR', 'DRI', 'DVA', #'DE',
'DAL', 'XRAY', 'DVN', 'DLR', #'DFS',
'DISCA', 'DISCK', 'DISH', 'DG', 'DLTR', 'D', 'DOV', 'DWDP', #'DPS',
'DTE', 'DUK', 'DRE', #'DXC',
'ETFC', 'EMN', 'ETN', 'EBAY', 'ECL', 'EIX', 'EW', 'EA', 'EMR', 'ETR', #'EVHC',
'EOG', 'EQT', 'EFX', 'EQIX', 'EQR', 'ESS', 'EL', 'RE', #'ES',
'EXC', 'EXPE', 'EXPD', #'ESRX', #'EXR',
'XOM', 'FFIV', 'FB', 'FAST', 'FRT', 'FDX', 'FIS', #'FITB',
'FE', 'FISV', 'FLIR', 'FLS', 'FLR', 'FMC', 'FL', 'F', 'FTV', 'FBHS', 'BEN',
'FCX', 'GPS', 'GRMN', 'IT', 'GD', #'GE', #'GGP',
'GIS', 'GM', 'GPC', 'GILD', 'GPN', #'GS',
'GT', 'GWW', 'HAL', 'HBI', 'HOG', #'HRS',
'HIG', 'HAS', 'HCA', 'HCP', 'HP', #'HSIC',
'HES', 'HPE', 'HLT', 'HOLX', 'HD', 'HON', 'HRL', 'HST', 'HPQ', 'HUM', #'HBAN',
'HII', 'IDXX', #'INFO',
'ITW', 'ILMN', 'INCY', 'IR', 'INTC', 'ICE', 'IBM', 'IP', 'IPG', 'IFF', 'INTU',
'ISRG', 'IVZ', 'IPGP', 'IQV', 'IRM', 'JBHT', 'JEC', 'SJM', 'JNJ', 'JCI', 'JPM',
'JNPR', 'KSU', 'K', #'KEY',
'KMB', 'KIM', 'KMI', 'KLAC', 'KSS', #'KHC',
'KR', 'LB', 'LLL', 'LH', 'LRCX', 'LEG', 'LEN', #'LUK',
'LLY', 'LNC', 'LKQ', 'LMT', 'L', 'LOW', 'LYB', 'MTB', 'MAC', 'M', 'MRO', 'MPC',
'MAR', 'MMC', 'MLM', 'MAS', 'MA', 'MAT', 'MKC', 'MCD', 'MCK', 'MDT', 'MRK',
'MET', 'MTD', 'MGM', #'KORS',
'MCHP', 'MU', 'MSFT', 'MAA', 'MHK', 'TAP', 'MDLZ', #'MON', #'MNST',
'MCO', #'MS',
'MSI', 'MYL', 'NDAQ', 'NOV', 'NAVI', 'NKTR', 'NTAP', 'NFLX', 'NWL', #'NFX',
'NEM', 'NWSA', 'NWS', 'NEE', 'NLSN', 'NKE', 'NI', 'NBL', 'JWN', 'NSC', 'NTRS',
'NOC', 'NCLH', 'NRG', 'NUE', 'NVDA', 'ORLY', 'OXY', 'OMC', 'OKE', 'ORCL', 'PCAR',
# 'PKG',
'PH', 'PAYX', 'PYPL', 'PNR', 'PBCT', 'PEP', 'PKI', 'PRGO', 'PFE', 'PCG', 'PM',
'PSX', 'PNW', 'PXD', 'PNC', 'RL', 'PPG', 'PPL', #'PX',
'PFG', 'PG', 'PGR', 'PLD', 'PRU', 'PEG', 'PSA', 'PHM', 'PVH', 'QRVO', 'QCOM',
'PWR', 'DGX', 'RRC', 'RJF', 'RTN', 'O', 'RHT', 'REG', 'REGN', 'RF', 'RSG',
'RMD', 'RHI', 'ROK', 'COL','ROP', 'ROST', 'RCL', 'SPGI', 'CRM', 'SBAC', # 'SCG', #income statement missing
'SLB', 'STX', 'SEE', 'SRE', 'SHW', 'SPG', 'SWKS', 'SLG', 'SNA', 'SO', 'LUV',
'SWK', 'SBUX', 'STT', 'SRCL', 'SYK', 'STI', #'SIVB',
'SYMC', #'SYF',
'SNPS', 'SYY', #'TROW',
'TTWO', 'TPR', 'TGT', 'TEL', #'FTI',
'TXN', 'TXT', 'BK', 'CLX', 'COO', 'HSY', 'MOS', 'TRV', 'DIS', 'TMO', 'TIF', #'TWX',
'TJX', 'TMK', #'TSS', breaks Sharpe, #'TSCO',
'TDG', 'TRIP', #'FOXA',
'FOX', 'TSN', 'USB', 'UDR', 'ULTA', 'UAA', 'UA', 'UNP', 'UAL', 'UNH', 'UPS',
'URI', 'UTX', 'UHS', 'UNM', 'VFC', 'VLO', 'VAR', 'VTR', 'VRSN', 'VRSK', 'VZ',
'VRTX', 'VIAB', 'V', 'VNO', 'VMC', 'WMT', 'WBA', #'WM', #BS ist von 2018 aber IS und CFS von 2019
'WAT', 'WEC', 'WFC', 'WELL', 'WDC', 'WU', 'WRK', 'WY', 'WHR', 'WMB', 'WLTW',
'WYN', 'WYNN', 'XEL', 'XRX', 'XLNX', #'XL',
'XYL', 'YUM', 'ZBH', #'ZION',
'ZTS'
]
#FUNCTIONS THAT GRAB ALL THE DATA WE NEED FROM THE COMPANY PROFILES, CASH FLOW STATEMENTS, BALANCE SHEET, AND INCOME STATEMENT
"""
def read_company_profile(company):
file = open(f"{DATA_DIR}/company-profile-{company}.txt")
data = json.load(file)
price = float(data["profile"]["price"])
file.close()
return {"price": price}
"""
def read_company_profile(company):
file = open(f"{DATA_DIR}/company-profile-{company}.txt")
data = json.load(file)
sector = str(data["profile"]["sector"])
price = float(data["profile"]["price"])
beta = float(data["profile"]["beta"])
file.close()
return {"price": price, "sector": sector, "beta": beta}
def read_cash_flow(company, year_start, year_end):
file = open(f"{DATA_DIR}/cash-flow-{company}.txt")
data = json.load(file)
cash_flow = {}
for ent in data["financials"]:
y = int(ent["date"][0:4])
if year_start < y <= year_end:
cash_flow[y] = {
"dna": float(ent["Depreciation & Amortization"]),
"capex": float(ent["Capital Expenditure"]),
}
file.close()
return cash_flow
def read_balance_sheet(company, year_start, year_end):
file = open(f"{DATA_DIR}/balance-sheet-{company}.txt")
data = json.load(file)
balance_sheet = {}
for ent in data["financials"]:
y = int(ent["date"][0:4])
if year_start < y <= year_end:
balance_sheet[y] = {
"cash": float(ent["Cash and cash equivalents"]),
"ar": float(ent["Receivables"]),
"inv": float(ent["Inventories"]),
"ap": float(ent["Payables"]),
"debt": float(ent["Total debt"]),
}
file.close()
return balance_sheet
def read_income_statement(company, year_start, year_end):
file = open(f"{DATA_DIR}/income-statement-{company}.txt")
data = json.load(file)
income_statement = {}
for ent in data["financials"]:
y = int(ent["date"][0:4])
if year_start < y <= year_end:
income_statement[y] = {
"rv": float(ent["Revenue"]),
"rvgr": float(ent["Revenue Growth"]),
"ebit%": float(ent["EBIT Margin"]),
"shares": float(ent["Weighted Average Shs Out"])
}
file.close()
return income_statement