Lets evaluate portfolios and their benchmarks, with documentation and manual calculations to illustrate all underlying statistics.
import numpy as np
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
import pandas as pd
Lets create a dictionary with sercurity ticker and associated count. This is a sample set, it doesn't reflect actual investment.
securities={
"APOLLOTYRE.NS":500,
"ASHOKLEY.NS":300,
"BHARATFORG.NS":400,
"BHARTIARTL.NS":200,
"BIOCON.NS":1000,
"CEATLTD.NS":100,
"EMAMILTD.NS":220,
"GRASIM.NS":380,
"GUJGASLTD.NS":500,
"HDFCBANK.NS":1020,
"HINDUNILVR.NS":100,
"ICICIBANK.NS":450,
"IDEA.NS":200,
"YESBANK.NS": 120,
"BHEL.NS": 230,
"UVSL.NS": 130,
"PNB.NS": 330,
}
Yahoo Finance is a media platform that provides financial news, data about stock quotes, press releases, and financial reports. And all the data provided by Yahoo Finance is free. Yahoo Finance API is the API that Yahoo provides to fetch financial information.
adjusted_closing=pd.DataFrame()
for security in securities.keys():
adjusted_closing[security]=wb.DataReader(security, data_source='yahoo', start='2010-1-1')['Adj Close']
adjusted_closing.tail()
APOLLOTYRE.NS | ASHOKLEY.NS | BHARATFORG.NS | BHARTIARTL.NS | BIOCON.NS | CEATLTD.NS | EMAMILTD.NS | GRASIM.NS | GUJGASLTD.NS | HDFCBANK.NS | HINDUNILVR.NS | ICICIBANK.NS | IDEA.NS | YESBANK.NS | BHEL.NS | UVSL.NS | PNB.NS | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Date | |||||||||||||||||
2020-12-28 | 177.699997 | 95.300003 | 527.799988 | 521.599976 | 465.799988 | 1064.300049 | 421.500000 | 906.650024 | 375.100006 | 1412.849976 | 2388.899902 | 520.099976 | 10.40 | 17.799999 | 35.250000 | NaN | 32.400002 |
2020-12-29 | 180.750000 | 95.000000 | 523.450012 | 520.250000 | 460.500000 | 1070.400024 | 423.149994 | 909.500000 | 380.750000 | 1427.199951 | 2384.300049 | 528.799988 | 10.30 | 17.750000 | 35.400002 | NaN | 33.200001 |
2020-12-30 | 179.899994 | 94.800003 | 517.599976 | 516.150024 | 458.700012 | 1071.500000 | 423.450012 | 934.400024 | 382.200012 | 1432.500000 | 2406.600098 | 528.750000 | 10.20 | 17.750000 | 35.400002 | NaN | 32.750000 |
2020-12-31 | 178.000000 | 95.449997 | 525.299988 | 509.700012 | 465.399994 | 1080.949951 | 423.750000 | 927.849976 | 376.399994 | 1436.300049 | 2395.399902 | 535.049988 | 10.65 | 17.850000 | 35.900002 | NaN | 33.049999 |
2021-01-01 | 179.899994 | 99.099998 | 538.099976 | 515.150024 | 465.750000 | 1093.449951 | 423.700012 | 933.400024 | 378.000000 | 1425.050049 | 2387.550049 | 527.500000 | 11.20 | 18.000000 | 38.700001 | NaN | 34.799999 |
adjusted_closing.iloc[-1]
APOLLOTYRE.NS 179.899994 ASHOKLEY.NS 99.099998 BHARATFORG.NS 538.099976 BHARTIARTL.NS 515.150024 BIOCON.NS 465.750000 CEATLTD.NS 1093.449951 EMAMILTD.NS 423.700012 GRASIM.NS 933.400024 GUJGASLTD.NS 378.000000 HDFCBANK.NS 1425.050049 HINDUNILVR.NS 2387.550049 ICICIBANK.NS 527.500000 IDEA.NS 11.200000 YESBANK.NS 18.000000 BHEL.NS 38.700001 UVSL.NS NaN PNB.NS 34.799999 Name: 2021-01-01 00:00:00, dtype: float64
(adjusted_closing/adjusted_closing.iloc[0]*100).plot(figsize=(20,15))
<AxesSubplot:xlabel='Date'>