#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
int main() {
int buy = 0; //주식 구매수량
long long buy_price=0; // 구매한 주식의 가치
long long sum; //현금보유량 + 주식의가치(총가치)
srand((unsigned int)time(NULL));
cout << "**투입자금(원) : ";
long long Money; // 초기투입자금
cin >> Money;
long long save = Money;
bool check = false;
cout << "**투입한 주식의 현재가격 : ";
int before_price; //초기 주식 가격
cin >> before_price;
sum = Money + (long long)buy * (long long)(buy_price);
cout << "-----------------------------------------------------------------------------------------------------" << endl;
int day = 1;
while (true) {
cout << "**" << day << "일째**" << endl;
cout << "** 거래 전 ** " << endl;
cout << "**거래전가격 : " << before_price << endl;
cout << "**거래전보유현금 : " << Money <<"원" <<endl;
cout << "**거래전보유주식수량 : " << buy << endl;
cout << "**거래전보유주식가치 : " << (long long)buy * (long long)(before_price) << "원"<<endl;
cout << "**거래전보유총재화 : " << sum << "원" <<endl;
cout << "**거래전수익률 : " << ((double)sum - (double)save) / (double)save * (double)100 << "%" << endl;
cout << endl << endl;
int after_price = (int)(((((double)90) + ((double)(rand() % 201) / (double)(10))) / (double)(100)) * (double)(before_price)); //주식가격이 -10%에서 10%까지 변동가능
double rate = ((double)after_price - (double)before_price) / (double)(before_price) * (double)100;
cout << "주식 변동률 : " << rate << "%" << endl;
cout << endl;
if (check == false && rate <-3.0) {
while (Money - (long long)buy * (long long)after_price > 0) {
buy++;
}
buy--;
Money -= (long long)buy * (long long)after_price;
check = true;
buy_price = after_price * (long long)buy;
}
else if ((check == true && rate < -3.0) || (check == true && rate>3.0)) {
Money += (long long)buy * (long long)after_price;
check = false;
buy = 0;
}
sum = Money + (long long)(after_price) * (long long)buy;
cout << "**거래 후 " << endl;
cout << "**현재 주식가격 : " << after_price << "원" << endl;
cout << "**현재 보유현금 : " << Money << "원" <<endl;
cout << "**현재 보유주식수량 : " << buy << endl;
cout << "**현재 보유주식평가 : " << (long long)buy * (long long)after_price << "원" << endl;
cout << "**현재 총보유재화 : " << Money + (long long)buy * (long long)after_price << "원" <<endl;
cout << "**현재 수익률 : " << (((double)(sum)-(double)(save)) / (double)(save)) * (double)(100) << "%" <<endl;
before_price = after_price;
day++;
cout << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
Sleep(5000 + rand()%11);
}
}
현금을 주가보다 크게 넣어라 (예를들면 현금 5000000원 현재 주가 56200원 이렇게)
대충 이렇게 만듦
주가변동률은 -10%에서 +10% 사이로 랜덤으로 변하게 해놓고
주식을 보유 안하고있을때 갑자기 3%이상 급락하면 가진돈만큼 매수
주식을 보유 하고있을때 갑자기 3% 이상 급등하면 가진 주식수만큼 매도
주식 보유하고있을때 갑자기 3%이상 급락하면 가진 주식수만큼 매도
나머지는 그냥 패스
5초마다 주식가격 바뀜 ㅇㅇ
그냥 재미삼아 만들었으니 값 수정해서 해볼사람은 해보셈 ㅋㅋ
중간에 멈추고 싶으면 if (day == 30) break; 같은거 넣고
참고로 나는 삼성전자 5000000원 현재 56200원 넣으니까 한달뒤에 490만원되더라 ㅋㅋ
우와 님 개쩐다
비전공자임 ㅠ
갑자기의 기준이 어느정도임 - dc Cpp
무슨 갑자기?
갑자기 3%이상 급등 급락 - dc Cpp
주식가격이 -10%에서 10%까지 srand함수로 랜덤하게 변함 그 때 만약 -3%이하거나 3%이상일때
한틱마다라는거군 - dc Cpp
ㅇㅇ 그냥 기계적으로 장마감할때 사고판다 생각해