-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtradingSystem.py
More file actions
43 lines (42 loc) · 1.42 KB
/
tradingSystem.py
File metadata and controls
43 lines (42 loc) · 1.42 KB
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
import numpy as np
import pandas as pd
import MySQLdb as mdb
'''
def availableStockMarket():
# Open database connection
db = mdb.connect("localhost","sec_user", "password","securities_master")
# Prepare a cursor object using cursor() method
cursor = db.cursor()
'''
class Portfolio():
cash = 100000.0
equity = 0.0
def __init__(self):
self.stocks = {}
def buyStock(self, stock_symbol, stock_amount):
price = stockMarket.get_price(stock_symbol)
if price * stock_amount < self.cash:
self.stocks[stock_symbol] = stock_amount
else:
print "YOU DO NOT HAVE ENOUGH MONEY!"
def sellStock(self, stock_symbol, stock_amount):
price = stockMarket.get_price(stock_symbol)
if stock_symbol in self.stocks:
self.cash = self.cash + price * stock_amount
updated_stock_amount = self.stocks[stock_symbol] - stock_amount
if updated_stock_amount == 0:
del self.stocks[stock_symbol]
else:
self.stocks[stock_symbol] = updated_stock_amount
else:
print "YOU HAVE NO POSITION IN THIS STOCK!"
'''
def currentPortfolio(self):
print 'The total cash is: ', self.cash
print 'The stocks in your portfolio are: '
for item in self.stocks.items():
print item[0], ": ", item[1]
return 0
'''
p = Portfolio()
p.