Anyone use Python to analyze their finances?

Discuss all general (i.e. non-personal) investing questions and issues, investing news, and theory.
FamilyGuy87
Posts: 50
Joined: Tue Feb 18, 2014 1:26 pm

Re: Anyone use Python to analyze their finances?

Post by FamilyGuy87 »

ScaledWheel wrote: Mon Dec 09, 2019 3:51 pm
FamilyGuy87 wrote: Mon May 08, 2017 8:31 am I use Python for my personal budget and investing exclusively. I started with excel and over the years I have migrated to using only python. I find it's more robust and less prone to errors. My tool has a python backend which uses Pandas and Flask. For the frontend I use HTML based frameworks such as angular and dc.js.
Wondering if you're still doing this, and if so, how it's working. I've been pretty disappointed with most budget/portfolio apps and am looking to perhaps roll my own.
I still use the same python tool. I am very detail oriented and this tool gives me the flexibility to track everything that I need. Since it is my own tool it allows me to add features as time goes on.

I also love the idea of using GnuCash with the piecash module.
edu_lk
Posts: 1
Joined: Sun Apr 05, 2020 9:45 am

Re: Anyone use Python to analyze their finances?

Post by edu_lk »

FamilyGuy87 wrote: Mon May 08, 2017 8:31 am I use Python for my personal budget and investing exclusively. I started with excel and over the years I have migrated to using only python. I find it's more robust and less prone to errors. My tool has a python backend which uses Pandas and Flask. For the frontend I use HTML based frameworks such as angular and dc.js.

When I combine both of these I can create very cool tools. I can keep track of all my transactions and display the transactions in very cool ways such as the sankey method as seen below.


It also automatically downloads all the investment price data using pandas datareader and calculates Betas and Alphas for my portfolio. You can see the image below. I also used to calculate the efficient frontier and display that information also. But I did not find that as useful for personal investing. Since I keep track of my transactions and portfolio prices, I can calculate my IRR and other items. I have a dashboard page that shows all that information in detail.


Finally, I can create different goals and create projections. The one below if for college savings.

I think python is a really easy tool to be able to accomplish all three items in the OP.

FamilyGuy
Hi FamilyGuy,

I saw your post and thought it was really interesting the tool you developed using Python. Are you still using it? If possible, could you make a template available?
I would like to integrate my expenses & income with my portfolio. Should I create two CSV and make Python read both of them or only one CSV would be enough? I am kind confused how I am going to connect both of them because in my portfolio I am willing to do further analysis such as monthly return, risk, asset classification, rebalance, projections... so I believe integrating in one single CSV would not be a good idea. What do you think?

Thank you!
Eduardo
hayesfj
Posts: 54
Joined: Sat Dec 26, 2009 8:39 am

Re: Anyone use Python to analyze their finances?

Post by hayesfj »

This thread has not been updated in a while, and I wanted to see if others are using Python. I have a background in coding, Excel, VBA, and Google Sheets. I started learning Python about four months ago as a hobby. I mainly have been using data from sites such as Yahoo, multpl, GuruFocus, SimFin, and EDGAR and using Pandas, Numpy, and Matplotlib. I primarily use Google Colab as my coding environment as I like the integration with Google Drive and Google Sheets. I would like to know if others in the forum have a similar interest.

Thanks!
kaesler
Posts: 243
Joined: Mon Mar 12, 2007 4:53 pm
Location: Boston, MA

Re: Anyone use Python to analyze their finances?

Post by kaesler »

Not Python but perhaps of interest. I’ve written code for calculating Federal and State (MA) taxes which can be called from a Google sheet. It is written in Purescript.

If there is interest I could possibly make it available for others to use.
User avatar
LadyGeek
Site Admin
Posts: 95696
Joined: Sat Dec 20, 2008 4:34 pm
Location: Philadelphia
Contact:

Re: Anyone use Python to analyze their finances?

Post by LadyGeek »

^^^ If anyone has open source software they'd like to share, I'll put it in the wiki. See: Using open source software for portfolio analysis

Short scripts can go in the wiki directly. Otherwise, please point to the source code (GitHub, etc.). You can also upload the source to Google Drive and share the link.

I suggest discussing languages other than python in this thread: [Wiki] - Using open-source software for portfolio analysis
Wiki To some, the glass is half full. To others, the glass is half empty. To an engineer, it's twice the size it needs to be.
User avatar
Raraculus
Posts: 339
Joined: Sat Jul 20, 2019 10:43 am

Re: Anyone use Python to analyze their finances?

Post by Raraculus »

LadyGeek wrote: Mon Jun 21, 2021 7:27 am ^^^ If anyone has open source software they'd like to share, I'll put it in the wiki. See: Using open source software for portfolio analysis
Wow, I guess there's a wiki on just about anything! Thank you for sharing that. I'm trying to use R for backtesting some investment strategies.
GLState
Posts: 216
Joined: Wed Feb 15, 2017 9:38 am

Re: Anyone use Python to analyze their finances?

Post by GLState »

Note for anyone trying to run Hedgefundie's "Risk parity strategy using 3x leveraged ETFs" code found in the Wiki:

