Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Team 134-Fintellect/InvestmentGraph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.util.*;

class InvestmentGraph {
private Map<String, List<String>> goalDependencies = new HashMap<>();
private Map<String, Integer> goalPriorities = new HashMap<>();
private PriorityQueue<String> priorityQueue;

public InvestmentGraph() {
priorityQueue = new PriorityQueue<>((a, b) -> goalPriorities.get(b) - goalPriorities.get(a));
}

public void addGoal(String goal, int priority) {
if (!goalDependencies.containsKey(goal)) {
goalDependencies.put(goal, new ArrayList<>());
}
goalPriorities.put(goal, priority);
priorityQueue.add(goal);
}

public void addDependency(String goal, String dependency) {
goalDependencies.putIfAbsent(dependency, new ArrayList<>());
goalDependencies.get(dependency).add(goal);
}

public void displayGoalsByPriority() {
System.out.println("Goals sorted by priority:");
while (!priorityQueue.isEmpty()) {
String goal = priorityQueue.poll();
System.out.println(goal + " (Priority: " + goalPriorities.get(goal) + ")");
}
}

public void displayGoalOrder() {
Map<String, Integer> indegree = new HashMap<>();
for (String goal : goalDependencies.keySet()) {
indegree.put(goal, 0);
}
for (List<String> dependencies : goalDependencies.values()) {
for (String dependent : dependencies) {
indegree.put(dependent, indegree.getOrDefault(dependent, 0) + 1);
}
}

Queue<String> queue = new LinkedList<>();
for (String goal : indegree.keySet()) {
if (indegree.get(goal) == 0) {
queue.add(goal);
}
}

System.out.println("Goal Completion Order:");
while (!queue.isEmpty()) {
String current = queue.poll();
System.out.println(current);
for (String dependent : goalDependencies.getOrDefault(current, new ArrayList<>())) {
indegree.put(dependent, indegree.get(dependent) - 1);
if (indegree.get(dependent) == 0) {
queue.add(dependent);
}
}
}
}
}
75 changes: 75 additions & 0 deletions Team 134-Fintellect/InvestmentPlanner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import java.util.*;

public class InvestmentPlanner {

static class Investment {
String name;
int cost, expectedReturn, risk;

Investment(String name, int cost, int expectedReturn, int risk) {
this.name = name;
this.cost = cost;
this.expectedReturn = expectedReturn;
this.risk = risk;
}
}

public static void optimizePortfolioFractional() {
Scanner sc = new Scanner(System.in);

System.out.println("Enter your total budget (₹): ");
int budget = sc.nextInt();
if (budget <= 0) {
System.out.println("Budget must be greater than 0. Exiting optimization.");
return;
}

System.out.println("Enter your maximum acceptable risk level (e.g., 1 to 10): ");
int maxRisk = sc.nextInt();

System.out.println("How many investment options do you want to enter?");
int n = sc.nextInt();
if (n <= 0) {
System.out.println("No investment options provided. Exiting optimization.");
return;
}

Investment[] options = new Investment[n];
for (int i = 0; i < n; i++) {
System.out.println("\nEnter details for Investment " + (i + 1));
System.out.print("Name: ");
String name = sc.next();
System.out.print("Cost (₹): ");
int cost = sc.nextInt();
System.out.print("Expected Return (₹): ");
int ret = sc.nextInt();
System.out.print("Risk (1-10): ");
int risk = sc.nextInt();

if (cost <= 0 || ret <= 0 || risk < 1 || risk > 10) {
System.out.println("Invalid investment details. Skipping this investment.");
continue;
}

options[i] = new Investment(name, cost, ret, risk);
}

Arrays.sort(options, (a, b) -> Double.compare((double) b.expectedReturn / b.cost, (double) a.expectedReturn / a.cost));

double totalReturn = 0;
for (Investment inv : options) {
if (budget >= inv.cost) {
budget -= inv.cost;
totalReturn += inv.expectedReturn;
System.out.println("Selected: " + inv.name + " (Full)");
} else {
double fraction = (double) budget / inv.cost;
totalReturn += inv.expectedReturn * fraction;
System.out.println("Selected: " + inv.name + " (" + (fraction * 100) + "%)");
break;
}
}

System.out.println("Maximized Return: ₹" + totalReturn);
}
}
116 changes: 116 additions & 0 deletions Team 134-Fintellect/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

