{"id":4306,"date":"2019-07-25T15:52:13","date_gmt":"2019-07-25T05:52:13","guid":{"rendered":"https:\/\/casestudyhelp.com\/sample-questions\/?p=4306"},"modified":"2019-07-25T15:53:13","modified_gmt":"2019-07-25T05:53:13","slug":"affirm-take-home-coding-challenge-balance-the-loan-books","status":"publish","type":"post","link":"https:\/\/casestudyhelp.com\/sample-questions\/affirm-take-home-coding-challenge-balance-the-loan-books\/","title":{"rendered":"Affirm Take Home Coding Challenge: Balance the Loan Books"},"content":{"rendered":"<blockquote><p>Online <a title=\"Programming Assignment Help\" href=\"https:\/\/casestudyhelp.com\/programming-help\/\" target=\"_blank\"><strong>Programming Assignment Help<\/strong><\/a> by professionals programmers of Case Study Help. We cover <strong>Python, PHP, JAVA, AJAX, C, C++, C#, Databases, SQL, MATLAB, ASP.Net<\/strong> Assignments at affordable price.<\/p><\/blockquote>\n<h2><strong>Background<\/strong><\/h2>\n<ul>\n<li style=\"text-align: justify;\">At Affirm, we borrow money from our banking partners through debt facilities. In turn, we use these facilities to extend loans to customers.<\/li>\n<li style=\"text-align: justify;\">A banking partner may require a covenant, which is a set of restrictions on the loans that a facility may fund. Common restrictions include:\n<ul>\n<li>Maximum default rate: A bank may restrict us from funding certain riskier loans.<\/li>\n<li>Geographic location: A bank may restrict us from funding loans in certain states.<\/li>\n<\/ul>\n<\/li>\n<li style=\"text-align: justify;\">We may establish multiple facilities with a single bank. In this case, the bank may define covenants that apply to all of their facilities, or only to an individual one.<\/li>\n<\/ul>\n<h3><strong>Goals<\/strong><\/h3>\n<p style=\"text-align: justify;\">You will be provided with a list of facilities and covenants, as well as a stream of loans that Affirm would like to fund with those facilities. Your task is to write a program that consumes loans from the stream and assigns each loan to a facility while respecting each facility\u2019s covenants<\/p>\n<h3><strong>Input<\/strong><\/h3>\n<p style=\"text-align: justify;\">An input data set will consist of four CSV files, describing the facilities, banks, covenants, and loans, respectively. These files are described in the following sections. You will be given two data sets, a small data set (in the folder \u2018small\u2019) for manually verifying your understanding of the problem, along with a large data set (in the folder \u2018large\u2019) for more rigorously stress-testing your program. The folder \u2018small\u2019 will also contain the solution files \u2018assignments.csv\u2019 and \u2018yields.csv\u2019. These files will be described later.<\/p>\n<h3><strong>facilities.csv<\/strong><\/h3>\n<p>Each row in this file describes a single facility.<\/p>\n<table style=\"height: 95px;\" width=\"793\">\n<tbody>\n<tr>\n<td width=\"208\"><strong>Field<\/strong><\/td>\n<td width=\"208\"><strong>Type<\/strong><\/td>\n<td width=\"208\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"208\">bank_id<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The ID of the bank providing this facility.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">facility_id<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The ID of the facility.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">interest_rate<\/td>\n<td width=\"208\">float<\/td>\n<td width=\"208\">Between 0 and 1; the interest rate of this facility. In this simplified model, when we<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"height: 27px;\" width=\"794\">\n<tbody>\n<tr>\n<td width=\"208\"><\/td>\n<td width=\"208\"><\/td>\n<td width=\"208\">use x dollars from this facility to fund a loan, we are charged x * interest_rate dollars in interest.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">amount<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The total capacity of the facility in cents.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: center;\"><a title=\"Order Now\" href=\"https:\/\/casestudyhelp.com\/MyOrder.php\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-4044\" src=\"https:\/\/casestudyhelp.com\/sample-questions\/wp-content\/uploads\/2019\/04\/Order-now.png\" alt=\"Order Now\" width=\"552\" height=\"87\" srcset=\"https:\/\/casestudyhelp.com\/sample-questions\/wp-content\/uploads\/2019\/04\/Order-now.png 552w, https:\/\/casestudyhelp.com\/sample-questions\/wp-content\/uploads\/2019\/04\/Order-now-300x47.png 300w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/a><\/p>\n<h3><strong>banks.csv<\/strong><\/h3>\n<p>Each row in this file describes a banking partner.<\/p>\n<table style=\"height: 5px;\" width=\"802\">\n<tbody>\n<tr>\n<td width=\"208\"><strong>Field<\/strong><\/td>\n<td width=\"208\"><strong>Type<\/strong><\/td>\n<td width=\"208\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"208\">bank_id<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The ID of the bank.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">bank_name<\/td>\n<td width=\"208\">string<\/td>\n<td width=\"208\">The name of the bank.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3><strong>covenants.csv<\/strong><\/h3>\n<p style=\"text-align: justify;\">Each row in this denormalized file represents at least one covenant that we have with a bank. If a row contains both a max_default_likelihood and a banned_state, they should be treated as separate covenants.<\/p>\n<table style=\"height: 148px;\" width=\"804\">\n<tbody>\n<tr>\n<td width=\"223\"><strong>Field<\/strong><\/td>\n<td width=\"193\"><strong>Type<\/strong><\/td>\n<td width=\"208\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"223\">bank_id<\/td>\n<td width=\"193\">integer<\/td>\n<td width=\"208\">The ID of the bank requiring this covenant.<\/td>\n<\/tr>\n<tr>\n<td width=\"223\">facility_id<\/td>\n<td width=\"193\">integer<\/td>\n<td width=\"208\">If present, denotes that this covenant applies to the facility with this ID; otherwise, this covenant applies to all of the bank\u2019s facilities.<\/td>\n<\/tr>\n<tr>\n<td width=\"223\">max_default_likelihood<\/td>\n<td width=\"193\">float<\/td>\n<td width=\"208\">If present, specifies the maximum allowed default rate for loans in the facility (or in the bank\u2019s facilities).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"height: 54px;\" width=\"804\">\n<tbody>\n<tr>\n<td width=\"223\">banned_state<\/td>\n<td width=\"193\">string<\/td>\n<td width=\"208\">If present, indicates that loans in the facility (or in the bank\u2019s facilities) may not originate from this state.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><\/h3>\n<h3><strong>loans.csv<\/strong><\/h3>\n<p style=\"text-align: justify;\">Each row in this file represents a loan we would like to fund. Loans are ordered chronologically based on when we received them.<\/p>\n<table style=\"height: 302px;\" width=\"804\">\n<tbody>\n<tr>\n<td width=\"208\"><strong>Field<\/strong><\/td>\n<td width=\"208\"><strong>Type<\/strong><\/td>\n<td width=\"208\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"208\">id<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The ID of the loan. Strictly increasing.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">amount<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The size of the loan in cents.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">interest_rate<\/td>\n<td width=\"208\">float<\/td>\n<td width=\"208\">Between 0 and 1; the interest rate of the loan. In this simplified model, the amount of money we earn from a loan (if it doesn\u2019t default) is amount * interest_rate.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">default_likelihood<\/td>\n<td width=\"208\">float<\/td>\n<td width=\"208\">Between 0 and 1; the probability that this loan will default. In this simplified model, when the loan defaults, we lose all the money that we lent and do not earn any interest on the loan.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">state<\/td>\n<td width=\"208\">string<\/td>\n<td width=\"208\">State where the loan originated.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3><strong>Calculating Loan Yields<\/strong><\/h3>\n<p style=\"text-align: justify;\">The <em>expected yield of a loan funded by a facility is the amount of interest that we expect to earn from the loan (taking into account the chance of a default), minus the expected loss from a default, minus the interest that we pay to the bank to use their facility:<\/em><\/p>\n<p>expected_yield =<\/p>\n<p>(1 &#8211; default_likelihood) * loan_interest_rate * amount<\/p>\n<ul>\n<li>default_likelihood * amount<\/li>\n<li>facility_interest_rate * amount<\/li>\n<\/ul>\n<h4><strong>Guarantees<\/strong><\/h4>\n<p style=\"text-align: justify;\">Our FP&amp;A team has been hard at work trying to negotiate good facility deals with our banking partners. They have guaranteed us that the following constraints hold:<\/p>\n<ol>\n<li style=\"text-align: justify;\">We can fund all the loans by processing them in the order that they are received and assigning each loan to the cheapest facility that can accommodate that loan legally (i.e. satisfying all the required covenants and not exceeding the facility\u2019s capacity). Note: depending on your ordering of facilities with an equal interest rate, you may be unable to assign the last loan (#425) of the large data set. This is OK.<\/li>\n<li style=\"text-align: justify;\">The expected yield of funding any loan with any facility is always nonnegative.<\/li>\n<\/ol>\n<h4><strong>Deliverables<\/strong><\/h4>\n<p style=\"text-align: justify;\">Your program should consume the input data and attempt to fund each loan with a facility. Unfunded loans are ignored by our system &#8212; they will earn no interest, nor will they lose money if they default. Your program should be streaming, meaning it that it should process loans in the order that they are received and not use future loans to determine how the current loan should be funded.<\/p>\n<p style=\"text-align: justify;\">Please include instructions on how to run (and build, if necessary) your code. Your program should produce two output files:<\/p>\n<h3><strong>assignments.csv<\/strong><\/h3>\n<p>Each row in this file describes a loan assignment.<\/p>\n<table style=\"height: 16px;\" width=\"796\">\n<tbody>\n<tr>\n<td width=\"208\"><strong>Field<\/strong><\/td>\n<td width=\"208\"><strong>Type<\/strong><\/td>\n<td width=\"208\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"208\">loan_id<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The ID of the loan.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">facility_id<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">If the loan is funded, the ID of its facility; otherwise, empty.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h4><strong>yields.csv<\/strong><\/h4>\n<p>Each row in this file describes the expected yield of a facility.<\/p>\n<table style=\"height: 5px;\" width=\"794\">\n<tbody>\n<tr>\n<td width=\"208\"><strong>Field<\/strong><\/td>\n<td width=\"208\"><strong>Type<\/strong><\/td>\n<td width=\"208\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"208\">facility_id<\/td>\n<td width=\"208\">integer<\/td>\n<td width=\"208\">The ID of the facility.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"height: 90px;\" width=\"793\">\n<tbody>\n<tr>\n<td width=\"208\">expected_yield<\/td>\n<td width=\"208\">int<\/td>\n<td width=\"208\">The expected yield of the facility, rounded to the nearest cent. This is defined as the sum of the expected yields for all the loans in the facility.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">After completing a working code solution, you should include a write-up answering the following questions to the best of your ability:<\/p>\n<ol style=\"text-align: justify;\">\n<li>How long did you spend working on the problem? What did you find to be the most difficult part?<\/li>\n<li>How would you modify your data model or code to account for an eventual introduction of new, as-of-yet unknown types of covenants, beyond just maximum default likelihood and state restrictions?<\/li>\n<li>How would you architect your solution as a production service wherein new facilities can be introduced at arbitrary points in time. Assume these facilities become available by the finance team emailing your team and describing the addition with a new set of CSVs.<\/li>\n<li>Your solution most likely simulates the streaming process by directly calling a method in your code to process the loans inside of a for a loop. What would a REST API look like for this same service? Stakeholders using the API will need, at a minimum, to be able to request a loan be assigned to a facility, and read the funding status of a loan, as well as query the capacities remaining in facilities.<\/li>\n<li>How might you improve your assignment algorithm if you were permitted to assign loans in batch rather than streaming? We are not looking for code here, but pseudo-code or description of a revised algorithm appreciated.<\/li>\n<li>Discuss your solution\u2019s runtime complexity.<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Feel free to include any additional comments in your write-up.<\/p>\n<p style=\"text-align: justify;\">You should send us a folder containing the source code to your program, the output files produced by your program on the \u2018large\u2019 data set, as well as your analysis.<\/p>\n<h4><strong>Evaluation<\/strong><\/h4>\n<p style=\"text-align: justify;\">Your program will be evaluated based on the following criteria, in decreasing order of importance:<\/p>\n<ol style=\"text-align: justify;\">\n<li><em>Correctness <\/em>\u2013 Does the assignment produced by your program satisfy all the required covenants? Does the assignment stay within each facility\u2019s capacity?<\/li>\n<li><em>Clarity <\/em>\u2013 Is your code well-organized and easy to read?<\/li>\n<li><em>Extensibility \u2013 <\/em>Is your solution architected in a manner that makes it easy to collaborate with multiple engineers, and allow them to add and modify features in a consistent, testable way?<\/li>\n<\/ol>\n<h4 style=\"text-align: justify;\"><strong>Final Notes and Suggestions<\/strong><\/h4>\n<p style=\"text-align: justify;\"><strong>Important! Please read carefully<\/strong>:<\/p>\n<ul style=\"text-align: justify;\">\n<li><em>We strongly suggest first implementing a simple, well-written, correct, and (reasonably) performant program before attempting to optimise it further.<\/em><\/li>\n<li>If you are in a time pinch, it should take you at most 2-3 hours to write a minimal working program and some thoughtful analysis. If you have more time and are confident in your working solution, we encourage you to elaborate on your solution to showcase your architecture and code organization skills, possibly implementing some of your ideas from the write-up questions. If you do expand on your solution after completing the basic requirements, consider using git to commit working checkpoints, in order for us to see your progress and give credit for past versions if the final version does not pan out.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">More Tips:<\/p>\n<ul style=\"text-align: justify;\">\n<li>Unlike in many other coding challenges, your program\u2019s clarity and efficiency are more important than its optimality. Maximising profit, in this case, is an open problem, so we don\u2019t suggest spending a lot of time coming up with neat heuristics before actually writing a working program. (This is also why we have given you a simple heuristic that is guaranteed to assign all the loans without losing money on any loan.)<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">You may use any language you like. Using a high-level scripting language will probably allow the most rapid progress. You may also use any external libraries that you wish \u2013 this will likely be helpful for parsing CSV files in some languages \u2013 but you really shouldn\u2019t need to use anything fancy (e.g. databases, multithreading, or LP solvers).<\/p>\n<script type=\"text\/javascript\" charset=\"utf-8\" src=\"http:\/\/w.sharethis.com\/widget\/?wp=6.2.9\"><\/script>","protected":false},"excerpt":{"rendered":"<p>Online Programming Assignment Help by professionals programmers of Case Study Help. We cover Python, PHP, JAVA, AJAX, C, C++, C#, Databases, SQL, MATLAB, ASP.Net Assignments at affordable price. Background At Affirm, we borrow money from our banking partners through debt facilities. In turn, we use these facilities to extend loans to customers. A banking partner [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2042],"tags":[2046,2047,2044,2045,2050,2048,2049,2043],"_links":{"self":[{"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/posts\/4306"}],"collection":[{"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/comments?post=4306"}],"version-history":[{"count":2,"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/posts\/4306\/revisions"}],"predecessor-version":[{"id":4308,"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/posts\/4306\/revisions\/4308"}],"wp:attachment":[{"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/media?parent=4306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/categories?post=4306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/casestudyhelp.com\/sample-questions\/wp-json\/wp\/v2\/tags?post=4306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}