aboutsummarylogtreecommitdiffstats
path: root/graph.h
blob: c1063e00fdb30f0ad36412fcc174163368253658 (plain)
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
#ifndef GRAPH_H
#define GRAPH_H

#define ZOOM_5y 0
#define ZOOM_4y 1
#define ZOOM_3y 2
#define ZOOM_2y 3
#define ZOOM_1y 4
#define ZOOM_9m 5
#define ZOOM_6m 6
#define ZOOM_3m 7
#define ZOOM_1m 8

#define ROWS_SPACING 5
#define COLS_SPACING 12
#define DAYS_TO_BUSINESS_DAYS_RATIO (29.0/20.0)

#include <stdlib.h>
#include <ncurses.h>
#include "api.h"

extern int zoom_months[9], zoom_change_x_months[9];

/**
 * -- Main input loop for graphing --
 *
 * Gets the five year history of the given security(s) and calls graph_print to initially display a graph of it/them.
 * If symbol2 is NULL, only displays the graph for symbol.
 * The user may input keystrokes to manipulate the graph(s).
 * Valid keystrokes:
 * q: Quits program
 * UP: increase zoom level by one and moves start date forward by one year, three months, or two months.
 * DOWN: decreases zoom level by one and moves start date backward by one year, three months, or two months.
 * LEFT: moves start date backward by one year, three months, or one month.
 * RIGHT: moves start date forward by one year, three months, or one month.
 * @param symbol first symbol
 * @param symbol2 second symbol
 */
void graph_main(const char* symbol, const char* symbol2);

/**
 * Prints out a NCurses based graph given an array of daily close prices.
 * If points2 if not NULL, also prints a graph of its data in a different color.
 * x-axis -- date
 * y-axis -- close price
 * @param points daily close prices of past five years of first security
 * @param points2 daily close prices of past five years of second security
 * @param start_time the starting date of prices to print
 * @param zoom the zoom level
 * @param symbol first symbol
 * @param symbol2 second symbol
 */
void graph_print(const double* points, const double* points2, struct tm* start_time, int zoom,
        const char* symbol, const char* symbol2);

/**
 * Reallocates the given array with size trading days. Moves all values to end of the array and sets
 * values not initialized as EMPTY.
 * @param points the array to realloc
 * @param size the size of points
 * @param trading_days the size to realloc
 * @return the reallocated array
 */
double* graph_fill_empty(double* points, int size, int trading_days);

#endif