-
Notifications
You must be signed in to change notification settings - Fork 2
/
getMarketPrice.py
executable file
·64 lines (48 loc) · 1.63 KB
/
getMarketPrice.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
#!/usr/bin/env python
import numpy as np
from tools import financialAnalysisTools as fa
import matplotlib.pyplot as plt
import pandas as pd
from_file = True
df = None
############################ Portfolio ###################################
valueStocks = {
'BIDU': 1,
'AAPL': 1,
'AMD': 1,
'PYPL': 1,
'HD': 1,
}
dividendStocks = {
}
ETFStocks = {
}
if from_file:
df = pd.read_csv('my_portfolio.csv', sep=',', names=['stocks'])
############################ //Portfolio// ###################################
if __name__ == '__main__':
if df is None:
stock_types = {'Value Stocks': valueStocks, 'Dividend Stocks': dividendStocks, 'ETF Stocks': ETFStocks}
total_value = 0
for stock_type, stocks in stock_types.items():
type_value = 0
print ("\n")
for stock, amt in stocks.items():
price, currency = fa.getMarketPrice(stock)
try:
type_value += price*amt
total_value += price*amt
print (" {s}: ${v} CAD (${p} {c} ea.)".format(s=stock, v=price*amt, p=price, c=currency))
except:
print (" {s}: Could not acquire price!".format(s=stock))
print (" {s}: ${p} CAD".format(s=stock_type, p=type_value))
print ("Total Value: ${} CAD".format(total_value))
else:
for i, stocks in df.iterrows():
stk = stocks.values[0]
price, currency = fa.getMarketPrice(stk, False)
if price is not None:
df.at[i,'price'] = price
df.at[i,'currency'] = currency
print df
df.to_csv('my_portfolio_updated.csv',sep=',', index=False)