Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from pandas_datareader import data as web
- import numpy as np
- tickers={'stock':['AAPL', 'GOOGL', 'TSLA'], 'quantity': [50, 100,300]}
- df=pd.DataFrame(tickers)
- stock_prices=web.DataReader(['AAPL', 'GOOGL', 'TSLA'], data_source='yahoo', start='2017-01-01', end='2020-01-01')['Close']
- #add an empy column
- #stock_prices["Ptf_Value"] = ""
- def ValuePortfolio():
- stock_prices['Ptf_Value'] = 0
- i=0
- while i<= len(tickers):
- stock = tickers['stock'][i]
- quantity = tickers['quantity'][i]
- stock_prices['Ptf_Value'] = stock_prices * quantity + stock_prices['Ptf_Value']
- i = i+1
- ValuePortfolio()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement