func simulateMortgage() { mortgage := set.Uniform(time.Now(), set.Month, 500, 150000) payments := set.Mimic(mortgage, func(set.Event) float64 { return -10000 }) net := set.Consolidate(mortgage, set.Cumulative(payments)) interest := set.Compound(net, 0.05, set.Year) fracInterest := set.Mult(interest, 1.0/1200) balance := set.TrimBelow(set.Consolidate(net, set.Cumulative(interest)), 0) fmt.Printf("net: \n%v", net[:len(balance)]) fmt.Printf("interest: \n%v", interest[:len(balance)]) fmt.Printf("fracInterest: \n%v", fracInterest[:len(balance)]) fmt.Printf("balance: \n%v", balance) }
func simulateLife() { now := time.Now() // income salary := set.PieceWise(set.Month, set.Uniform(now, set.Month, 12*3, 75e3/12), set.Uniform(now, set.Month, 12*4, 93e3/12), set.Uniform(now, set.Month, 12*9, 112e3/12), set.Uniform(now, set.Month, 12*9, 136e3/12), set.Uniform(now, set.Month, 12*20, 40e3/12), ) // expenses incomeTax := set.Mult(salary, -0.4) propertyTax := set.Uniform(now, set.Year, 100, 3000) gas := set.PieceWise(set.Month, set.Uniform(now, set.Month, 24, 150), set.Uniform(now, set.Month, 1200, 350), ) food := set.PieceWise(set.Month, set.Uniform(now, set.Month, 12*4, 200), set.Uniform(now, set.Month, 12*4, 400), set.Uniform(now, set.Month, 12*4, 600), set.Uniform(now, set.Month, 12*4, 400), set.Uniform(now, set.Month, 12*50, 200), ) misc := set.PieceWise(set.Month, set.Uniform(now, set.Month, 12*25, 500), set.Uniform(now, set.Month, 12*100, 1000), ) // allocations net := set.Cumulative(set.Append(salary, gas, food, misc, incomeTax, propertyTax)) investments := set.Mimic(net, func(e set.Event) float64 { return max(0, e.Amount-25000) }) savings := set.Consolidate(net, set.Mult(investments, -1)) // interest interest := set.Compound(investments, 0.03, set.Year) netWorth := set.Consolidate(net, set.Cumulative(interest)) _, _ = savings, netWorth //fmt.Printf("salary: \n%v", salary) //fmt.Printf("incomeTax: \n%v", incomeTax) //fmt.Printf("gas: \n%v", gas) //fmt.Printf("food: \n%v", food) //fmt.Printf("misc: \n%v", misc) fmt.Printf("savings: \n%v", savings) //fmt.Printf("investments: \n%v", investments) //fmt.Printf("interest: \n%v", interest) //fmt.Printf("netWorth: \n%v", netWorth) //fmt.Printf("tot interest: %v\n", set.Sum(interest)) }