-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition_sizing.cpp
30 lines (27 loc) · 1.01 KB
/
position_sizing.cpp
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
#include <iostream>
#include <sstream>
#include <cstring>
class PositionSizing {
public:
PositionSizing(double riskPercentage, double stopLossPercentage)
: riskPercentage(riskPercentage), stopLossPercentage(stopLossPercentage) {}
void setRiskPercentage(double percentage) {
riskPercentage = percentage;
}
void setStopLossPercentage(double percentage) {
stopLossPercentage = percentage;
}
double calculatePositionSize(double portfolioSize, double entryPrice) {
double riskAmount = portfolioSize * riskPercentage;
double stopLossAmount = entryPrice * stopLossPercentage;
double positionSize = riskAmount / stopLossAmount;
return positionSize;
}
double calculatePositionSizeWithMaxLoss(double portfolioSize, double entryPrice, double maxLossAmount) {
double positionSize = maxLossAmount / (entryPrice * stopLossPercentage);
return positionSize;
}
private:
double riskPercentage;
double stopLossPercentage;
};