Simulate personal finances over time
Project description
fisi
Financial Simulator (fisi) is a framework to explicitly simulate personal finances over time, including revenues, expenses, assets, and events (e.g. buying a house, or quitting your job), automatically accounting for taxes, inflation, and asset growth.
Simulations are based on US tax law, and calculations are performed on a year-by-year basis.
keywords: financial planning, early retirement, life planning
Installation
Install with pip:
pip install fisi
Usage
Content below comes from the walkthrough notebook.
Specify revenues and expenses
Revenues have a fixed value, and expenses grow with a fixed inflation rate. The state is used to calculate taxes.
from fisi.flows import Expense, TaxableIncome
salary = TaxableIncome(name="Salary", initial_value=70_000, state="MA")
housing = Expense(name="Housing", initial_value=20_000, inflation_rate=0.02)
cost_of_living = Expense(name="Cost of Living", initial_value=20_000, inflation_rate=0.03)
Specify assets
from fisi.assets import Asset
cash = Asset(name="Cash", initial_value=5_000, growth_rate=0.01, cap_value=10_000)
from fisi.assets import PretaxAsset, TaxableAsset
from fisi.growth import GrowthType
bonds = TaxableAsset(
name="Bonds",
initial_value=10_000,
allocation=0.1,
growth_type=GrowthType.BONDS,
seed=42
)
stocks = TaxableAsset(
name="Stocks",
initial_value=20_000,
allocation=0.9,
growth_type=GrowthType.STOCKS,
seed=42
)
_401k = PretaxAsset(
name="401k",
initial_value=10_000,
growth_type=GrowthType.STOCKS,
seed=42
)
Alternatively, see TaxablePortfolio or PretaxPortfolio in fisi.assets, to simulate a mix of stocks and bonds with automatic rebalancing.
Specify events acting on any of your revenues, expenses, or assets
Events include actions on methods of any of your financial objects; say you want to quit your job, after which your salary goes to 0, and you now have to pay for health insurance.
health_insurance = Expense(name="Health Insurance", initial_value=0, inflation_rate=0.03)
quit_job = Event(
name="Quit Job",
year=2040,
actions=[
Action(
target=salary,
action="update_base_values",
params={"new_base_values": 0, "duration": 100},
),
Action(
target=health_insurance,
action="update_base_values",
params={"new_base_values": 2_000, "duration": 100},
),
],
)
Simulate your finances over a number of years
In each year, the order of operations is:
- Balance cash flow.
- Negative cash flow acumulates as debt.
- Positive cash flow is available to be distributed among assets.
- Invest in pre-tax assets.
- Tax revenues.
- Distribute cash flow, by investing in assets or paying off debt.
- Grow assets.
- Add inflation to expenses.
from fisi.model import FinancialModel
model = FinancialModel(
revenues=[salary],
expenses=[housing, cost_of_living, health_insurance],
assets=[cash, bonds, stocks, _401k],
events=[quit_job],
duration=60, # years
number_of_simulations=1_000,
)
model.run()
And plot the results
ax = model.plot_all();
Currently, financial objects are modified in-place during simulations, so you should create new instances for different simulations; you can also plot each of them individually:
salary.plot()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fisi-0.1.1.tar.gz.
File metadata
- Download URL: fisi-0.1.1.tar.gz
- Upload date:
- Size: 122.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81c0ebcf5e65b383c470cfff3b22aaf099f63c98d73a642a34032c8ab3467160
|
|
| MD5 |
0c4152a49afeb835f51cc454ea538c49
|
|
| BLAKE2b-256 |
35126d673c71b16edd53e482fd96236225fb0fcb7899178a060599cc12783667
|
File details
Details for the file fisi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fisi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a64b96dfdeca80f41156cd29c30ede92661b9e793b104f3811e27c7c872ce03
|
|
| MD5 |
b16f289fd7c000f128789fe13af168ee
|
|
| BLAKE2b-256 |
3d0d6c71919edbe349bddea97d70cea281bd76accddb7accb0daaac333084a70
|