For java NAV is the Net Assets Valuation which is the value of the total assets
ID: 3890003 • Letter: F
Question
For java
NAV is the Net Assets Valuation which is the value of the total assets held in a portfolio. Often the portfolio managers try to track a certain benchmark portfolio in terms of the percentage weight of the assets. For instance, consider a portfolio PORT with 3 assets and a benchmark portfolio BENCH with 3 assets:
The percentage Nav in stock A for PORT can be calculated as follows:
A Portfolio is said to be overweight in a stock if its %Nav in that stock is larger than the %Nav in the stock in the Benchmark. Alternately, it is underweight in a stock if its %Nav in a stock is less than the benchmark.
Write a program to calculate the difference in the %Nav of the holdings in the PORT and the BENCH.
Sort the portfolios in alphabetical order and display the difference upto 2 decimal points.
For example:
Input:
PORT:AXN,10,10;BGT,20,30;CXZ,10,30|BENCH:AXN,50,10;BGT,30,30;DFG,30,20
Output:
AXN:-15.0,BGT:15.0,CXZ:30.0,DFG:-30.0
Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pi;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author Veerendra Patel
*/
public class NewClass1{
NewClass1()
{
}
String stock;
int quantity;
float price;
float percentage;
float NAV;
void readDetails()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Stock:");
stock = input.next();
System.out.println("Enter Quantity:");
quantity=input.nextInt();
System.out.println("Enter Price:");
price = input.nextFloat();
}
void PrintDetails()
{
System.out.println(stock+" "+quantity+" "+price+" "+percentage);
}
public static void main(String[] args)
{
NewClass1[] Port = new NewClass1[10];
NewClass1[] Bench = new NewClass1[10];
System.out.println("Enter the Deatils for PORT: ");
System.out.println(" How many stocks?");
Scanner in=new Scanner(System.in);
int n = in.nextInt();
System.out.print(n);
for(int i=0;i<n;i++)
{
Port[i]=new NewClass1();
Port[i].readDetails();
}
float PortNAV=0;
for(int i=0;i<n;i++)
{
PortNAV+=Port[i].quantity*Port[i].price;
}
for(int i=0;i<n;i++)
{
Port[i].percentage=((Port[i].quantity*Port[i].price)*100) / PortNAV;
}
System.out.println("Enter the Deatils for Bench: ");
System.out.println(" How many stocks?");
n = in.nextInt();
for(int i=0;i<n;i++)
{
Bench[i]=new NewClass1();
Bench[i].readDetails();
}
float BenchNAV=0;
for(int i=0;i<n;i++)
{
BenchNAV+=Bench[i].quantity*Bench[i].price;
}
for(int i=0;i<n;i++)
{
Bench[i].percentage=((Bench[i].quantity*Bench[i].price)*100) / BenchNAV;
}
System.out.println("Port Stock Quantity Price Percentage Difference");
for(int i=0;i<n;i++)
{
Port[i].PrintDetails();
float diff=Port[i].percentage-Bench[i].percentage;
System.out.print(diff);
if(diff<0)
{
System.out.print("UnderWeight");
}
else
{
System.out.print("OverWeight");
}
}
System.out.println("Bench Stock Quantity Price Percentage");
for(int i=0;i<n;i++)
{
Bench[i].PrintDetails();
float diff=Bench[i].percentage-Port[i].percentage;
System.out.print(diff);
if(diff<0)
{
System.out.print("UnderWeight");
}
else
{
System.out.print("OverWeight");
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.