while (true) {
// Display the main menu
System.out.println("\nWelcome to Fintech Investment Planner!");
System.out.println("======================================");
System.out.println("1. Optimize Investment Portfolio");
System.out.println("2. View Investment Goal Dependencies");
System.out.println("3. Run Risk Profile Simulator");
System.out.println("4. Get Personalized Fund Recommendations");
System.out.println("5. Exit");

// User input for menu choice
System.out.print("Enter your choice: ");
int choice = sc.nextInt();

// Handle user selection using switch
switch (choice) {
case 1:
System.out.println("Running Portfolio Optimization...");
InvestmentPlanner.optimizePortfolioFractional(); // Updated to call fractional optimization
break;

case 2:
System.out.println("Opening Goal Dependency Tracker...");
runGoalDependencyModule(); // Calls method for goal dependency management
break;

case 3:
System.out.println("Launching Risk Profiling Simulator...");
runRiskProfileSimulation(sc); // Calls method to simulate risk profile
break;

case 4:
System.out.println("Generating Personalized Fund Recommendations...");
PortfolioAllocator.suggestFundsWeighted(); // Updated to call weighted fund recommendation
break;

case 5:
System.out.println("Exiting... Thank you for using the planner.");
return; // Ends the program

default:
System.out.println("Invalid option. Please try again.");
}
}
}

// Handles the investment goal and dependency logic
private static void runGoalDependencyModule() {
try (Scanner sc = new Scanner(System.in)) {
InvestmentGraph graph = new InvestmentGraph(); // Custom class for managing goals as a graph

// Collect number of goals from user
System.out.print("Enter number of goals: ");
int n = sc.nextInt();
sc.nextLine(); // Clear input buffer

// Add goals with their priorities
for (int i = 0; i < n; i++) {
System.out.print("Enter goal name: ");
String goal = sc.nextLine();

System.out.print("Enter priority (integer) for this goal: ");
int priority = sc.nextInt();
sc.nextLine();

graph.addGoal(goal, priority);
}

// Collect dependencies between goals
System.out.print("Enter number of dependencies: ");
int d = sc.nextInt();
sc.nextLine();

for (int i = 0; i < d; i++) {
System.out.print("Enter dependency (format: dependentGoal prerequisiteGoal): ");
String[] dep = sc.nextLine().split(" ");
if (dep.length == 2) {
graph.addDependency(dep[0], dep[1]);
} else {
System.out.println("Invalid format. Skipping this dependency.");
}
}

// Display the ordered list of goals based on dependencies
graph.displayGoalOrder();
}
}

// Simulates user risk profiling based on basic inputs
private static void runRiskProfileSimulation(Scanner sc) {
System.out.print("Enter your age: ");
int age = sc.nextInt();

System.out.print("Enter total savings (in ₹): ");
int savings = sc.nextInt();

System.out.print("Do you have active loans? (true/false): ");
boolean hasLoans = sc.nextBoolean();

// Create a UserProfile object
RiskProfileSimulator.UserProfile profile = new RiskProfileSimulator.UserProfile(
age, savings, 0, hasLoans, 0, 0
);

// Determine risk type using the updated method
String riskType = RiskProfileSimulator.determineRiskType(profile);
System.out.println("Risk Profile: " + riskType);
}
}
126 changes: 126 additions & 0 deletions Team 134-Fintellect/PortfolioAllocator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import java.util.*;

