import { Money } from "bigint-money/dist" ; import { Etf } from "./Fund/Etf" ; import { Fund } from "./Fund/Fund" ; import { MutualFund } from "./Fund/MutualFund" ; import { DeductibleFee } from "./Pricing/DeductibleFee" ; import { Fee } from "./Pricing/Fee" ; import { Transaction } from "./Transaction" ; export class Broker { constructor ( public name , public product , public serviceFee , public serviceFeeFrequency = 'quarterly' , public serviceFeeCalculation , public mutualFundTransactionFee , public etfTransactionFee , public dividendDistributionFee , public costOverview , public logo ? , public website ? , public affiliateLink ? ) { } public getTransactionCosts ( transaction ) { const transactionFee = this . getTransactionFeeFor ( transaction . fund ) ; return transactionFee . calculateFor ( transaction . amount ) ; } public calculateDividendFees ( dividend ) { return this . dividendDistributionFee . calculateFor ( dividend ) ; } public registerTransactionCosts ( transactionCosts ) { if ( this . serviceFee instanceof DeductibleFee ) { this . serviceFee . updateLastTransactionCosts ( transactionCosts ) ; } } public getMonthlyServiceFee ( portfolioValue ) { if ( this . serviceFeeFrequency !== 'monthly' ) { return new Money ( 0 , 'EUR' ) ; } return this . serviceFee . calculateFor ( portfolioValue ) ; } public getQuarterlyServiceFee ( portfolioValue , averageMonthlyValue , averageValue ) { if ( this . serviceFeeFrequency !== 'quarterly' ) { return new Money ( 0 , 'EUR' ) ; } if ( this . serviceFeeCalculation === 'averageEndOfMonth' ) { return this . serviceFee . calculateFor ( averageMonthlyValue ) ; } else if ( this . serviceFeeCalculation === 'averageOfQuarter' ) { return this . serviceFee . calculateFor ( averageValue ) ; } return this . serviceFee . calculateFor ( portfolioValue ) ; } private getTransactionFeeFor ( fund ) { if ( fund instanceof MutualFund ) { return this . mutualFundTransactionFee ; } if ( fund instanceof Etf ) { return this . etfTransactionFee ; } } }