주식, 코인 구매 판매 수수료를 계산 예제 자료 소스

주식, 코인을 구매하여 판매할 때 수수료를 계산 예제 자료입니다. 첫 번째 예제는 수수료가 없는 경우, 두 번째 자료는 구매수수료만 있는 경우, 세 번째 자료는 구매 및 판매 모두에 수수료가 있는 경우입니다.

상품 구매 및 판매 수수료를 고려한 예제 자료

주식, 코인 등은 모두 구매 및 판매 수수료가 있기에 세 번째 예제를 참고하여야 합니다. CHAT GPT가 꽤 예제를 잘 만들어줘서 애용하고 있는데, 3.5버전은 잘못된 정보를 자연스럽게 말하는 경향이 있어서 조심하셔야 합니다.

decimal buyPrice;
decimal sellPrice;
decimal cost;
decimal profit;
decimal commissionRate;
decimal buyCommissionRate;
decimal sellCommissionRate;
decimal buyCost;
decimal sellCost;

// 1.수수료 없음
// 상품 가격과 판매 가격을 변수에 저장합니다.
buyPrice = 100.0m;
sellPrice = 120.0m;

// 구매 비용과 판매 수익을 계산합니다.
cost = buyPrice;
profit = sellPrice - buyPrice;

// 결과를 콘솔에 출력합니다.
Debug.WriteLine("[1] 상품 구매 비용: {0}", cost);
Debug.WriteLine("[1] 상품 판매 수익: {0}", profit);

// 2.구매수수료
// 구매 가격, 판매 가격, 수수료율을 변수에 저장합니다.
buyPrice = 100.0m;
sellPrice = 120.0m;
commissionRate = 0.01m; // 수수료율 1%

// 구매 비용과 판매 수익을 계산합니다.
cost = buyPrice * (1 + commissionRate);
profit = sellPrice - cost;

// 결과를 콘솔에 출력합니다.
Debug.WriteLine("[2] 상품 구매 비용: {0}", cost);
Debug.WriteLine("[2] 상품 판매 수익: {0}", profit);

// 3.구매수수료, 판매수수료
// 구매 가격, 판매 가격, 구매 수수료율, 판매 수수료율을 변수에 저장합니다.
buyPrice = 100.0m;
sellPrice = 120.0m;
buyCommissionRate = 0.01m; // 구매 수수료율 1%
sellCommissionRate = 0.02m; // 판매 수수료율 2%

// 구매 비용과 판매 비용을 계산합니다.
buyCost = buyPrice * (1 + buyCommissionRate);
sellCost = sellPrice * (1 - sellCommissionRate);

// 구매 비용과 판매 수익을 계산합니다.
profit = sellCost - buyCost;

// 결과를 콘솔에 출력합니다.
Debug.WriteLine("[3] 상품 구매 비용: {0}", buyCost);
Debug.WriteLine("[3] 상품 판매 비용: {0}", sellCost);
Debug.WriteLine("[3] 상품 판매 수익: {0}", profit);

댓글