Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Portfolio Valuation Sample Script
- # Mike Kerry
- market = {"TSLA": 662, "GOOG": 2053, "AAPL": 152, "FB": 291, "NFLX": 535, "BTC": 24000}
- market21 = {"TSLA": 985, "GOOG": 2965, "AAPL": 180, "FB": 340, "NFLX": 595, "BTC": 48000}
- positions = {"FB": 15, "GOOG": 5, "TSLA": 9, "AAPL": 45, "NFLX": 12, "BTC": 0.1}
- newdict = {}
- totval1 = 0
- totval2 = 0
- print("\n Stock Position Unit Price Valuation % of Unit Price \
- Valuation % of Appreciation %")
- print(" Code 2020 2020 Portfolio 2021 \
- 2021 Portfolio 21/20 \n")
- for name, qty in positions.items():
- p1 = market[name]
- p2 = market21[name]
- v1 = qty * p1
- v2 = qty * p2
- appr = (v2 - v1) * 100 / v1
- totval1 += v1
- totval2 += v2
- newdict[name] = (qty, p1, v1, 0.0, p2, v2, 0.0, appr, )
- for name in newdict.keys():
- qty, p1, v1, pc1, p2, v2, pc2, appr = newdict[name]
- pc1 = v1 * 100 / totval1
- pc2 = v2 * 100 / totval2
- newdict[name] = (qty, p1, v1, pc1, p2, v2, pc2, appr)
- print(f" {name :6} {qty : 9} {p1 :9} {v1:12.0f} {pc1 :9.0f} \
- {p2:12} {v2:12.0f} {pc2: 11.0f} {appr :15.2f}" )
- print()
- print(f" TOTALS {totval1 :28.0f} {totval2 :31.0f} \
- {(totval2 - totval1) * 100 / totval1: 25.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement