Skip to content

An app to play with finance APIs, such as Personal Capital and YNAB.

Notifications You must be signed in to change notification settings

AdamGagorik/FinanceScripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Finance Scripts

This is a set of scripts to download and analyze finance data.

The aim is to...

  1. download daily holdings automatically
  2. download historical data
  3. update YNAB accounts

Setup

Clone the repository.

Create a conda environment.

conda env create -f environment.yml
conda activate FinanceScripts

Credentials

Set the following environment variables.

PC_PASSWORD=[Your PC Password]
PC_USERNAME=[Your PC Username]
YNAB_APIKEY=[Your YNAB apikey]
  • These variables may be set in a filed called .env in the run directory.
  • Please note that the script will pause for 2-factor authentication on the 1st run.

Example

import pandas as pd
import dataclasses
import datetime


import finance.apis
import finance.scrapers


if __name__ == '__main__':
    # create API handler instance
    handler = finance.apis.pcap.PCAPHandler()

    # fetch all transaction objects
    transactions = finance.scrapers.pcap.TransactionsScraper(handler, t0=datetime.datetime.now(), dt=1)
    for transaction in transactions.objects:
        print(transaction)

    # create a dataframe from any dataclass based object
    tframe: pd.DataFrame = pd.DataFrame(dataclasses.asdict(t) for t in transactions.objects)

Apps

python -m scraper.pcap.apps.marketvalue

A script to download the market value for an account. The script is given a starting date and a time period freqency. The rows of the resulting dataframe will display the market value at the timestamps.

cd ./workspace
conda activate FinanceScripts
python -m scraper.apps.pcap.marketvalue --start 2019-12-01 --freq W

For example, the following frame will be produced.

Vanguard : Roth IRA
                                   Date   Payee Memo  Amount
0      2019-12-01 23:59:59.999999+00:00  Market       123.45
1      2019-12-08 23:59:59.999999+00:00  Market       678.90
2      2019-12-15 23:59:59.999999+00:00  Market       123.45
3      2019-12-22 23:59:59.999999+00:00  Market       678.90
4      2019-12-29 23:59:59.999999+00:00  Market       123.45
Total                                                1728.15

Filling Logic

Fill in missing values by creating YAML based rule files in the run directory.

  • The rules are a list ofwhere and value mappings.
    • If all items from the where mapping match an instance's attributes...
      • The items from the value mapping will be set on the instance.

fillna-holdings.yaml

rules:
  - where:
      cusip: 'XXXXXXXXX'
      userAccountId: 00000000
    value:
      accountName: 'RothIRA'
      ticker: 'VTSAX'

About

An app to play with finance APIs, such as Personal Capital and YNAB.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published