-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
71 lines (52 loc) · 2.17 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
title: "README"
author: "Andrew Plowright"
date: "April 5, 2019"
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures"
)
library(questradeOFX)
```
## Overview
This package was created to facilitate the conversion of Questrade account statements in Excel to OFX format, which can then be read into Microsoft Money. This operation should be performed in three steps:
1. Format the statement generated by Questrade using `format_statement`
2. Review the statement and make changes where necessary
3. Convert to OFX using `write_OFX` and then import into Microsoft Money
## Example
Get the file paths for your Questrade statement and a table of your funds. Two sample files are provided with this package.
```{r}
stmt_path <- system.file("extdata", "sample_statement.xlsx", package = "questradeOFX")
fund_path <- system.file("extdata", "sample_funds.csv", package = "questradeOFX")
```
View the funds table. This _data.frame_ must have the name and symbol of all the funds in your Questrade statement.
```{r}
# Read CSV file of funds
fund_table <- read.csv(fund_path)
fund_table
```
Read the statement and then use `format_statement` to prepare it for conversion to OFX. This function automatically formats the date/times correctly, identifies the types of transactions and creates unique transaction IDs.
```{r}
# Read statement from Excel file
stmt <- xlsx::read.xlsx(stmt_path,1, stringsAsFactors = F)
# Format statement correctly
stmt <- format_statement(stmt)
stmt
```
Be sure to carefully review this table and make adjustments when necessary. Questrade is inconsistent with the use of stock symbols, so make sure they match what is contained in `fund_table`.
```{r}
# Replace incorrect symbols
stmt[stmt$symbol == "VUN", "symbol"] <- "VUN.TO"
stmt[stmt$symbol == "XEC", "symbol"] <- "XEC.TO"
```
Once the statement is reviewed, set the statement's date and save to an OFX file. This can now be imported into Microsoft Money.
```{r, eval = FALSE}
# Get statement date from file
stmt_date <- file.info(stmt_path)[,"mtime"]
# Write OFX file to disk
write_OFX(stmt, "new_statement.ofx", stmt_date, fund_table)
```