Advertisement
acclivity

pyPortfolioValuation-Sample

Dec 17th, 2021
1,891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. # Portfolio Valuation Sample Script
  2. # Mike Kerry
  3.  
  4. market = {"TSLA": 662, "GOOG": 2053, "AAPL": 152, "FB": 291, "NFLX": 535, "BTC": 24000}
  5. market21 = {"TSLA": 985, "GOOG": 2965, "AAPL": 180, "FB": 340, "NFLX": 595, "BTC": 48000}
  6.  
  7. positions = {"FB": 15, "GOOG": 5, "TSLA": 9, "AAPL": 45, "NFLX": 12, "BTC": 0.1}
  8.  
  9. newdict = {}
  10.  
  11. totval1 = 0
  12. totval2 = 0
  13. print("\n Stock      Position   Unit Price   Valuation      % of     Unit Price    \
  14. Valuation      % of     Appreciation %")
  15. print(" Code                     2020        2020      Portfolio      2021         \
  16. 2021      Portfolio       21/20 \n")
  17. for name, qty in positions.items():
  18.     p1 = market[name]
  19.     p2 = market21[name]
  20.     v1 = qty * p1
  21.     v2 = qty * p2
  22.     appr = (v2 - v1) * 100 / v1
  23.     totval1 += v1
  24.     totval2 += v2
  25.  
  26.     newdict[name] = (qty, p1, v1, 0.0, p2, v2, 0.0, appr, )
  27.  
  28. for name in newdict.keys():
  29.     qty, p1, v1, pc1, p2, v2, pc2, appr = newdict[name]
  30.     pc1 = v1 * 100 / totval1
  31.     pc2 = v2 * 100 / totval2
  32.     newdict[name] = (qty, p1, v1, pc1, p2, v2, pc2, appr)
  33.  
  34.     print(f" {name :6}  {qty : 9}   {p1 :9} {v1:12.0f}  {pc1 :9.0f} \
  35. {p2:12} {v2:12.0f} {pc2: 11.0f} {appr :15.2f}" )
  36.  
  37. print()
  38. print(f" TOTALS        {totval1 :28.0f}      {totval2 :31.0f}   \
  39. {(totval2 - totval1) * 100 / totval1: 25.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement