0% found this document useful (0 votes)
4 views

CA6 UTSAV

hhhhhhuhhuh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CA6 UTSAV

hhhhhhuhhuh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Name - UTSAV RANJAN

Roll no.- 23BA069 Section


-A

PORTFOLIO REPORT USING


LINEAR PROGRAMMING
BACKGROUND OF THE REPORT :

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.

FORMULATING LNEAR PROGRAMING PROBLEM :

• The objective is to maximize the expected return on the portfolio. Suppose


x_i represents the proportion of the fund invested in stock i . The expected
return of the portfolio is: \text{Maximize: } \sum_{i=1}^{n} x_i r_i

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

• No stock can make up more than 2% of the total portfolio:


x_i \leq 0.02 \quad \text{for all } i

• The portfolio variance (risk) should not exceed 1: \sum_{i=1}^{n}

\sum_{j=1}^{n} x_i x_j \sigma_{ij} \leq 1 where \sigma_{ij} represents the

covariance between stock i and stock j .

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

COMMANDS USED IN SOFTWARE :


import pandas as pd

import numpy as np

import cvxpy as cp

# Load your data

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)

# Extract the relevant columns

company_names = data.iloc[:, 0] # Company names (first


column)
expected_returns = data.iloc[:, 1].to_numpy() # Average
returns (second column)

variances = data.iloc[:, 2].to_numpy() # Variances (third


column)

# Number of stocks

n = len(company_names)
# Define variables
x = cp.Variable(n)

# Objective function: maximize total expected return

objective = cp.Maximize(expected_returns @ x)

# Constraints

constraints = [

cp.sum(x) == 1, # The sum of weights should be 1

x >= 0, # No negative investments

x <= 0.02, # No more than 2% in any stock

cp.quad_form(x, np.diag(variances)) <= 1 # Variance


constraint (diagonal covariance matrix)

# Formulate the optimization problem


problem = cp.Problem(objective,
constraints)
# Solve the problem

problem.solve()

# Retrieve the optimal weights

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.

STOCK ALLOCATION : The optimised portfolio allocations, generated


through Python, have been meticulously calculated and saved in an Excel
file. Each stock has been strategically assigned a specific proportion of the
total Rs 50,000 million fund, with a strict adherence to the 2% cap per stock,
ensuring a balanced and efficient investment strategy.

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

Name - UTSAV RANJAN


Roll no.- 23BA069
Section - A

You might also like