Last active
June 10, 2018 08:21
-
-
Save rodoabad/7413e680396429a6b9041540ae9ab5fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import BigNumber from 'bignumber.js'; | |
| import moment from 'moment'; | |
| const defaultDecimalPlaces = 10; | |
| const findApplicableSplitsAgainstDividendYear = (dividendYear, splits) => { | |
| const formattedDividendYear = Number(moment(dividendYear).format('X')); | |
| return splits.reduce((acc, split) => { | |
| const formattedExDate = Number(moment(split.exDate).format('X')); | |
| return formattedExDate > formattedDividendYear ? | |
| [ | |
| ...acc, | |
| split.ratio | |
| ] : | |
| acc; | |
| }, []); | |
| } | |
| const applySplitsRatiosToMatchingDividendAmount = (dividendAmount, applicableSplits) => applicableSplits.reduce((acc, ratio) => { | |
| const amountWithAppliedSplitRatio = acc.multipliedBy(ratio); | |
| return amountWithAppliedSplitRatio; | |
| }, dividendAmount); | |
| export const adjustDividendAmountForSplits = (dividend, splits) => { | |
| const dividendAmount = new BigNumber(dividend.amount); | |
| const applicableSplits = findApplicableSplitsAgainstDividendYear(dividend.exDate, splits); | |
| const divAmountWithAppliedSplitRatios = applySplitsRatiosToMatchingDividendAmount(dividendAmount, applicableSplits); | |
| return divAmountWithAppliedSplitRatios.decimalPlaces(defaultDecimalPlaces).toNumber(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment