#include <stdlib.h>
#include <stdio.h>
#include <math.h>


double start_balance = 0.314469*1233.000000+0.265490*1233.000000+0.701562*1233.000000+0.010000*1233.000000+1.594723*1233.000000+0.003771*1233.000000+0.010000*1233.000000+1.000000*1233.000000+0.017000*1233.000000+0.649474*1233.000000;

double buy1 = 0.769568*727.000000+0.033000*727.000000+1.000000*727.000000+0.968229*727.000000+1.000000*727.000000+0.956603*727.000000+1.000000*727.000000+1.000000*727.000000+0.982367*727.000000;

double sell1 = 0.400200*809.000000+0.300000*809.000000+4.426677*809.000000+0.020000*809.000000+0.300000*809.000000+0.140690*809.000000+2.087505*809.000000;
double fee1 = 1.45693+1.09215+16.11532+0.07281+1.09215+0.51218+7.59956;

double buy2 = 0.920138*771.000000+0.020168*771.000000+0.500000*771.000000+0.010000*771.000000+0.083271*771.000000+6.466422*771.000000;

double buy3 = 0.036000*776.799960;
double fee2 = 0.12584;

double sell2 = 6.901390*799.000000+0.030000*798.930000+0.030000*798.930000+0.030000*798.930000+0.051000*798.033000+0.957610*798.000000;
double fee3 = 24.81395+0.10786+0.10786+0.10786+0.18315+3.43878;

double buy4 = 8.020000*791.000000;
double fee4 = 28.54719;

double sell3 = 8.020000*886.000000;
double fee5 = 31.97574;

double buy5 = 2.442374*843.000000+0.497835*843.000000+0.010000*843.000000+0.100000*843.000000;
double fee6 = 9.26515+1.88854+0.03794+0.37935;

double sell4 = 0.579662*879.000000+2.470547*878.000000;
double fee7 = 2.29285+9.76113;

double buy6 = 8.372000*851.000000;
double fee8 = 32.06057;

double sell5 = 4.487471*895.000000+3.884529*894.000000;
double fee9 = 18.07329+15.62746;

double buy7 = 3.854560*1015.000000+0.010000*1015.000000+0.011440*1015.000000+0.200000*1015.000000+0.168300*1015.000000+1.000000*1015.000000+0.030068*1015.000000+1.000000*1015.000000+1.000000*1015.000000+0.023239*1015.000000;
double fee10 = 17.6057+0.04568+0.05225+0.9135+0.76871+4.5675+0.13734+4.5675+4.5675+0.10614;

double sell6 = 7.297607*1043.000000;
double fee11 = 34.25132;

double buy8 = 8.502000*889.000000;
double fee12 = 34.01225;

double sell7 = 2.876981*954.000000+5.625019*954.000000+0.050636*955.000000;
double fee13 = 12.35088+24.14821+0.19947;

double buy9 = 0.857095*941.000000+0.082000*941.000000+0.010000*941.000000+0.010000*941.000000+0.026639*941.000000+0.010000*941.000000+1.890785*941.000000;
double fee14 = 3.62937+0.34723+0.04235+0.04235+0.1128+0.04235+8.00653;

double sell8 = 2.835883*909.555000;
double fee15 = 10.63999;

double buy10 = 8.06000000*983.5;
double fee16 = 32.69892;

double sell9 = 8.06*941.00;
double fee17 = 31.2859;

double buy11 = 2.15888908*929.00+2.95995497*929.00+0.10032014*929.00+0.04149654*929.00+0.12994714*929.00+0.11823751*929.00;
double fee18 = 8.27313+11.34292+0.38444+0.15902+0.49797+0.4531;

double buy12 = 2.56599999*938.00;
double fee19 = 9.9285;

double sell10 = 8.07484537*945;
double fee20 = 31.47676;

double buy13 = 8.502*890;
double fee21 = 31.21297;

double sell11 = 7.57906835*917+0.57000000*917+0.35293165*917;
double fee22 = 28.66877+2.1561+1.33501;

double buy14 = 0.09999999*928.12749+6.17748888*930.0+2.01102898*930.0;
double fee23 = 0.38285+23.69839+7.71481;

double sell12 = 8.28851784*948.90;
double fee24 = 32.44302;

double buy15 = 8.34000000*938.00;
double fee25 = 32.26955;

double sell13 = 0.54735441*956.00+1.55769905*956.00+6.23494654*956.00;
double fee26 = 2.15849+6.14279+24.58751;

double buy16 = 8.36800000*945;
double fee27 = 32.61951;

double sell14 = 8.36800000*972.50;
double fee28 = 33.56876;

double buy17 = 0.01*872.0+9.0*895.0;
double fee29 = 0.03466+32.01863;

double sell15 = 9.01*953.0;
double fee30 = 34.13146;

double buy18 = 9.07962161*934.01;
double fee31 = 45.1859;

double sell16 = 4.07955618*955.01+0.101*955.0+2.0*955.0+0.34999999*955.0+0.01249649*955.0+2.53656895*945.22666;
double fee32 = 20.64889+0.51121+10.123+1.77152+0.06325+12.70745;

double buy19 = 13.018*660;
double fee33 = 47.25534;

double sell17 = 0.06250727*690.01508+0.01*690.01005+3.62157374*690.00001+4.92703388*690.00+0.28057319*690.00+0.02240090*690.00+0.10429745*690.00+0.32408265*690.00+0.01142535*690.00+0.29015686*690.00+2.00*690.00+1.36394871*690.00;
double fee34 = 0.23722+0.03795+13.74387+18.69809+1.06478+0.08501+0.39581+1.22989+0.04336+1.10115+7.59+5.17619;

double buy20 = 14.238*624.00;
double fee35 = 48.86482;


int main(int argc, char **argv){
	double tmp1 = 0;
	double tmp2 = 0;
	double usd = 0;
	double shares = 0;
	double cur_balance = start_balance;
	printf("start balance: %lf\n", start_balance);
	printf("trade %%\t portf %%\t usd\t shares\n");


	cur_balance -= buy1;
	cur_balance += sell1;
	cur_balance -= fee1;
	tmp1 = 1 - buy1 / sell1;
	tmp1 *= 100;
	tmp2 = 1 - start_balance/cur_balance;
	tmp2 *= 100;
	usd = cur_balance;
	//shares = 
	printf("%lf %lf %lf\n", tmp1, tmp2, usd);
	//cur_balance += sell1;

	tmp1 = 1 - (buy2+buy3) / sell2;
	tmp1 *= 100;
	tmp2 = 1 - cur_balance/(cur_balance+sell2-buy2-buy3-fee2-fee3);
	tmp2 *= 100;
	cur_balance -= buy2+buy3+fee2+fee3;
	cur_balance += sell2;
	printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);
	//printf("\t%lf %lf\n", buy2+buy3, sell1);
	//tmp1 = 1 - 4 / sell3;

	tmp1 = 1 - buy4 / sell3;
	tmp1 *= 100;
	tmp2 = 1 - cur_balance/(cur_balance+sell3-fee5-buy4-fee4);
	tmp2 *= 100;
	cur_balance -= buy4;
	cur_balance -= fee4+fee5;
	cur_balance += sell3;
	printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);


    tmp1 = 1 - buy5 / sell4;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell4-fee7-buy5-fee6);
    tmp2 *= 100;
    cur_balance -= buy5+fee6+fee7;
    cur_balance += sell4;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy6 / sell5;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell5-fee9-buy6-fee8);
    tmp2 *= 100;
    cur_balance -= buy6+fee8+fee9;
    cur_balance += sell5;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy7 / sell6;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell6-fee11-buy7-fee10);
    tmp2 *= 100;
    cur_balance -= buy7+fee10+fee11;
    cur_balance += sell6;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy8 / sell7;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell7-fee13-buy8-fee12);
    tmp2 *= 100;
    cur_balance -= buy8+fee12+fee13;
    cur_balance += sell7;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy9 / sell8;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell8-fee15-buy9-fee14);
    tmp2 *= 100;
    cur_balance -= buy9+fee14+fee15;
    cur_balance += sell8;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy10 / sell9;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell9-fee17-buy10-fee16);
    tmp2 *= 100;
    cur_balance -= buy10+fee16+fee17;
    cur_balance += sell9;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);




    tmp1 = 1 - (buy11+buy12) / sell10;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell10-buy11-buy12-fee18-fee19-fee20);
    tmp2 *= 100;
    cur_balance -= buy11+buy12+fee18+fee19+fee20;
    cur_balance += sell10;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);


    tmp1 = 1 - buy13 / sell11;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell11-fee21-buy13-fee22);
    tmp2 *= 100;
    cur_balance -= buy13+fee21+fee22;
    cur_balance += sell11;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy14 / sell12;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell12-fee23-buy14-fee24);
    tmp2 *= 100;
    cur_balance -= buy14+fee23+fee24;
    cur_balance += sell12;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy15 / sell13;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell13-fee25-buy15-fee26);
    tmp2 *= 100;
    cur_balance -= buy15+fee25+fee26;
    cur_balance += sell13;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy16 / sell14;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell14-fee27-buy16-fee28);
    tmp2 *= 100;
    cur_balance -= buy16+fee28+fee27;
    cur_balance += sell14;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy17 / sell15;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell15-fee29-buy17-fee30);
    tmp2 *= 100;
    cur_balance -= buy17+fee29+fee30;
    cur_balance += sell15;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);

    tmp1 = 1 - buy18 / sell16;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell16-fee31-buy18-fee32);
    tmp2 *= 100;
    cur_balance -= buy18+fee31+fee32;
    cur_balance += sell16;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);


    tmp1 = 1 - buy19 / sell17;
    tmp1 *= 100;
    tmp2 = 1 - cur_balance/(cur_balance+sell17-fee33-buy18-fee34);
    tmp2 *= 100;
    cur_balance -= buy19+fee33+fee34;
    cur_balance += sell17;
    printf("%lf %lf %lf\n", tmp1, tmp2, cur_balance);




	printf("\nEnd balance: %lf\n", cur_balance);

	tmp1 = 1 - start_balance/cur_balance;
	tmp1 *= 100;
	printf("Total gain %% %lf\n", tmp1);

	return 0;
}