import { Broker } from "./Broker" ; import { Fund } from "./Fund/Fund" ; import { Percentage } from "./Percentage" ; export class Portfolio { constructor ( public assets , public brokers ) { } public getMarketCapPercentage ( ) { return this . getFunds ( ) . reduce ( ( previous , current ) => previous . add ( current . getMarketCapitalization ( ) ) , new Percentage ( 0 ) ) ; } public getFundNames ( ) { return this . assets . map ( ( asset ) => asset . fund . getIdentifier ( ) ) ; } public getYearlyCosts ( expectedDividend ) { return this . assets . reduce ( ( sum , asset ) => { const fund = asset . fund ; const fundCosts = fund . getTotalExpenseRatio ( ) . add ( fund . getInternalTransactionCosts ( ) ) . add ( fund . getDividendLeak ( ) . multiply ( expectedDividend ) ) ; return sum . add ( asset . allocation . multiply ( fundCosts ) ) ; } , new Percentage ( 0 ) ) ; } public getTotalExpenseRatio ( ) { return this . assets . reduce ( ( sum , asset ) => sum . add ( asset . allocation . multiply ( asset . fund . getTotalExpenseRatio ( ) ) ) , new Percentage ( 0 ) ) ; } public getDividendLeak ( ) { return this . assets . reduce ( ( sum , asset ) => sum . add ( asset . allocation . multiply ( asset . fund . getDividendLeak ( ) ) ) , new Percentage ( 0 ) ) ; } private getFunds ( ) { return this . assets . map ( ( asset ) => asset . fund ) ; } }