-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (53 loc) · 2 KB
/
main.cpp
File metadata and controls
66 lines (53 loc) · 2 KB
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
#include <iostream>
#include <vector>
// simple function
double simple_return(double initial_price, double final_price) {
return (final_price - initial_price) / initial_price;
}
// create the vector iteration as a function
double iterate_prices(const std::vector<double>& prices) {
std::cout << "All prices: " << std::endl;
for (int i = 0; i < prices.size(); i++) {
std::cout << "price " << i + 1 << ": " << prices[i] << std::endl;
}
return 0;
}
int main() {
// learning how to use variables
double spot = 110.0;
double strike = 105.0;
int steps = 252;
bool in_the_money = spot > strike;
// learning how to use std::cout
std::cout << "Spot price: " << spot << std::endl;
std::cout << "Strike price: " << strike << std::endl;
std::cout << "Steps: " << steps << std::endl;
std::cout << "In the money: " << std::boolalpha << in_the_money << std::endl;
// learning how to use functions
double entry_price = 100.0;
double current_price = 95.0;
double profit = simple_return(entry_price, current_price);
std::cout << "PnL: " << profit << std::endl;
// learning how to use if statements
if (profit > 0) {
std::cout << "Profit" << std::endl;
} else if (profit < 0) {
std::cout << "loss" << std::endl;
} else {
std::cout << "Break even" << std::endl;
}
// learning how to use vectors
std::vector<double> prices = {100.0, 102.5, 101.0, 105.0};
std::cout << "first price: " << prices[0] << std::endl;
std::cout << "second price: " << prices[1] << std::endl;
std::cout << "third price: " << prices[2] << std::endl;
std::cout << "fourth price: " << prices[3] << std::endl;
// Use a loop to iterate over vecotor
std::cout << "All prices: " << std::endl;
for (int i = 0; i < prices.size(); i++) {
std::cout << "price " << i + 1 << ": " << prices[i] << std::endl;
}
iterate_prices(prices);
iterate_prices({110.0, 108.0, 107.5, 109.0});
return 0;
}