public class PortfolioAllocator {

static class Fund {
String name;
int expectedReturn, risk, tenure, cost;

Fund(String name, int expectedReturn, int risk, int tenure, int cost) {
this.name = name;
this.expectedReturn = expectedReturn;
this.risk = risk;
this.tenure = tenure;
this.cost = cost;
}

public int weightedScore(int userRisk, int userTenure, int weightReturn, int weightRisk, int weightTenure) {
int riskScore = Math.max(0, 10 - Math.abs(userRisk - this.risk) * 2);
int tenureScore = Math.max(0, 10 - Math.abs(userTenure - this.tenure));
return (expectedReturn * weightReturn) + (riskScore * weightRisk) + (tenureScore * weightTenure);
}
}

// HashMap to store funds for quick lookup
private static Map<String, Fund> fundMap = new HashMap<>();

// Graph to represent fund dependencies
private static Map<String, List<String>> fundDependencyGraph = new HashMap<>();

public static void suggestFundsWeighted() {
Scanner sc = new Scanner(System.in);

System.out.println("Enter your risk tolerance (1 - Conservative, 2 - Balanced, 3 - Aggressive): ");
int userRisk = sc.nextInt();
if (userRisk < 1 || userRisk > 3) {
System.out.println("Invalid risk tolerance. Please enter a value between 1 and 3.");
return;
}

System.out.println("Enter your preferred investment tenure (in years): ");
int userTenure = sc.nextInt();
if (userTenure <= 0) {
System.out.println("Investment tenure must be greater than 0. Please enter a valid tenure.");
return;
}

System.out.println("Assign weights to factors (total should be 100):");
System.out.print("Weight for Return: ");
int weightReturn = sc.nextInt();
System.out.print("Weight for Risk: ");
int weightRisk = sc.nextInt();
System.out.print("Weight for Tenure: ");
int weightTenure = sc.nextInt();

if (weightReturn + weightRisk + weightTenure != 100) {
System.out.println("Weights must add up to 100. Please re-enter the weights.");
return;
}

// Initialize funds and dependencies
initializeFundsAndDependencies();

// Sort funds based on weighted score
List<Fund> fundList = new ArrayList<>(fundMap.values());
fundList.sort((a, b) -> b.weightedScore(userRisk, userTenure, weightReturn, weightRisk, weightTenure)
- a.weightedScore(userRisk, userTenure, weightReturn, weightRisk, weightTenure));

System.out.println("\nPersonalized Fund Recommendations:");
for (Fund f : fundList) {
System.out.println(f.name + " | Score: " + f.weightedScore(userRisk, userTenure, weightReturn, weightRisk, weightTenure));
}

// Display fund dependencies
System.out.println("\nFund Dependency Graph:");
for (String fund : fundDependencyGraph.keySet()) {
System.out.println(fund + " -> " + fundDependencyGraph.get(fund));
}

// Portfolio optimization using DP
System.out.println("\nEnter your budget for investment: ");
int budget = sc.nextInt();
int maxReturn = optimizePortfolioDP(fundList, budget);
System.out.println("Maximum return achievable within budget: " + maxReturn);
}

private static void initializeFundsAndDependencies() {
// Add funds to the HashMap
fundMap.put("Tech ETF", new Fund("Tech ETF", 18, 3, 5, 100));
fundMap.put("Public Provident Fund", new Fund("Public Provident Fund", 8, 1, 15, 50));
fundMap.put("SIP Balanced", new Fund("SIP Balanced", 12, 2, 7, 70));
fundMap.put("Government Bonds", new Fund("Government Bonds", 7, 1, 10, 40));
fundMap.put("Bluechip Equity", new Fund("Bluechip Equity", 14, 2, 6, 90));
fundMap.put("Aggressive Mutual", new Fund("Aggressive Mutual", 20, 3, 4, 120));

// Add dependencies to the graph
fundDependencyGraph.put("Tech ETF", Arrays.asList("Bluechip Equity"));
fundDependencyGraph.put("Public Provident Fund", Arrays.asList());
fundDependencyGraph.put("SIP Balanced", Arrays.asList("Government Bonds"));
fundDependencyGraph.put("Government Bonds", Arrays.asList());
fundDependencyGraph.put("Bluechip Equity", Arrays.asList());
fundDependencyGraph.put("Aggressive Mutual", Arrays.asList("Tech ETF", "SIP Balanced"));
}

// Dynamic Programming for portfolio optimization
private static int optimizePortfolioDP(List<Fund> funds, int budget) {
int n = funds.size();
int[][] dp = new int[n + 1][budget + 1];

for (int i = 1; i <= n; i++) {
Fund fund = funds.get(i - 1);
for (int w = 1; w <= budget; w++) {
if (fund.cost <= w) {
dp[i][w] = Math.max(dp[i - 1][w], dp[i - 1][w - fund.cost] + fund.expectedReturn);
} else {
dp[i][w] = dp[i - 1][w];
}
}
}

return dp[n][budget];
}

public static void main(String[] args) {
suggestFundsWeighted();
}
}
Loading