- store stocks in JSON file
- use convenient command line params git-svn-id: http://moon:8086/svn/projects/Stock@348 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -11,17 +11,17 @@
|
|||||||
# https://www.investopedia.com/articles/technical/02/050602.asp
|
# https://www.investopedia.com/articles/technical/02/050602.asp
|
||||||
# https://ntguardian.wordpress.com/2016/09/19/introduction-stock-market-data-python-1
|
# https://ntguardian.wordpress.com/2016/09/19/introduction-stock-market-data-python-1
|
||||||
|
|
||||||
do_plot = 1
|
|
||||||
|
|
||||||
if do_plot:
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib as mpl
|
import matplotlib as mpl
|
||||||
mpl.rc('figure', max_open_warning = 0)
|
mpl.rc('figure', max_open_warning = 0)
|
||||||
|
|
||||||
from stock import Stock
|
from stock import Stock
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'show_range_days' : 10,
|
'analyze_range_days' : 5,
|
||||||
|
'plot_range_days' : 0,
|
||||||
'btfd' : {'thresh_max' : -7, 'thresh_min' : 1, 'cand_window' : 5},
|
'btfd' : {'thresh_max' : -7, 'thresh_min' : 1, 'cand_window' : 5},
|
||||||
'k_euro' : 1 / 1.11,
|
'k_euro' : 1 / 1.11,
|
||||||
'ema_alpha' : 0.75,
|
'ema_alpha' : 0.75,
|
||||||
@@ -30,108 +30,38 @@ params = {
|
|||||||
'fetch_on_outdated' : True
|
'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 = ['PCELF']
|
|
||||||
#show_symbols = ['OHB.DE']
|
|
||||||
#show_symbols = ['UBSFF']
|
|
||||||
#show_symbols = ['DHER.DE']
|
|
||||||
#show_symbols = ['WDI.DE']
|
|
||||||
#show_symbols = ['EVT.DE']
|
|
||||||
show_symbols = []
|
show_symbols = []
|
||||||
|
|
||||||
symbols = {
|
parser = argparse.ArgumentParser()
|
||||||
'KEP' : {'name' : 'Korea Electric Power Corporation', 'currency' : '$'},
|
parser.add_argument('--symbol', help='Symbol to fetch')
|
||||||
'MRK.DE' : {'name' : 'Merck', 'currency' : '€'},
|
parser.add_argument('--analyze-range', type=int, help='Analyze window [days]')
|
||||||
'TOM.F' : {'name' : 'Toyota Motor Corporation', 'currency' : '€'},
|
parser.add_argument('--plot-range', type=int, help='Plot range [days]')
|
||||||
'SSHPF' : {'name' : 'Scanship Holding ASA', 'currency' : '$'},
|
|
||||||
'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' : '$'}}
|
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
f = open('stocks.json', 'r')
|
||||||
|
s = f.read()
|
||||||
|
symbols = json.loads(s)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
if args.symbol is not None:
|
||||||
|
show_symbols = [args.symbol]
|
||||||
|
if args.symbol not in symbols:
|
||||||
|
symbols[args.symbol] = {'name' : 'Full name here', 'currency' : '$'}
|
||||||
|
s = json.dumps(symbols, sort_keys=True, indent=4)
|
||||||
|
f = open('stocks.json', 'w')
|
||||||
|
f.write(s)
|
||||||
|
f.close()
|
||||||
|
else:
|
||||||
|
print ("{} is already in database".format(args.symbol))
|
||||||
|
|
||||||
|
if args.analyze_range is not None:
|
||||||
|
params['analyze_range_days'] = args.analyze_range
|
||||||
|
|
||||||
|
if args.plot_range is not None:
|
||||||
|
params['plot_range_days'] = args.plot_range
|
||||||
|
|
||||||
|
do_plot = params['plot_range_days'] > 0
|
||||||
buy_list = {}
|
buy_list = {}
|
||||||
def buy_callback(data):
|
def buy_callback(data):
|
||||||
name = data['name']
|
name = data['name']
|
||||||
@@ -151,7 +81,7 @@ if len(show_symbols) > 0:
|
|||||||
title.fetch()
|
title.fetch()
|
||||||
title.statistics()
|
title.statistics()
|
||||||
try:
|
try:
|
||||||
ind = title.analyze(buy_callback, range_days=params['show_range_days'])
|
ind = title.analyze(buy_callback, range_days=params['analyze_range_days'])
|
||||||
if do_plot:
|
if do_plot:
|
||||||
title.show(ind, figNum=figNum)
|
title.show(ind, figNum=figNum)
|
||||||
figNum += 1
|
figNum += 1
|
||||||
@@ -164,7 +94,7 @@ else:
|
|||||||
title.fetch()
|
title.fetch()
|
||||||
title.statistics()
|
title.statistics()
|
||||||
try:
|
try:
|
||||||
ind = title.analyze(buy_callback, range_days=params['show_range_days'])
|
ind = title.analyze(buy_callback, range_days=params['analyze_range_days'])
|
||||||
if Stock.has_candidate(ind, 'BTFD'):
|
if Stock.has_candidate(ind, 'BTFD'):
|
||||||
print('-----------------------------------------------')
|
print('-----------------------------------------------')
|
||||||
if do_plot:
|
if do_plot:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class Stock(object):
|
|||||||
self.fig = None
|
self.fig = None
|
||||||
self.currency = symbol_params['currency']
|
self.currency = symbol_params['currency']
|
||||||
self.currency_corr = 1
|
self.currency_corr = 1
|
||||||
if '$' in self.currency:
|
if 'USD' in self.currency:
|
||||||
self.currency_corr = self.params['k_euro']
|
self.currency_corr = self.params['k_euro']
|
||||||
|
|
||||||
self.data = {}
|
self.data = {}
|
||||||
@@ -135,7 +135,7 @@ class Stock(object):
|
|||||||
def __plot(self, id, data, keys):
|
def __plot(self, id, data, keys):
|
||||||
ax = plt.subplot(id)
|
ax = plt.subplot(id)
|
||||||
N = len(data['index'])
|
N = len(data['index'])
|
||||||
start = max(0, N - self.params['show_range_days'])
|
start = max(0, N - self.params['plot_range_days'])
|
||||||
stop = N
|
stop = N
|
||||||
xr = list(range(start, stop))
|
xr = list(range(start, stop))
|
||||||
sliced = Stock.slice(data, start, stop)
|
sliced = Stock.slice(data, start, stop)
|
||||||
@@ -153,7 +153,7 @@ class Stock(object):
|
|||||||
|
|
||||||
def __ind(self, data, keys):
|
def __ind(self, data, keys):
|
||||||
N = len(data['index'])
|
N = len(data['index'])
|
||||||
start = max(0, N - self.params['show_range_days'])
|
start = max(0, N - self.params['plot_range_days'])
|
||||||
stop = N
|
stop = N
|
||||||
xr = list(range(start, stop))
|
xr = list(range(start, stop))
|
||||||
sliced = Stock.slice(data, start, stop)
|
sliced = Stock.slice(data, start, stop)
|
||||||
|
|||||||
Reference in New Issue
Block a user