-
Notifications
You must be signed in to change notification settings - Fork 0
/
investment.h
46 lines (36 loc) · 1.63 KB
/
investment.h
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
#ifndef INVESTMENT_H
#define INVESTMENT_H
#include "date.h"
// a list of functions to deal with the investment struct
// made by Marco Calabretta at the request of my dad
// all functions require valid pointers as arguments
// an investment vehicle that you would like to calculate the cagr of, i.e. a
// stock or a stock portfolio
struct investment;
// creates an investment vehicle (stock portfolio, real estate portfolio, etc)
// and returns a pointer to it effects: allocates heap memory, client must call
// investment_delete time: O(1)
struct investment *investment_create();
// frees all memory associated with i
// time: O(1)
void investment_destroy(struct investment *i);
// buys d dollars of investment i at date (day, month, year)
// effects: mutates *i through pointers
// requires: d > 0
void investment_buy(double d, struct investment *i, struct date *buy_date);
// sells d dollars of investment i at date (day, month, year)
// effects: mutates *i through pointers
// requires: d > 0
void investment_sell(double d, struct investment *i, struct date *sell_date);
// adds a dividend of d dollars to the investment
// requires: d > 0
void investment_add_dividend(double d, struct investment *i);
// gets the total value of the investment i, including dividends
double investment_get_total(struct investment *i);
// sets the final value of your investment at d dollars, excluding dividends
// requires: d > 0
void investment_final_value(double d, struct investment *i);
// returns the cagr of i as a percentage. e.g. 12.34 means a 12.34% annual
// return
double investment_cagr(struct investment *i);
#endif