Advertisement
angelorcc

Untitled

Feb 19th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import pandas as pd
  2. from pandas_datareader import data as web
  3. import numpy as np
  4.  
  5. tickers={'stock':['AAPL', 'GOOGL', 'TSLA'], 'quantity': [50, 100,300]}
  6. df=pd.DataFrame(tickers)
  7. stock_prices=web.DataReader(['AAPL', 'GOOGL', 'TSLA'], data_source='yahoo', start='2017-01-01', end='2020-01-01')['Close']
  8. #add an empy column
  9.  
  10. #stock_prices["Ptf_Value"] = ""
  11. def ValuePortfolio():
  12.     stock_prices['Ptf_Value'] = 0
  13.     i=0
  14.     while i<= len(tickers):
  15.         stock = tickers['stock'][i]
  16.         quantity = tickers['quantity'][i]
  17.         stock_prices['Ptf_Value']  = stock_prices * quantity + stock_prices['Ptf_Value']
  18.         i = i+1
  19.        
  20. ValuePortfolio()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement