vapore 0.6.3

Vangaurd portfolio rebalancing algorithm
Documentation
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
use clap::{crate_version, App, Arg};
use time::OffsetDateTime;

/// Args struct holds all CLI argument values passed
///
/// # Panic
///
/// Panics if percent stock and bond do not add up to 100
#[derive(Clone)]
pub struct Args {
    pub csv_path: String, // Path of the downloaded vanguard transactions file
    pub retirement_year_option: Option<i32>,
    pub percent_stock_brokerage: f32, // Percent of stocks for brokerage account
    pub percent_bond_brokerage: f32,  // Percent of bonds for brokerage account
    pub percent_stock_retirement_option: Option<f32>, // Percent of stock for retirement account
    pub percent_bond_retirement_option: Option<f32>, // Percent bond for retirement account
    pub brokerage_cash_add: f32,      // Amount of cash added to brokerage account
    pub brokerage_us_stock_add: f32,
    pub brokerage_us_bond_add: f32,
    pub brokerage_int_stock_add: f32,
    pub brokerage_int_bond_add: f32,
    pub traditional_cash_add: f32,
    pub traditional_us_stock_add: f32,
    pub traditional_us_bond_add: f32,
    pub traditional_int_stock_add: f32,
    pub traditional_int_bond_add: f32,
    pub roth_cash_add: f32,
    pub roth_us_stock_add: f32,
    pub roth_us_bond_add: f32,
    pub roth_int_stock_add: f32,
    pub roth_int_bond_add: f32,
    pub brok_acct_option: Option<u32>, // Vanguard brokerage account number
    pub trad_acct_option: Option<u32>, // Vanguard traditional IRA account number
    pub roth_acct_option: Option<u32>, // Vanguard roth IRA account number
    pub output: bool,                  // Whether or not to output calculations to a txt file
    pub age_option: Option<u32>,        // age
    pub distribution_year: u32,        // age
    pub distribution_table_path: String,
    pub use_brokerage_retirement: bool,
}

