public static double [ ] computeSeasonalAdjustments ( double [ ] realizedCPIValues , int lastMonth , int numberOfYearsToAverage ) { /* * Cacluate average log returns */ double [ ] averageLogReturn = new double [ 12 ] ; Arrays . fill ( averageLogReturn , 0.0 ) ; for ( int arrayIndex = 0 ; arrayIndex < 12 * numberOfYearsToAverage ; arrayIndex ++ ) { int month = ( ( ( ( ( lastMonth - 1 - arrayIndex ) % 12 ) + 12 ) % 12 ) ) ; double logReturn = Math . log ( realizedCPIValues [ realizedCPIValues . length - 1 - arrayIndex ] / realizedCPIValues [ realizedCPIValues . length - 2 - arrayIndex ] ) ; averageLogReturn [ month ] += logReturn / numberOfYearsToAverage ; } /* * Normalize */ double sum = 0.0 ; for ( int index = 0 ; index < averageLogReturn . length ; index ++ ) { sum += averageLogReturn [ index ] ; } double averageSeasonal = sum / averageLogReturn . length ; double [ ] seasonalAdjustments = new double [ averageLogReturn . length ] ; for ( int index = 0 ; index < seasonalAdjustments . length ; index ++ ) { seasonalAdjustments [ index ] = averageLogReturn [ index ] - averageSeasonal ; } // Annualize seasonal adjustments for ( int index = 0 ; index < seasonalAdjustments . length ; index ++ ) { seasonalAdjustments [ index ] = seasonalAdjustments [ index ] * 12 ; } return seasonalAdjustments ; }
Computes annualized seasonal adjustments from given monthly realized CPI values .