git-svn-id: http://moon:8086/svn/projects/Stock@328 fda53097-d464-4ada-af97-ba876c37ca34
174 lines
6.7 KiB
Python
174 lines
6.7 KiB
Python
# Stock Investors Financial Math
|
|
# https://www.fmlabs.com/reference/default.htm?url=SimpleMA.htm
|
|
|
|
# Alpha Vantage
|
|
# https://www.alphavantage.co/documentation/
|
|
|
|
# Pandas
|
|
# https://pandas.pydata.org/pandas-docs/stable/index.html
|
|
|
|
# Knowledge
|
|
# https://www.investopedia.com/articles/technical/02/050602.asp
|
|
# https://ntguardian.wordpress.com/2016/09/19/introduction-stock-market-data-python-1
|
|
|
|
import matplotlib.pyplot as plt
|
|
from stock import Stock
|
|
|
|
key = '0UO7Z2MVZ2YSQSVE'
|
|
params = {
|
|
'show_range_days' : 5,
|
|
'k_euro' : 1 / 1.11,
|
|
'ema_alpha' : 0.75,
|
|
'sma_days' : 10,
|
|
'q_days' : 10,
|
|
'fetch_on_outdated' : True
|
|
}
|
|
|
|
show_symbols = ['OHB.DE', 'ITMPF', 'PLUG', 'MOR.DE', 'CSCO', 'ERCA.DE', 'AVGO', 'DIS', 'UBSFF', 'DHER.DE', 'AIR']
|
|
show_symbols = ['CSCO']
|
|
#show_symbols = ['OHB.DE']
|
|
#show_symbols = ['UBSFF']
|
|
show_symbols = ['DHER.DE']
|
|
#show_symbols = ['WDI.DE']
|
|
#show_symbols = ['EVT.DE']
|
|
show_symbols = []
|
|
|
|
symbols = {
|
|
|
|
'RIG' : {'name' : 'Transocean Ltd.', 'currency' : '$'},
|
|
'BBIO' : {'name' : 'BridgeBio Pharma, Inc.', 'currency' : '$'},
|
|
'APA' : {'name' : 'Apache Corporation', 'currency' : '$'},
|
|
'CBB-PB' : {'name' : 'Cincinnati Bell Inc.', 'currency' : '$'},
|
|
'NMHLY' : {'name' : 'NMC Health Plc', 'currency' : '$'},
|
|
'PINS' : {'name' : 'Pinterest', 'currency' : '$'},
|
|
'TSLA' : {'name' : 'Tesla Inc.', 'currency' : '$'},
|
|
'ACB' : {'name' : 'Aurora Cannabis Inc.', 'currency' : '$'},
|
|
'ITCI' : {'name' : 'Intra-Cellular Therapies', 'currency' : '$'},
|
|
'WDI.DE' : {'name' : 'WireCard', 'currency' : '€'},
|
|
'AAPL' : {'name' : 'Apple', 'currency' : '$'},
|
|
'XLNX' : {'name' : 'Xilinx', 'currency' : '$'},
|
|
'QCOM' : {'name' : 'Qualcomm', 'currency' : '$'},
|
|
'DPW.DE' : {'name' : 'Deutsche Post', 'currency' : '€'},
|
|
'CSCO' : {'name' : 'Cisco', 'currency' : '$'},
|
|
'AIR' : {'name' : 'Airbus', 'currency' : '$'},
|
|
'BA' : {'name' : 'Boeing', 'currency' : '$'},
|
|
'NVDA' : {'name' : 'Nvidia', 'currency' : '$'},
|
|
'MSFT' : {'name' : 'Microsoft', 'currency' : '$'},
|
|
'DIS' : {'name' : 'Disney', 'currency' : '$'},
|
|
'NFLX' : {'name' : 'Netflix', 'currency' : '$'},
|
|
'OHB.DE' : {'name' : 'OHB', 'currency' : '€'},
|
|
'ERCA.DE' : {'name' : 'Ericsson', 'currency' : '€'},
|
|
'VAR1.DE' : {'name' : 'Varta', 'currency' : '€'},
|
|
'HD' : {'name' : 'Home Depot', 'currency' : '$'},
|
|
'AMZN' : {'name' : 'Amazon', 'currency' : '$'},
|
|
'GOOGL' : {'name' : 'Google', 'currency' : '$'},
|
|
'FB2A.DE' : {'name': 'Facebook Inc.', 'currency' : '€'},
|
|
'ZIL2.DE' : {'name': 'ElringKlinger', 'currency' : '€'},
|
|
'SIS.DE' : {'name': 'First Sensor', 'currency' : '€'},
|
|
'SIE.DE' : {'name': 'Siemens', 'currency' : '€'},
|
|
'GFT.DE' : {'name': 'GFT Technologies', 'currency' : '€'},
|
|
'AMD.DE' : {'name': 'Advanced Micro Devices', 'currency' : '€'},
|
|
'CAP.DE' : {'name': 'Encavis', 'currency' : '€'},
|
|
'ADBE' : {'name': 'Adobe', 'currency' : '$'},
|
|
'PANW' : {'name': 'Palo Alto Networks', 'currency' : '$'},
|
|
'AMAT' : {'name': 'Applied Materials', 'currency' : '$'},
|
|
'RIB.DE' : {'name': 'RIB Software', 'currency' : '€'},
|
|
'WAF.DE' : {'name': 'Siltronic', 'currency' : '€'},
|
|
'EVT.DE' : {'name': 'Evotec', 'currency' : '€'},
|
|
'VOW.DE' : {'name': 'Volkswagen', 'currency' : '€'},
|
|
'BMW.DE' : {'name': 'BMW', 'currency' : '€'},
|
|
'NSU.DE' : {'name': 'Audi', 'currency' : '€'},
|
|
'DAI.DE' : {'name': 'Daimler', 'currency' : '€'},
|
|
'SHA.DE' : {'name': 'Schaeffler', 'currency' : '€'},
|
|
'CON.DE' : {'name': 'Continental', 'currency' : '€'},
|
|
'DHER.DE' : {'name': 'Delivery Hero', 'currency' : '€'},
|
|
'BSL.DE' : {'name': 'Basler', 'currency' : '€'},
|
|
'D6H.DE' : {'name': 'DATAGROUP', 'currency' : '€'},
|
|
'TC1.DE' : {'name': 'Tele Columbus', 'currency' : '€'},
|
|
'VODI.DE' : {'name': 'Vodaphone Group', 'currency' : '€'},
|
|
'ATVI' : {'name': 'Activision Blizzard', 'currency' : '$'},
|
|
'GME' : {'name': 'GameStop', 'currency' : '$'},
|
|
'NTO.F' : {'name': 'Nintendo', 'currency' : '$'},
|
|
'UBSFF' : {'name': 'UBI Soft', 'currency' : '$'},
|
|
'NXPRF' : {'name': 'Nexans', 'currency' : '$'},
|
|
# 'IMPUF' : {'name': 'Impala Platinum Holdings', 'currency' : '$'},
|
|
'NMPNF' : {'name': 'Northam Platinum', 'currency' : '$'},
|
|
'ALSMY' : {'name': 'Alstom', 'currency' : '$'},
|
|
'ARRD.F' : {'name': 'Arcelor Mittal', 'currency' : '$'},
|
|
'PHG' : {'name': 'Philips', 'currency' : '$'},
|
|
'KEYS' : {'name': 'KeySight', 'currency' : '$'},
|
|
'ORCL' : {'name': 'Oracle', 'currency' : '$'},
|
|
'UBER' : {'name': 'Uber', 'currency' : '$'},
|
|
'VMW' : {'name': 'VMWare', 'currency' : '$'},
|
|
'AVGO' : {'name' : 'Avago', 'currency' : '$'},
|
|
'CY' : {'name': 'Cypress Semiconductor', 'currency' : '$'},
|
|
'QABSY' : {'name': 'Qanta Airways', 'currency' : '$'},
|
|
'BLDP' : {'name': 'Ballard Power', 'currency' : '$'},
|
|
'D7G.F' : {'name': 'Nel ASA', 'currency' : '$'},
|
|
'ITMPF' : {'name': 'ITM Power', 'currency' : '$'},
|
|
'PLUG' : {'name': 'PlugPower', 'currency' : '$'},
|
|
'PCELF' : {'name': 'PowerCell', 'currency' : '$'},
|
|
'SU.PA' : {'name': 'Schneider Electric', 'currency' : '$'},
|
|
# 'SON1.DE' : {'name': '', 'currency' : '€'},
|
|
'STM.DE' : {'name': 'STM Micro', 'currency' : '€'},
|
|
'BC8.DE' : {'name': 'Bechtle', 'currency' : '€'},
|
|
'MOR.DE' : {'name' : 'Morphosys', 'currency' : '€'},
|
|
'BAYN.DE' : {'name' : 'Bayer', 'currency' : '€'},
|
|
'BEI.DE' : {'name' : 'Beiersdorf', 'currency' : '€'},
|
|
'EUZ.DE' : {'name': 'Eckert & Ziegler', 'currency' : '€'},
|
|
'SLAB' : {'name': 'Silicon Laboratories', 'currency' : '$'},
|
|
'SPLK' : {'name' : 'Splunk', 'currency' : '$'},
|
|
'IAG' : {'name' : 'IAG', 'currency' : '$'},
|
|
'INTC' : {'name' : 'Intel Corporation', 'currency' : '$'},
|
|
'I' : {'name': 'IntelSat', 'currency' : '$'}}
|
|
|
|
buy_list = {}
|
|
def buy_callback(data):
|
|
name = data['name']
|
|
item = data['item']
|
|
if name not in buy_list:
|
|
buy_list[name] = {'items': [item]}
|
|
else:
|
|
buy_list[name]['items'].append(item)
|
|
|
|
print(data)
|
|
|
|
figNum = 1
|
|
if len(show_symbols) > 0:
|
|
for symbol in show_symbols:
|
|
if symbol in symbols:
|
|
title = Stock(symbol, symbols[symbol])
|
|
title.fetch()
|
|
title.statistics()
|
|
ind = title.analyze(buy_callback, range_days=params['show_range_days'])
|
|
title.show(ind, figNum=figNum)
|
|
figNum += 1
|
|
else:
|
|
for symbol in symbols:
|
|
title = Stock(params, symbol, symbols[symbol])
|
|
title.fetch()
|
|
title.statistics()
|
|
ind = title.analyze(buy_callback, range_days=params['show_range_days'])
|
|
if Stock.has_candidate(ind, 'BTFD'):
|
|
print('-----------------------------------------------')
|
|
title.show(ind, figNum=figNum)
|
|
figNum += 1
|
|
|
|
gain_accum = 0
|
|
num_stocks = 0
|
|
for symbol in buy_list:
|
|
items = buy_list[symbol]['items']
|
|
title = Stock(params, symbol, symbols[symbol])
|
|
title.fetch()
|
|
title.statistics()
|
|
gain = title.get_latest('close_n') - items[0]['value']
|
|
gain_accum += gain
|
|
num_stocks += 1
|
|
print ('{}: Gain = {} %'.format(symbol, gain))
|
|
|
|
if num_stocks > 0:
|
|
print ('Gain total = {} %'.format(gain_accum/num_stocks))
|
|
|
|
plt.show()
|
|
|