Skip to content

Instantly share code, notes, and snippets.

@htrajan
htrajan / search.java
Created February 12, 2018 22:27
Binary Home Searching
@Inject BinarySearchSolver solver;
...
Function<Double, Affordability> affordabilityFn ...; // our mapping function that takes a number and returns an affordability
Function<Affordability, Boolean> manageableTargetTest = affordability -> affordability.getOrdinal() <= MANAGEABLE.getOrdinal();
double maxManageablePrice = solver.solveForMaxValuePassingTargetTest(
lowerBound,
@htrajan
htrajan / homeAffordability
Last active February 12, 2018 23:08
Home Affordability
{
“affordability”: “MANAGEABLE”,
“mortgageAffordability”: “MEDIUM”,
“dtiRatio”: 0.32,
“desiredDtiRatio”: 0.29,
“downPaymentRatio”: 0.2,
“desiredDownPaymentRatio”: 0.15,
“retirementImpact”: “NONE”,
“mortgageWillForeclose”: false
}
Map<Account, Double> getSavingsRecommendations(
double savingsToAllocate,
Collection<Account> accounts,
Collection<Goal> goals);
public class AccountSavingsRecommender {
@Inject RetirementGoalSavingsAllocator retirementAllocator;
@VisibleForTesting
Map<Goal, Double> computePvByGoal(Collection<Goal> goals) {...}
……
@VisibleForTesting
public class AccountSavingsRecommenderTest {
private final Mockery mockery = new Mockery();
private final RetirementGoalSavingsAllocator retirementAllocator = mockery.mock(RetirementGoalSavingsAllocator.class);
@Test
public void computePvByGoal_retirement() {
Account retirementAccount = TestAccountFactory.exampleRetirementAccount();
mockery.checking(new Expectations() {{
oneOf(retirementAllocator).getAccountForPvCalculation();
public class AccountSavingsRecommenderIntegrationTest {
private static final LocalDate today = new LocalDate(2018, 6, 25);
private AccountSavingsRecommender getRecommender() {
AccountSavingsRecommender recommender = new AccountSavingsRecommender();
RetirementGoalSavingsAllocator retirementAllocator = new RetirementGoalSavingsAllocator();
retirementAllocator.today = today;
RetirementAccountSelector accountSelector = new RetirementAccountSelector();
Account realisticRetirementAccount = RetirementAccount.builder()
.withInvestedBalance(34_332.67)
.withCashBalance(2_190.95)
.withType(Type.R_401_K)
.withExpectedAccountReturn(0.057)
.build();
{
"banner": {"institutions": ["CHASE"], "text": "Linking in progress", "button": "Link more"},
"hub": [{"institution": "CHASE", "title": "Linking in progress", "subtitle": "This usually takes about 1 minute for Chase."}]
}
{
"actionType": "ACTION",
"title": "Check your credentials",
"subtitle": "Looks like an incorrect username or password for Vanguard.",
"cta": "Try again"
}