Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

R, matlab, C++ or Java is preferable. Please do do python at all. R is most pref

ID: 3731894 • Letter: R

Question

R, matlab, C++ or Java is preferable. Please do do python at all.
R is most preferable

7. Dollar Weighted Yield rate: Write a program to calculate annualized dollar weighted yield rates given the investments and timing of the investment. Assume that number of withdrawals and deposits are finite Test Problem On January 1, 1995 Siobhan's investment account had a balance of $8412. She deposited $1000 on November 1, 1995 and withdrew $ 600 on November 1,1997. Her balance on July 1, 1998 was 9620. What was Siobhan's approximate annual dollar-weighted yield rate for the 42 months? Now suppose I add another deposit on October 1, 1995 (assuming final balance and all other terms are still same) can your program handle it (without writing entirely new program)? Suppose I made a deposit on Dec 31, 1995 can your program handle it and give me dollar weighted rate(assuming final balance and all other terms are still same). What if I change the length of investment to 48 month(That mean Jan1, 1999)? Can your program give the dollar weighted rate of return without having to write a new program?

Explanation / Answer

Below approach solves both test problem, any number of transactions can be added and dollar weighted rate can be calculated.

DollarWeighedYieldCalculator.Java

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.HashMap;

import java.util.Map;

import java.util.Scanner;

public class DollarWeighedYieldCalculator {

Map<Integer,Transaction> map= new HashMap<Integer,Transaction>();

int i;

public static void main(String [] args) throws NumberFormatException, ParseException

{

Scanner sc=new Scanner(System.in);

DollarWeighedYieldCalculator dWYC = new DollarWeighedYieldCalculator();

System.out.println("Welcome to Dollar Weighed Yield Calculator");

System.out.println("Enter Current Account Balanace of Account Holder in following format AccountName Balance DateInFormat(dd/MM/yyyy) Ex Sioban 2000 01/01/1991");

String input= sc.nextLine();

String[] sa = input.split("");

  

  

dWYC.map.put(++(dWYC.i), new Transaction(sa[0],"Deposit",Integer.parseInt(sa[1]),new SimpleDateFormat("dd/MM/yyyy").parse(sa[2])));

  

boolean askAgain = true;

while (askAgain) {

System.out.print("Enter a number: 1 to add Transaction, 2 to view annual dollar yield ");

String line = sc.nextLine();

switch (line) {

case "1":

dWYC.addTransaction();

break;

case "2":

dWYC.showYield();

break;

default:

askAgain = false;

}

}

}

private void showYield() {

float netDeposit=0;

float netWithdraw=0;

float netDepositCont=0;

float netWithdrawCont=0;

for (Map.Entry<Integer,Transaction> entry : this.map.entrySet())

{

Transaction t=entry.getValue();

if(t.getTransactionType().equalsIgnoreCase("Deposit"))

{

netDeposit+=t.getAmt();

netDepositCont=(t.getAmt()*(t.getTransactionDate().getMonth())/12);

}

else if(t.getTransactionType().equalsIgnoreCase("Withdraw"))

{

netWithdraw+=t.getAmt();

netWithdrawCont=(t.getAmt()*(t.getTransactionDate().getMonth())/12);

}

}

float balance= netDeposit-netWithdraw;

float balanceCont= netDepositCont - netWithdrawCont;

float dollarWeightedSum = (balance/balanceCont)*(100);

System.out.println("Dollar weighted Sum is "+ dollarWeightedSum);

}

private void addTransaction() throws NumberFormatException, ParseException {

System.out.println("Enter Transaction of Account Holder in following format AccountName TransactionType Balance DateInFormat(dd/MM/yyyy) Ex Sioban Deposit/Withdraw 2000 01/01/1991");

Scanner sc1=new Scanner(System.in);

String input= sc1.nextLine();

String[] sa = input.split("");

  

this.map.put(++i, new Transaction(sa[0],sa[1],Integer.parseInt(sa[2]),new SimpleDateFormat("dd/MM/yyyy").parse(sa[3])));

  

}

}

class Transaction{

private String accountName;

public String getAccountName() {

return accountName;

}

public void setAccountName(String accountName) {

this.accountName = accountName;

}

//Deposit or Withdraw

private String transactionType;

private float amt;

private Date transactionDate;

public String getTransactionType() {

return transactionType;

}

public void setTransactionType(String transactionType) {

this.transactionType = transactionType;

}

public float getAmt() {

return amt;

}

public void setAmt(float amt) {

this.amt = amt;

}

public Date getTransactionDate() {

return transactionDate;

}

public void setTransactionDate(Date transactionDate) {

this.transactionDate = transactionDate;

}

public Transaction(String accountName, String transactionType, float amt,

Date transactionDate) {

super();

this.accountName = accountName;

this.transactionType = transactionType;

this.amt = amt;

this.transactionDate = transactionDate;

}

public Transaction()

{

}

@Override

public String toString() {

return "Transaction [accountName=" + accountName + ", transactionType="

+ transactionType + ", amt=" + amt + ", transactionDate="

+ transactionDate + "]";

}

}