def __init__(self, symbol, **kwargs): super(EditModal, self).__init__(**kwargs) ids = self.ids ids.symbol.text = symbol self.editor = StockEditor() stocks, crypto = self.editor.list_stocks() stock = [stock for stock in stocks if symbol in stock] crypt = [stock for stock in crypto if symbol in stock] edit = Button(text='Edit') edit.id = 'edit' edit.bind(on_press=self.on_press) delete = Button(text='Delete') delete.id = 'delete' delete.bind(on_press=self.on_press) add = Button(text='Add') add.id = 'add' add.bind(on_press=self.on_press) if bool(stock): ids.price.text = str(stock[0][2]) ids.quantity.text = str(stock[0][1]) self.ids.modal.add_widget(edit) self.ids.modal.add_widget(delete) elif bool(crypt): ids.price.text = str(crypt[0][2]) ids.quantity.text = str(crypt[0][1]) ids.crypto.active = True self.ids.modal.add_widget(edit) self.ids.modal.add_widget(delete) else: ids.modal.add_widget(add) self.open()
class EditModal(ModalView): """ Modal to add and edit stock positions TODO: update adjusted cost basis of stocks with new purchase """ def __init__(self, symbol, **kwargs): super(EditModal, self).__init__(**kwargs) ids = self.ids ids.symbol.text = symbol self.editor = StockEditor() stocks, crypto = self.editor.list_stocks() stock = [stock for stock in stocks if symbol in stock] crypt = [stock for stock in crypto if symbol in stock] edit = Button(text='Edit') edit.id = 'edit' edit.bind(on_press=self.on_press) delete = Button(text='Delete') delete.id = 'delete' delete.bind(on_press=self.on_press) add = Button(text='Add') add.id = 'add' add.bind(on_press=self.on_press) if bool(stock): ids.price.text = str(stock[0][2]) ids.quantity.text = str(stock[0][1]) self.ids.modal.add_widget(edit) self.ids.modal.add_widget(delete) elif bool(crypt): ids.price.text = str(crypt[0][2]) ids.quantity.text = str(crypt[0][1]) ids.crypto.active = True self.ids.modal.add_widget(edit) self.ids.modal.add_widget(delete) else: ids.modal.add_widget(add) self.open() def on_press(self, instance): """ :param instance: action id from button (add / delete / edit) :return: None """ action = instance.id ids = self.ids crypto = ids.crypto.active symbol = ids.symbol.text.upper() quantity = float(ids.quantity.text) price = float(ids.price.text) table = 'Crypto' if crypto else 'Stocks' action_string = '_stock("{}", "{}", "{}", "{}")'.format( table, symbol, quantity, price) eval('self.editor.' + action + action_string) self.editor.close() self.dismiss()
def on_press(self): """ TODO: Volume? another graph? remove to make graph larger? currently prints the :return: """ stocks, crypto = StockEditor().list_stocks() print(DisplayGraphs().total_val())
def __init__(self, **kwargs): """ scrollable list view of crypto to display (crypto, quantity, price) :param kwargs: """ super(Crypto, self).__init__(**kwargs) stocks, crypto = StockEditor().list_stocks() self.data = [{ 'id': stock[0], 'quantity': str(stock[1]), 'price': str(stock[2]), 'table': 'Crypto' } for stock in crypto]
def stock_grabber(): """ Take list of stocks and retrieve stock data using P DataReader, save as a .pkl file :return: None """ stocks, crypto = StockEditor().list_stocks() stock_list = [stock[0] for stock in stocks] crypto_list = [crypt[0] for crypt in crypto] start = date(2020, 1, 1) end = date.today() if not os.path.join('data/stock.pkl'): stock_ticker = Data(stock_list, 'yahoo', start, end) stock_pickle = add_adj_value(stock_ticker) crypto_ticker = Data(crypto_list, 'yahoo', start, end) stock_pickle.to_pickle(os.path.join('data/stock.pkl')) crypto_pickle = add_adj_value(crypto_ticker) crypto_pickle.to_pickle(os.path.join('data/crypto.pkl'))
def add_adj_value(data): """ Add column Adj Val (Adj Close * # of Stock) to stock data :param data: results from pandas data reader (Pandas Dataframe) :return: results from PDR + Adj Val Column (Pandas Dataframe) """ pickle = data.copy() adj_close = pickle['Adj Close'] # get list of stocks [(symbol, quantity, price), ...] stocks, crypto = StockEditor().list_stocks() if stocks[0][0] in adj_close: data_list = stocks elif crypto[0][0] in adj_close: data_list = crypto else: print('Stock ticker not available') adj_val = pandas.DataFrame() for i, stock in enumerate(data_list): adj_val.insert(loc=i, column=('Adj Val', stock[0]), value=adj_close[stock[0]] * stock[1]) pickle = pickle.merge(adj_val, on='Date') return pickle
def __init__(self): self.stock_pickle = pd.read_pickle(os.path.join('data/stock.pkl')) self.crypto_pickle = pd.read_pickle(os.path.join('data/crypto.pkl')) self.stock_list, self.crypto_list = StockEditor().list_stocks()