Last active
October 9, 2020 04:27
-
-
Save xaviershay/9b3a586a1884a18b81c2041984d0ee95 to your computer and use it in GitHub Desktop.
contribution-vs-interest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://vega.github.io/schema/vega/v5.json", | |
"description": "Plots two functions using a generated sequence.", | |
"width": 600, | |
"height": 300, | |
"title": "Figure out what monthly contribution is equivalent to what savings rate", | |
"data": [{ | |
"name": "month", | |
"values": [ | |
], | |
"transform": [ | |
{"type": "sequence", "start": 0, "stop": 200, "step": 10, "as": "c"}, | |
{ | |
"type": "formula", | |
"expr": "datum.c*months+balance", | |
"as": "v" | |
}, | |
{ | |
"type": "formula", | |
"expr": "(pow(datum.v / balance, 1/months)-1)*12*100", | |
"as": "y" | |
}, | |
{ | |
"type": "formula", | |
"expr": "1.1", | |
"as": "comparison" | |
}, | |
{ | |
"type": "formula", | |
"expr": "datum.y <= 10 ? true : false", | |
"as": "defined" | |
}, | |
{ | |
"type": "formula", | |
"expr": "datum.y <= 10 ? datum.y : 10", | |
"as": "y" | |
} | |
] | |
}], | |
"signals": [ | |
{ | |
"name": "balance", | |
"value": 1000, | |
"description": "How much money you start with", | |
"bind": {"input": "range", "min": 10, "max": 20000, "step": 1, "debounce": 10} | |
}, | |
{ | |
"name": "months", | |
"value": 60, | |
"description": "How many months you save for", | |
"bind": {"input": "range", "min": 1, "max": 240, "step": 1, "debounce": 10} | |
} | |
], | |
"scales": [ | |
{ | |
"name": "x", | |
"type": "point", | |
"range": "width", | |
"domain": {"data": "month", "field": "c"} | |
}, | |
{ | |
"name": "y", | |
"type": "linear", | |
"range": "height", | |
"nice": true, | |
"zero": true, | |
"domain": {"data": "month", "field": "y"}, | |
"domainMax": 10 | |
} | |
], | |
"axes": [ | |
{"orient": "bottom", "scale": "x", "title": "Monthly Contribution ($)"}, | |
{"orient": "left", "scale": "y", "title": "Equivalent Interest Rate (% p.a.)"} | |
], | |
"marks": [ | |
{ | |
"type": "line", | |
"from": {"data": "month"}, | |
"stroke": "red", | |
"encode": { | |
"update": { | |
"x": {"scale": "x", "field": "c"}, | |
"y": {"scale": "y", "field": "y"}, | |
"strokeWidth": {"value": 2}, | |
"defined": {"field": "defined"} | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment