<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/are-you-buying-an-apartment-how-to-hack-competition-in-the-real-estate-market-with-data-monitoring/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://appsilon.com/buying-or-selling-an-apartment-data-science/"> r – Appsilon Data Science | We Provide End­ to­ End Data Science Solutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In the last couple of years, real estate companies have shifted their focus to the digital world, and now almost all investments have an online system showing what apartments are available. This is very convenient for their potential clients, as they can easily become familiar with the apartments on offer. Things become interesting when all available data is monitored on a weekly basis, and sales progress is analysed.</p>
<blockquote>
<p>Why is this so important? As sales dynamics are crucial figures that are rarely represented as a number, it gives you an edge in negotiations. Knowing the dynamics enables you to better plan your cash flow over time, and increase your asset efficiency in the short term.</p>
</blockquote>
<p>This investigation helped me to fight against the odds of the <a rel="nofollow" href="https://www.ey.com/pl/pl/industries/real-estate/the-polish-real-estate-guide-2018-en" target="_blank">current real estate market in Poland</a><u>,</u> and close apartment deals on better terms.</p>
<p>How can you benefit as an individual client?</p>
<ol>
<li>You have an additional edge in price negotiations.</li>
<li>You can choose the right moment to buy.</li>
<li>You can predict the next move of a developer. Was the investment successful? Will they continue to the next phase? What’s their current financial situation?</li>
</ol>
<p>Also, this approach can be beneficial to a real estate company through monitoring competition?</p>
<ol>
<li>You have first-hand knowledge about market demand in a given location.</li>
<li>You can recognise patterns in your competitor’s sales process.</li>
<li>You can better understand clients’ needs. Which types of apartments are sold more quickly?</li>
</ol>
<h2>Example results after monitoring one of the locations in Warsaw</h2>
<p><span>The investment is built in the Warsaw eastern district of Praga Południe. This is an area with great potential. Currently, there are a lot of apartment buildings and places that wait for renovation or replacement. However, it is very well connected with the city center (15 minutes by public transport or 10 minutes by car). Another advantage is that there are a lot of points of interests like shopping malls, parks, schools or medical service points.</span></p>
<p>The monitored investment is built in the eastern Warsaw district of Praga Południe. This is an area with great potential. Currently, there are a lot of apartment buildings and places waiting to be renovated. However, it is very well connected with the city centre (15 minutes by public transport or 10 minutes by car). There are also a lot of facilities nearby, such as shopping malls, parks, schools, or medical service points.</p>
<p>Here are the basic characteristics of the monitored investment:</p>
<ul>
<li>There are 135 apartments for sale.</li>
<li>There are 8 floors in the building; each floor has 14 to 16 apartments.</li>
<li>Investment starts from an empty plot with construction permission, work on the site started in Q1 2018. Planned date of completion is Q4 2019.</li>
<li>The real estate developer began selling apartments in April 2018.</li>
</ul>
<p>After collecting the first data from the investment website, we can see the current offers of different apartment types:</p>
<p><img sizes="(max-width: 763px) 100vw, 763px" src="https://i1.wp.com/appsilon.com/assets/uploads/2018/09/types-of-apartments-e1538736853539.png?w=450&ssl=1" alt="types-of-apartments" class="wp-image-1340" data-recalc-dims="1"></p>
<p>This is good to know, but the most interesting data comes from the periodical monitoring of sales progress. Below you can see the timeline representing the number of apartments sold each week:<span><img sizes="(max-width: 947px) 100vw, 947px" src="https://i2.wp.com/appsilon.com/assets/uploads/2018/09/sell-count-1-e1538738393450.png?w=450&ssl=1" alt="" class="wp-image-1343" data-recalc-dims="1"></span></p>
<p>What else can we see? For example, what is the current state of sales progress?</p>
<p><span><img sizes="(max-width: 781px) 100vw, 781px" src="https://i0.wp.com/appsilon.com/assets/uploads/2018/09/availability.png?w=450&ssl=1" alt="" class="wp-image-1341" data-recalc-dims="1"></span></p>
<p>It is worth remembering that construction began in Q1 2018. Currently, only the building’s foundation is ready, but almost half of the apartments are already sold.</p>
<h2><strong>Predicted date of selling all apartments</strong></h2>
<p>Let’s see what the <strong>sales dynamic</strong> is by apartment type. We can also try to make a simple prediction of when all apartments will be sold.</p>
<p><img sizes="(max-width: 917px) 100vw, 917px" src="https://i0.wp.com/appsilon.com/assets/uploads/2018/09/sales-rate-1.png?w=450&ssl=1" alt="sales-rate-dynamic" class="wp-image-1342" data-recalc-dims="1"></p>
<p>What we can see from this visualisation:</p>
<ul>
<li>If the selling pace continues, almost all apartments will be sold by May 2019. This is over 6 months before the planned construction completion date.</li>
<li>However, not all apartments have the same sales dynamic. The fastest selling apartments have 1 or 2 rooms. The biggest apartments, with 4 rooms, are less popular – only 3 have sold.</li>
</ul>
<h3><strong>Did potential buyers change their mind? Could they get a mortgage loan?</strong></h3>
<p>Another interesting observation is about apartments that had sold, but later became available again. There are multiple reasons why this happens. It is important to understand how the selling process works. The buyer has to sign an agreement with the developer before requesting a loan from a bank. There is always a possibility that after officially signing for an apartment, the bank can reject your loan request. The buyer can also change their mind and withdraw for other reasons.</p>
<p>In the observed data, there was only one situation like this.  A 2-room apartment with a separate kitchen was sold at the end of August 2018, but, in mid-September, became available again.</p>
<h2><strong>Data scraping</strong></h2>
<p>Gathering valuable data for analysis is the foundation of every data science process. When the data comes from an external online source, one of the methods is <a rel="nofollow" href="https://en.wikipedia.org/wiki/Data_scraping" target="_blank">data scraping</a>. This technique means that the data is “scraped” from a website by a web crawler (other names are “robot” or “scraper”). The robot parses text into a machine-readable format, so then it can be analysed.</p>
<p>Companies are aware of this process, so they usually protect their websites and online systems. Some of the techniques are:</p>
<ul>
<li>Displaying content in a dynamic way (e.g. using JavaScript) or complicating website structure, so it is harder for a crawler to parse.</li>
<li>Protecting content with captcha or other robot-detection tools.</li>
<li>Anomaly detection systems that analyse behaviour between requests and ban suspicious visitors.</li>
</ul>
<p>At <a rel="nofollow" href="https://appsilon.com/services/real-estate" target="_blank">Appsilon</a> we know how to deal with all of these obstacles. All of them make web scraping harder, but are not bulletproof.</p>
<h2>Collecting the data from the investment page</h2>
<p>In the case described in this article, I monitored one of the locations in Warsaw. The real estate developer is selling apartments in this location using an online system, which contains the following table of apartment availability.</p>
<p><img sizes="(max-width: 1198px) 100vw, 1198px" src="https://i2.wp.com/appsilon.com/assets/uploads/2018/09/Screenshot-from-2018-09-30-19-40-08.png?w=450&ssl=1" alt="" class="wp-image-1334" data-recalc-dims="1"></p>
<p>This system didn’t have any captcha or anomaly detection protection. The only impediment here is that the content is loaded dynamically using JavaScript, and there is no open API endpoint where we can just request the data. You are able to view the data only after clicking through the interface.</p>
<p>The solution is a web crawler simulating human behaviour, clicking through the interface. Imagine that you have a robot-employee, who monitors all the information you need, on a weekly basis, doesn’t get tired or bored, and is 100% precise.</p>
<p>I used <a rel="nofollow" href="https://developers.google.com/web/tools/puppeteer/" target="_blank">Google’s Puppeteer.js</a> technology; it can replicate a human behaviour in a browser running in the background. Here is the source code of a scraper:</p>
<p> </p>
<figure>
<pre><code data-lang="r">
<span>const puppeteer = require('puppeteer');</span>
<span>(async() => {</span>
<span>  const browser = await puppeteer.launch();</span>
<span>  const page = await browser.newPage();</span>
<span>  await page.goto('</span><a rel="nofollow" href="https://real-estate-developer-address.com/list.aspx" target="_blank"><span>https://real-estate-developer-address.com/</span></a><span>'); // Real URL address is confidential</span>
<span>  await page.click('#cbNotSale');</span>
<span>  await page.waitFor(2000);</span>

<span>  const nextSelector = '//input[contains(@alt, &quot;>&quot;)]'</span>
<span>  var next = await page.$x(nextSelector)
</span>
<span>  while (next.length > 0) {</span>
<span>    const cells = await page.$x('//*[@id=&quot;gwProducts&quot;]/tbody/tr/td');</span>
<span>    var vals = [];</span>
<span>    var val = null;</span>

<span>    for (var i = 0; i &lt; cells.length; i++) {</span>
<span>      val = await page.evaluate(x => x.textContent, cells[i])</span>
<span>      if (val == &quot;F1&quot;) vals.push([]); // The quickest (dirty) way to recognize row beginning.</span>
<span>      if (val == &quot;zobacz&quot; || val.trim() == &quot;&quot;) continue; // The quickest (dirty) way to recognize row end.</span>
<span>      vals[vals.length - 1].push(val)</span>
<span>    }</span>

<span>    vals.forEach(row => {</span>
<span>      console.log(row.join(&quot;;&quot;)) // Robot prints collected rows to the stdout</span>
<span>    });
</span>
<span>    await next[0].click()</span>
<span>    await page.waitFor(2000);</span>
<span>    next = await page.$x(nextSelector)</span>
<span>  }
</span>
<span>  await page.screenshot({path: 'example.png'});</span>
<span>  await browser.close();</span>

<span>})();
</span></code></pre>
</figure>
<p><span>And we can run the crawler with the command below. Just configure a CRON or other job to run this weekly:</span></p>
<figure>
<pre><code data-lang="r">
<span>node scraper.js > data-YYYY-MM-DD.csv </span></code></pre>
</figure>
<p>This is just one of a wide range of techniques that can be used for scraping. Let us know if you want to know more about <a rel="nofollow" href="https://appsilon.com/services/real-estate" target="_blank">collecting data and other business cases from our experience</a>!</p>
<h2><b>Aftermath</b></h2>
<p>As a private investor, I need to excel in my investments. There is no place for bad bets, which is why I use all available cards in the deck to make sure I do everything in my data science power. This analysis gave me the information about the investment’s financial performance, and I could predict how much time I had to close the deal for my dream apartment. I had more time for the final decision, and I was more confident during negotiations. Remember that buying an apartment at the latest possible moment gives you short-term alternatives, instead of freezing your capital right away. <strong>I had an edge that other buyers did not, so I could easily tackle false claims about the popularity of the apartments,</strong> and not feel pressured into buying. Each sales process is a game with unequal distribution of knowledge. Knowledge of sales dynamics will allow you to fight against the odds and close better deals.</p>
<p>Artykuł <a rel="nofollow" href="https://appsilon.com/buying-or-selling-an-apartment-data-science/" target="_blank">Are you buying an apartment? How to hack competition in the real estate market with data monitoring</a> pochodzi z serwisu <a rel="nofollow" href="https://appsilon.com/" target="_blank">Appsilon Data Science | We Provide End­ to­ End Data Science Solutions</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://appsilon.com/buying-or-selling-an-apartment-data-science/"> r – Appsilon Data Science | We Provide End­ to­ End Data Science Solutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/Fo2WCaIB48c" height="1"></a></div>