CA6 UTSAV
CA6 UTSAV
In this project I had to manage ,Rs.50,000million funds after selecting stocks from
500 companies listed on BSE.After collecting the data I found the expected returns
and and the variance . The primary was to construct the optimal portfolio that
maximises return while keeping the portfolio risk within acceptable limits.The
project uses linear programming for optimisation ensuring constraints like stock
allocation limits .
PROJECT OBJECTIVE :
The key objective of the project is to create a portfolio that:
• Maximizes the expected return on the fund.
• Limits the allocation of any stock to a maximum of 2% of the total portfolio.
• Ensures that the portfolio variance does not exceed 1.
where r_i is the expected return of stock i , and x_i is the proportion invested in
stock i .
• Constraints:
• Total investment should sum to the full fund:
\sum_{i=1}^{n} x_i = 1
SOFTWARE USED :
First I have collected the datas of all the 500 companies from , YFINANCE in
PYTHON .After getting the data I I have converted the excel sheet in .CSV format
to run the programme in PYTHON.Panda also helped me a lot in transferring the
final output back to excel for further analysis . CVXPY was employed to calculate
the optimal values by formulating and solving the linear programming problem. This
involved defining the objective function, constraints, and running the optimisation to
find the best possible portfolio allocation.
1.EXCEL
2.YFINANCE
3.TERMINAL
4.CVXPY
5.PYTHON
import numpy as np
import cvxpy as cp
file_path = "/Users/utsav/Desktop/500_stocks_portfolio_dataa
2..csv" # Update this path to where your CSV file is located
data = pd.read_csv(file_path)
# Number of stocks
n = len(company_names)
# Define variables
x = cp.Variable(n)
objective = cp.Maximize(expected_returns @ x)
# Constraints
constraints = [
problem.solve()
optimal_weights = x.value
# Combine the results into a DataFrame for
easy viewing
result = pd.DataFrame({
'Company': company_names,
'Optimal Allocation':
optimal_weights
})
result = result.sort_values(by='Optimal
Allocation',
ascending=False).reset_index(drop=True)
EXCEL was used to only for the data so that I can run the programme in the .CSV
extension file.
RESULTS
EXPECTED RETURN : The expected return of the optimised portfolio is 7.395%.
VARIANCE : The variance of the portfolio is below 1 , ensuring it meets the
risk constraint.
CONCLUSION :
After running the portfolio optimization model using Python (with libraries like
yfinance for stock data retrieval and Excel for analysis), we achieved a
diversified stock portfolio of BSE 500 companies. The model was constrained
by a 2% maximum allocation per stock and aimed to maximize average
returns while keeping the portfolio variance below 1.
The use of Python and the yfinance library facilitated the automated download
of stock price data, which was used to compute expected returns, variances,
and covariances between stocks. These metrics were crucial to calculating the
portfolio’s overall risk (variance) and ensuring that it remained within the
defined risk threshold. Bibliographic software :
1.chatgpt
2.bse500
3.terminal
4.cvapy