Using the provided code in recent version of R will generate an error:
Error in c.xts(c(NA, NA), c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, :
zero-length vectors with non-zero-length index are not allowed

This is because the tidyverse package loads the dplyr package which has its own lag function.

We have to add "stats::" wherever the lag function is in the code to use the stats lag rather than dplyr lag

# long 100% spy at signal
spSig <- stats::lag(signal, 2) * spyRets

# long 100% upro at signal
upSig <- stats::lag(signal, 2) * uproRets

# go 50/50 upro/tmf at signal
uptmfSig <- stats::lag(signal, 2)*.5*uproRets + stats::lag(signal, 2)*.5*tmfRets

Here's a explanation of the problem on StackOverFlow:
https://stackoverflow.com/questions/628 ... ime-series
GLState
Posts: 216
Joined: Wed Feb 15, 2017 9:38 am

Re: Anyone use Python to analyze their finances?

Post by GLState »

For those that are interested in a deeper dive into Quantitative Finance using R, MIT has a grad level course coming up on July 7th, 2021 on EdX.
https://www.edx.org/course/mathematical ... ve-finance
MathWizard
Posts: 6561
Joined: Tue Jul 26, 2011 1:35 pm

Re: Anyone use Python to analyze their finances?

Post by MathWizard »

I've been a programer since the punch arc and assembly days, and have been a consultant for decades

I first wrote analysis programs in a high level language, then realized that anyone who needed to take the over for me would prefer a simple Excel spreadsheet with how much to take out of each account with the intent to be tax efficient.

That is what I use now.

The largest part of any changes long lasting computer program is maintenance and updating. This is usually done by somebody who did not write the program.

Make this as simple as possible and document everything within the spreadsheet.
User avatar
NAVigator
Posts: 2545
Joined: Tue Feb 27, 2007 6:24 am
Location: Iowa

Re: Anyone use Python to analyze their finances?

Post by NAVigator »

This thread has a spectrum of experience with Python from beginner to expert. For those at the starting line, there is a FREE Kindle book called, "Python Programming: A Beginner's Guide to Learn Python in 7 Days" by Ramsey Hamilton. Today is Prime Day.
"I was born with nothing and I have most of it left."
User avatar
Elric
Posts: 731
Joined: Fri Dec 07, 2018 11:23 pm
Location: Virginia
Contact:

Re: Anyone use Python to analyze their finances?

Post by Elric »

Not very Bogleheads, but I used Python and Pandas to look at an aspect of structured notes a few years back. You can read about what I did, with a link to the code, here: https://www.mcgurrin.info/robots/343/

Note: Financially I did fine on these (although I don't hold any now, nor do I have any intention of buying more in the future). But as the market was increasing, they kept getting called, which wasn't meeting my goals.
"No man is free who must work for a living." (Illya Kuryakin)
masrepus
Posts: 126
Joined: Fri Apr 24, 2015 12:14 pm

Re: Anyone use Python to analyze their finances?

Post by masrepus »

Does anyone have a method to get share information from Fidelity? I simply want to get the number of shares in my accounts that I can use in my google sheets to update net worth. I haven't found an API that is open. Worst case I create a scrape function. But an API would be easiest combined with Python.
lws
Posts: 831
Joined: Tue Apr 25, 2017 6:12 pm

Re: Anyone use Python to analyze their finances?

Post by lws »

Playing with Python is one of my current hobbies.
Learned a bit of Python to do science/engineering calculations for volunteer work and liked it.
Use LibreCalc for finances.
User avatar
JupiterJones
Posts: 3624
Joined: Tue Aug 24, 2010 3:25 pm
Location: Nashville, TN

Re: Anyone use Python to analyze their finances?

Post by JupiterJones »

I've been tracking my expenses more closely lately, and put everything in a spreadsheet once a month.

As part of this, I download CSV files of transactions for multiple credit cards. I then used to do a manual munging/reformatting/merging step, but I realized that all that would be perfect for a Python script. So I whipped one up and have been using it since.

I'm not sure if the time it is saving me has yet broken even with the time it took me to write it, but as my fellow programmers know, that's not the point at all. :D
"Stay on target! Stay on target!"
User avatar
quantAndHold
Posts: 10141
Joined: Thu Sep 17, 2015 10:39 pm
Location: West Coast

Re: Anyone use Python to analyze their finances?

Post by quantAndHold »

masrepus wrote: Sat Oct 23, 2021 11:51 am Does anyone have a method to get share information from Fidelity? I simply want to get the number of shares in my accounts that I can use in my google sheets to update net worth. I haven't found an API that is open. Worst case I create a scrape function. But an API would be easiest combined with Python.
Not specifically Fidelity, but you should be able to download the qfx file, then use either the ofxparse or ofxtools package to work with it. I use ofxtools to parse files I download from Vanguard. OFX is a complicated format, so it wasn’t as trivial as I would have liked, but unlike screen scraping, the download is stable enough that I wrote the code several years ago and haven’t had to modify it to deal with any changes to the file since then.
Sam_957
Posts: 164
Joined: Tue Oct 27, 2020 7:04 pm
Location: USA

Re: Anyone use Python to analyze their finances?

Post by Sam_957 »

There are quite a few books on finance and python but this one looks interesting

https://learning.oreilly.com/library/vi ... 484238028/
My other vehicle is an index fund.
Post Reply