Kelley Blue Book

So I'm still passively in the market for a car.  I wanted to do some analysis using  The problem is that their interface is terrible if you want trend data.  I wanted to see the private party "good condition" (the middle 80% range) price for a range of years and a range of mileages.  Doing it through the website was painful, so I wrote the following script (Ruby):

require "open-uri"  
require "nokogiri"  
require "csv"

years = (2006..2010)  
mileages = (0..10).map{ |v| 10000 + v*5000 }

data = {}

years.each do |year|  
  data[year] = {}
  mileages.each do |mileage|
    sleep 2
    doc = Nokogiri::HTML(open("{year}-mazda-mazda5/sport-minivan-4d/?pricetype=private-party&anchor=true&mileage=#{mileage}"))
     data[year][mileage] = doc.css(".good-value .value").text
    puts "year: #{year} mileage: #{mileage} value: #{data[year][mileage]}"
end"mazda5.csv", "w") do |csv|  
  csv << [""].concat(years.to_a)
  mileages.each do |mileage|
    csv << [mileage].concat({ |y| y[mileage] })

This produced a nice spreadsheet file and then I created the following chart (y axis is cost, x axis is mileage):

Interesting observations

The car seems to depreciate at the same rate with respect to miles, regardless of the year.  (ie, the slope of the lines are all about the same)

The car seems to depreciate at about the same rate with respect to time for the first few years.  (ie, the space between lines is constant for 2010,2009,2008)

There is a big drop in value between 2008 and 2007 models, and a slightly smaller gap between 2007 and 2006 models.


  • I like ruby. The library I used, nokogiri, is great.  I've tried some python libraries, like beautiful soup and lxml, but none are as succinct as nokogiri, especially when it comes to css selectors.

  • I find it interesting that there is such a sharp drop between 2008 and 2007. I always thought the car dropped in value more during the first 3 years than in years 4-8.

  • In the first three years, depreciation is about $500/year and $500/10k miles. So if trends continued, you could buy a 2010 and sell the car after 2 years and 20k for 2000 less than you bought it for.

comments powered by Disqus