Code covered by the BSD License  

Highlights from
Inflate

5.0

5.0 | 2 ratings Rate this file 2 Downloads (last 30 days) File Size: 3.24 KB File ID: #14457

Inflate

by Skynet

 

29 Mar 2007 (Updated 04 Jul 2007)

Adjust for inflation using the CPI Inflation Calculator at BLS.gov.

| Watch this File

File Information
Description

inflate(AMT,YEAR1,YEAR2) adjusts the value of the US dollar amount AMT for inflation as per the consumer price index, from what AMT was in year YEAR1 to what it was in year YEAR2. This is done using the CPI Inflation Calculator provided by the Bureau of Labor Statistics.

AMT can be any dollar amount. YEAR1 and YEAR2 each can both be any year from 1913 to the current year. YEAR2 is optional, with its default value being the current year.

EXAMPLES:

inflate(100,1913,2007) returns 2055.5455. This indicates that $100 in the year 1913 had the same purchasing power as $2,055.55 in the year 2007.

inflate(100,2007,1913) returns 4.8649

inflate(1,1975,2000) returns 3.2007

inflate(10.00,2001) returns 11.4906

amts=[100,10,1000];
years1=[2000,1925,1950];
years2=repmat(2007,size(amts));
amts_new=arrayfun(@inflate,amts,years1,years2) returns [118.1760, 116.2851, 8443.9419]
 
REMARKS:

Internet connectivity is required for this function to work.

This function will stop working if BLS changes its CPI Inflation Calculator page in a way that is sensitive to this function.

The URL to the CPI Inflation Calculator page is http://data.bls.gov/cgi-bin/cpicalc.pl

A "persistent" variable is used, so BLS is queried only once per session for every new combination of years.

It is of course possible to perform adjustment calculations entirely offline - this is warranted in any production environment. This is possible as long as historical CPI or inflation rates are available. By querying BLS, this function takes a somewhat lazy approach.

[Please subscribe to this file if you use it, so you can be notified of updates.]

Acknowledgements
This submission has inspired the following:
Adjust Per-capita
MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
01 Apr 2007 Dimitri Shvorob

Neat idea and instructive implementation! Now, if you could extend it to accept vectors.. The amount could be normalized to $1.

01 Apr 2007 John D'Errico

Excellent help, error checks, etc.

The only thing I'd do differently here would start with downloading the index in advance for every year between 1913 and 2007. Store this series in the code. Then any calls for a pair of years that do not go past 2007 result in only a pair of table lookups, followed by a simple ratio. This would improve both the speed of this code and reduce its reliance on the cpi server.

If the author wanted to get really tricky, store this data in an external mat file as a vector. Load it into memory as a persistent variable. This way subsequent calls will not even need to reload the lookup table. Test the current year, and if that year exceeds the last year in the data series, then make ONE call to the CPI server to update the series. Then save the updated series in the mat file. This would result in only minimal reliance on the internet.

Please login to add a comment or rating.
Updates
02 Apr 2007

Made a minor update to an error message.

11 Apr 2007

(1) Reorganized into subfunctions.
(2) Added persistent variable to lookup over same years faster.
(3) The output is no longer rounded to two decimal places.

11 Apr 2007

Shortened the displayed returned values in examples.

04 Jul 2007

Added MATLAB version check.

Tag Activity for this File
Tag Applied By Date/Time
finance Skynet 22 Oct 2008 09:06:17
modeling Skynet 22 Oct 2008 09:06:17
analysis Skynet 22 Oct 2008 09:06:17
inflation Skynet 22 Oct 2008 09:06:17
deflation Skynet 22 Oct 2008 09:06:17
cpi Skynet 22 Oct 2008 09:06:17
bls Skynet 22 Oct 2008 09:06:17
inflation calculator Skynet 22 Oct 2008 09:06:17

Contact us at files@mathworks.com