impl Args {
    pub fn new() -> Self {
        let this_year = OffsetDateTime::now_utc().year().to_string();
        let args = App::new("Vanguard Stock Adjustment")
            .version(crate_version!())
            .author("Rory Coffey <coffeyrt@gmail.com")
            .about("Return the number of vanguard stock that should be bought")
            .arg(
                Arg::with_name("Vanguard-Download")
                    .required(true)
                    .help("CSV download file from Vanguard with holdings"),
            )
            .arg(
                Arg::with_name("min-distribution")
                    .long("min-distribution")
                    .takes_value(true)
                    .help("Path of the minimum distribution csv from the IRS"),
            )
            .arg(
                Arg::with_name("retirement-year")
                    .long("retirement-year")
                    .short("Y")
                    .takes_value(true)
                    .help("Retirment year in the format of YYYY"),
            )
            .arg(
                Arg::with_name("percent-bond-brokerage")
                    .long("bond-percent-brokerage")
                    .takes_value(true)
                    .default_value("40")
                    .help("Percentage to allocate in bonds in the brokerage account"),
            )
            .arg(
                Arg::with_name("percent-stock-brokerage")
                    .long("stock-percent-brokerage")
                    .takes_value(true)
                    .default_value("60")
                    .help("Percentage to allocate in stocks in the brokerage account"),
            )
            .arg(
                Arg::with_name("percent-bond-retirement")
                    .long("bond-percent-retirement")
                    .takes_value(true)
                    .help("Percentage to allocate in bonds in the retirement account"),
            )
            .arg(
                Arg::with_name("percent-stock-retirement")
                    .long("stock-percent-retirement")
                    .takes_value(true)
                    .help("Percentage to allocate in stocks in the retirement account"),
            )
            .arg(
                Arg::with_name("add-cash-brokerage")
                    .long("adjust-cash-brokerage")
                    .short("B")
                    .allow_hyphen_values(true)
                    .takes_value(true)
                    .default_value("0")
                    .help("Amount of cash added to or withdraw from the brokerage account"),
            )
            .arg(
                Arg::with_name("add-us-stock-brokerage")
                    .long("add-us-stock-brokerage")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of brokerage US stock held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-us-bond-brokerage")
                    .long("add-us-bond-brokerage")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of brokerage US bond held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-int-stock-brokerage")
                    .long("add-int-stock-brokerage")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of brokerage international stock held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-int-bond-brokerage")
                    .long("add-int-bond-brokerage")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of brokerage international bond held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-cash-traditional")
                    .long("adjust-cash-traditional")
                    .short("T")
                    .allow_hyphen_values(true)
                    .takes_value(true)
                    .default_value("0")
                    .help("Amount of cash added to or withdraw from the traditional IRA account"),
            )
            .arg(
                Arg::with_name("add-us-stock-traditional")
                    .long("add-us-stock-traditional")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of traditional IRA US stock held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-us-bond-traditional")
                    .long("add-us-bond-traditional")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of traditional IRA US bond held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-int-stock-traditional")
                    .long("add-int-stock-traditional")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of traditional IRA international stock held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-int-bond-traditional")
                    .long("add-int-bond-traditional")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of traditional IRA international bond held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-cash-roth")
                    .long("adjust-cash-roth")
                    .short("R")
                    .allow_hyphen_values(true)
                    .takes_value(true)
                    .default_value("0")
                    .help("Amount of cash added to or withdraw from the roth IRA account"),
            )
            .arg(
                Arg::with_name("add-us-stock-roth")
                    .long("add-us-stock-roth")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of roth IRA US stock held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-us-bond-roth")
                    .long("add-us-bond-roth")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of roth IRA US bond held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-int-stock-roth")
                    .long("add-int-stock-roth")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of roth IRA international stock held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("add-int-bond-roth")
                    .long("add-int-bond-roth")
                    .takes_value(true)
                    .default_value("0")
                    .help("Value of roth IRA international bond held outside of Vanguard.  Used for calculating stock/bond ratios."),
            )
            .arg(
                Arg::with_name("acct-num-b")
                    .long("brokerage-acct")
                    .short("b")
                    .takes_value(true)
                    .required_unless_one(&["acct-num-r", "acct-num-t"])
                    .help("Brokerage account number"),
            )
            .arg(
                Arg::with_name("acct-num-r")
                    .long("roth-acct")
                    .short("r")
                    .requires("retirement-year")
                    .takes_value(true)
                    .required_unless_one(&["acct-num-b", "acct-num-t"])
                    .help("Roth IRA account number"),
            )
            .arg(
                Arg::with_name("acct-num-t")
                    .long("trad-acct")
                    .short("t")
                    .requires("retirement-year")
                    .takes_value(true)
                    .required_unless_one(&["acct-num-b", "acct-num-r"])
                    .help("Traditional IRA account number"),
            )
            .arg(
                Arg::with_name("output")
                    .long("output")
                    .short("o")
                    .takes_value(false)
                    .help("Output to text file in current directory"),
            )
            .arg(
                Arg::with_name("use_brokerage")
                    .long("use-brokerage-retirement")
                    .takes_value(false)
                    .help("Balance the brokerage account as if it is part of the retirement accoutn"),
            )
            .arg(
                Arg::with_name("birth_year")
                    .long("birth-year")
                    .takes_value(true)
                    .help("Birth year is used to calculate minimum distribution"),
            )
            .arg(
                Arg::with_name("distribution_year")
                    .long("distribution-year")
                    .takes_value(true)
                    .default_value(&this_year)
                    .help("Year for which the distribution is to be calculated"),
            )
            .get_matches();

        let csv_path = args.value_of("Vanguard-Download").unwrap().to_string();
        let distribution_table_path = args
            .value_of("min-distribution")
            .unwrap_or_default()
            .to_string();

        let percent_stock_brokerage = args
            .value_of("percent-stock-brokerage")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let percent_bond_brokerage = args
            .value_of("percent-bond-brokerage")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let brokerage_cash_add = args
            .value_of("add-cash-brokerage")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let brokerage_us_stock_add = args
            .value_of("add-us-stock-brokerage")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let brokerage_us_bond_add = args
            .value_of("add-us-bond-brokerage")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let brokerage_int_stock_add = args
            .value_of("add-int-stock-brokerage")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let brokerage_int_bond_add = args
            .value_of("add-int-bond-brokerage")
            .unwrap()
            .parse::<f32>()
            .unwrap();

        let traditional_cash_add = args
            .value_of("add-cash-traditional")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let traditional_us_stock_add = args
            .value_of("add-us-stock-traditional")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let traditional_us_bond_add = args
            .value_of("add-us-bond-traditional")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let traditional_int_stock_add = args
            .value_of("add-int-stock-traditional")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let traditional_int_bond_add = args
            .value_of("add-int-bond-traditional")
            .unwrap()
            .parse::<f32>()
            .unwrap();

        let roth_cash_add = args
            .value_of("add-cash-roth")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let roth_us_stock_add = args
            .value_of("add-us-stock-roth")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let roth_us_bond_add = args
            .value_of("add-us-bond-roth")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let roth_int_stock_add = args
            .value_of("add-int-stock-roth")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let roth_int_bond_add = args
            .value_of("add-int-bond-roth")
            .unwrap()
            .parse::<f32>()
            .unwrap();
        let distribution_year = args
            .value_of("distribution_year")
            .unwrap()
            .parse::<u32>()
            .unwrap();

        let mut retirement_year_option = None;
        if let Some(retirement_year) = args.value_of("retirement-year") {
            retirement_year_option = Some(retirement_year.parse::<i32>().unwrap())
        }
        let mut percent_stock_retirement_option = None;
        if let Some(percent_stock_retirement) = args.value_of("percent-stock-retirement") {
            percent_stock_retirement_option = Some(percent_stock_retirement.parse::<f32>().unwrap())
        }
        let mut percent_bond_retirement_option = None;
        if let Some(percent_bond_retirement) = args.value_of("percent-bond-retirement") {
            percent_bond_retirement_option = Some(percent_bond_retirement.parse::<f32>().unwrap())
        }

        let mut brok_acct_option = None;
        if let Some(brok_acct_str) = args.value_of("acct-num-b") {
            brok_acct_option = Some(brok_acct_str.parse::<u32>().unwrap())
        }
        let mut trad_acct_option = None;
        if let Some(trad_acct_str) = args.value_of("acct-num-t") {
            trad_acct_option = Some(trad_acct_str.parse::<u32>().unwrap())
        }
        let mut roth_acct_option = None;
        if let Some(roth_acct_str) = args.value_of("acct-num-r") {
            roth_acct_option = Some(roth_acct_str.parse::<u32>().unwrap())
        }
        let mut age_option = None;
        if let Some(birth_year) = args.value_of("birth_year") {
            age_option = Some(distribution_year - birth_year.parse::<u32>().unwrap())
        }
        let output = args.is_present("output");
        let use_brokerage_retirement = args.is_present("use_brokerage");
        Args {
            csv_path,
            retirement_year_option,
            percent_stock_brokerage,
            percent_bond_brokerage,
            percent_stock_retirement_option,
            percent_bond_retirement_option,
            brokerage_cash_add,
            brokerage_us_stock_add,
            brokerage_us_bond_add,
            brokerage_int_stock_add,
            brokerage_int_bond_add,
            traditional_cash_add,
            traditional_us_stock_add,
            traditional_us_bond_add,
            traditional_int_stock_add,
            traditional_int_bond_add,
            roth_cash_add,
            roth_us_stock_add,
            roth_us_bond_add,
            roth_int_stock_add,
            roth_int_bond_add,
            brok_acct_option,
            trad_acct_option,
            roth_acct_option,
            output,
            age_option,
            distribution_year,
            distribution_table_path,
            use_brokerage_retirement,
        }
    }
}

impl Default for Args {
    fn default() -> Self {
        Self::new()
    }
}