0% found this document useful (0 votes)
16 views11 pages

Project Report

The document is a report on investment portfolio selection using dynamic programming, submitted by students Zalak Patel and Akshar Patel at G H Patel College of Engineering & Technology. It outlines a problem description involving the selection of stocks based on risk tolerance and budget, and presents a solution approach utilizing a dynamic programming method akin to the knapsack problem. The report includes a source code implementation for the stock selection algorithm and discusses the benefits of the 0/1 knapsack algorithm in maximizing investment returns.

Uploaded by

Zalak Patel
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)
16 views11 pages

Project Report

The document is a report on investment portfolio selection using dynamic programming, submitted by students Zalak Patel and Akshar Patel at G H Patel College of Engineering & Technology. It outlines a problem description involving the selection of stocks based on risk tolerance and budget, and presents a solution approach utilizing a dynamic programming method akin to the knapsack problem. The report includes a source code implementation for the stock selection algorithm and discusses the benefits of the 0/1 knapsack algorithm in maximizing investment returns.

Uploaded by

Zalak Patel
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/ 11

G H Patel College of Engineering & Technology

(A Constituent College of CVM University)


Bakrol, Vallabh Vidyanagar

INFORMATION TECHNOLOGY DEPARTMENT

Report on

INVESTMENT PORTFOLIO SELECTION USING


DYNAMIC PROGRAMMING

Submitted By

Name of Student : Zalak Patel


Akshar Patel
Enrollment Number : 12202110501068
12202110501069

Design & Analysis of Algorithms (202045601)


A.Y. 2024-25 ODD TERM
CERTIFICATE

This is to certify that Seminar work embodied in this report entitled, “ Portfolio
selection using dynamic Programming ” was carried out by Patel Zalak
(12202110501068) & Akshar Patel (1220211050169), at G H Patel College of
Engineering& Technology for partial fulfilment of B.Tech degree to be awarded by
Charutar Vidya Mandal University (CVMU). This seminar work has been carried out
under my supervision and is to the satisfaction of department.

Date:
Place: G H Patel College of Engineering & Technology
Problem Description:
Given a set of investment options (stocks) with associated returns, risks, and
prices, the task is to:

1. Select Stocks: Based on the user's risk tolerance (low, medium, high) and
budget, choose stocks to invest in.

2. Optimize Allocation: Allocate the available budget among the selected


stocks in a way that maximizes the expected returns. The budget can be
used fully and the selection should be based on the maximum profit.

3. Calculate Returns: Determine the future value of the investment over a


specified number of years and provide a detailed report of expected
returns.
Solution Approach:
1. Data Collection: Gather information on available stocks, including their
returns, risks, and prices.

2. Knapsack Problem (Dynamic Programming Approach):The main


objective is to select stocks that maximize profit within a given budget
and specific risk tolerance. The decision at each step is whether to include
or exclude the current stock based on its price, risk, and the remaining
budget.

3. Risk Handling:Based on the user-selected risk type (low, medium, or


high), different risk ranges (risk_min, risk_max) are applied. Only stocks
within the specified risk range are considered for inclusion in the final
selection.
4. Dynamic Programming Table (DP Table):dp[idx][budget] represents
the maximum profit achievable with the first idx stocks and a budget of
budget.

The two options for each stock are:

Include the current stock, reducing the available budget and adding its
profit.

Exclude the current stock, keeping the budget unchanged.

The maximum value between including and excluding is stored in the DP


table.

5. Reconstruction of Selected Stocks: Once the DP table is filled, the


selected stocks are identified by traversing the table backwards. If the
value at dp[idx][budget] is not the same as dp[idx-1][budget], it means
the current stock was included in the solution.
6. Main Function: The StockSelection function reads the input, initializes
the DP table, and calls the knapsack function to calculate the maximum
profit.The selected stocks are printed along with their names, showing the
optimal stock selection for the given budget and risk.
Benefits of the 0/1 Knapsack Algorithm:
1. Maximizing Flexibility
2. Improved Profit Maximization
3. Simplicity and Scalability
4. Better Use of Budget
Source Code:
#include

<bits/stdc++.h>using

namespace std;

int knapsack(int profit[], int risk[], int prices[], int budget, int risk_min, int
risk_max, int idx, vector<vector<int>> &dp){

if(idx==0 || budget == 0) return 0;

if (dp[idx][budget] != -1) return dp[idx][budget];

if(budget< prices[idx-1] || risk[idx-1]< risk_min || risk[idx-1]>risk_max){

return dp[idx][budget] = knapsack(profit,risk,prices,budget, risk_min,


risk_max,idx- 1,dp);

int inc = profit[idx-1]+knapsack(profit,risk,prices,budget-prices[idx-


1], risk_min, risk_max,idx-1,dp);

int exc = knapsack(profit,risk,prices,budget, risk_min,

risk_max,idx-1,dp); if (inc > exc) {

dp[idx][budget] = inc;
} else {

dp[idx][budget] = exc;

return dp[idx][budget];

}
void findSelected(int idx, int budget, int profit[], int prices[], int risk[], int
min, int max, vector<int>& selected,vector<vector<int>> &dp) {

int x = budget;

while (idx > 0 && budget > 0) { if(budget<prices[idx-1] || risk[idx-1]<min


|| risk[idx-1]>max){}

else if (dp[idx][budget] != dp[idx -

1][budget]) { selected.push_back(idx -

1);

budget -= prices[idx - 1];


}

idx--;

cout<<endl;

void StockSelection(int n,int profit[], int risk[], int prices[], string names[],
int budget, int risk_min, int risk_max,string risk_type){

if (risk_type ==

"high") { risk_min

= 20;

risk_max = 100;

} else if (risk_type ==

"medium") { risk_min = 15;

risk_max = 20;
} else if (risk_type ==
"low") { risk_min = 5;

risk_max = 15;
} else {

printf("Invalid risk type. Use 'low', 'medium', or

'high'.\n"); return ;

vector<vector<int>>

dp(n+1,vector<int>(budget+1,-1)); vector<int>

selected;

int ans = knapsack(profit,risk, prices, budget, risk_min, risk_max,

n,dp); findSelected(n,budget,profit,prices,risk,risk_min,

risk_max,selected,dp); cout<<"You can make Maximum Profit :

"<<ans<<" with this Selectd Stokcs.\n";

cout<<"index\t"<<"\tName"<<endl;

for (int i=selected.size()-1; i>=0; i--) {

cout<<selected[i]+1<<"\t:\t" <<

names[selected[i]]<<endl;

int main() {

int n =

20;
int profit[] = {11,14,10,8,14,11,13,16,8,7,13,14,10,11,14,11,8,14,8 ,13};

int risk[] = {20,29,25,14,22,17,28,34,20,17,22,25,17,20,29,23,27,30,20,19};

int prices[] = {200, 500, 300, 150, 400, 250, 350, 600, 180, 120, 350, 420, 220,
300, 550,
280, 310, 640, 150, 280};

string names [n] = {"TCS", "Reliance", "HDFC", "ICICI", "Infosys",


"SBI", "Wipro", "HCL", "Axis", "Maruti",

"Bajaj", "L&T", "Adani", "Bharti", "ITC", "Hindalco", "Tech


Mahindra", "Power Grid", "ONGC", "Hero MotoCorp"};

int budget;

int risk_min, risk_max;

string risk_type ;

cout<<"Enter Risk Type('low', 'medium', or

'high') : "; cin>>risk_type;

cout<<"Enter Your Total

Budget : "; cin>>budget;

StockSelection(n,profit,risk,prices,names,budget,risk_min,risk_max,risk_type);

return 0;

}
Output

You might also like