home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / cpgms.zip / AIM.C < prev    next >
Text File  |  1985-08-05  |  13KB  |  397 lines

  1.  
  2.  
  3. /***********************************************************
  4.  
  5.                 Automatic Investment Management
  6.                              by
  7.                        David McCourt
  8. ************************************************************/
  9.  
  10. #include bdscio.h
  11. #define CLEARS "\032"           /* clear screen code */
  12. #define MAX_ISS 15              /* number of stocks or mutual funds */
  13. #define MAX_LET 11              /* number of letters in name        */
  14. char name[MAX_ISS] [MAX_LET];   /* name of stock or fund */
  15. char shares[MAX_ISS] [5];       /* no of shares owned */
  16. char price[MAX_ISS] [5];        /* current price */
  17. char cost[MAX_ISS] [5];         /* total invested in stock/fund
  18.                                    when shares are sold as directed
  19.                                    by AIM, the total cost is reduced
  20.                                    by the amount of the sale
  21.                                 */
  22. char value[MAX_ISS] [5];        /* current total value */
  23. char control[MAX_ISS] [5];      /* used for buy/sell decisions */
  24. char aim_rec[MAX_ISS] [5];      /* the buy sell amount */
  25. char bs[MAX_ISS] [5];           /* 'buy' or 'sell' instruction */
  26. char str[10];                   /* used for input to floating point */
  27. char m1[5];                     /* used to compute control */
  28. char m2[5];
  29. char m4[5];
  30. char tot_inv[5];                /* used to compute various totals */
  31. int x, iss_num, w_o;            /* iss_num = count of issues in file
  32.                                    w_o = issue currently being worked on
  33.                                    x = transaction code
  34.                                 */
  35.  
  36. main()
  37. {
  38.         iss_num = -1;
  39.         atof(m1, "1.1");
  40.         atof(m2, ".5");
  41.         atof(m4, ".1");
  42.         menu();
  43.  
  44. }
  45.  
  46. menu()
  47. {
  48.  
  49.         x = 0;
  50.         puts(CLEARS);
  51.         puts("\n\t\tMenu for Automatic Investment Management\n");
  52.         puts("\t\t========================================\n\n");
  53.         puts("\t\t\t 0) End session\n");
  54.         puts("\t\t\t 1) Original investment\n");
  55.         puts("\t\t\t 2) Dividends received as stock\n");
  56.         puts("\t\t\t 3) Additional cash invested\n");
  57.         puts("\t\t\t 4) AIM Market order - SELL \n");
  58.         puts("\t\t\t 5) AIM Market order - BUY\n");
  59.         puts("\t\t\t 6) Review portfolio\n");
  60.         puts("\t\t\t 7) Save file\n");
  61.         puts("\t\t\t 8) Read file\n");
  62.         puts("\t\t\t 9) Delete issue\n");
  63.         puts("\t\t\t10) Update Prices\n");
  64.         puts("\t\t\t11) Money Market original investment\n");
  65.         puts("\t\t\t12) Money Market deposits, withdrawal\n");
  66.         puts("\t\t\t    and interest received\n");
  67.         printf("\n\n\t\tEnter your choice: ");
  68.  
  69.         scanf("%d",&x);
  70.  
  71.         switch(x){
  72.                 case 0:
  73.                         exit();
  74.                         break;
  75.                 case 1:
  76.                         org_pur();
  77.                         shs_pur();
  78.                         break;
  79.                 case 2:
  80.                         list();
  81.                         sel_iss();
  82.                         shs_pur();
  83.                         break;
  84.                 case 3:
  85.                         new_add();
  86.                         break;
  87.                 case 4:
  88.                         list();
  89.                         sel_iss();
  90.                         shs_pur();
  91.                         break;
  92.                 case 5:
  93.                         list();
  94.                         sel_iss();
  95.                         shs_pur();
  96.                         break;
  97.                 case 6:
  98.                         ind_rep();
  99.                         break;
  100.                 case 7:
  101.                         save();
  102.                         break;
  103.                 case 8:
  104.                         load();
  105.                         break;
  106.                 case 9:
  107.                         delete();
  108.                         break;
  109.                 case 10:
  110.                         list();
  111.                         sel_iss();
  112.                         up_date();
  113.                         break;
  114.                 case 11:
  115.                         org_pur();
  116.                         dep_mon();
  117.                         break;
  118.                 case 12:
  119.                         list();
  120.                         sel_iss();
  121.                         dep_mon();
  122.                         break;
  123.                 default:
  124.                         menu();
  125.         }
  126.         menu();
  127. }
  128.  
  129. dep_mon()
  130. {
  131. char add_cash[5];
  132.  
  133.         puts(CLEARS);
  134.         printf("\n\t\tWorking on: %s",name[w_o]);
  135.         puts("\n\n\t\tEnter the amount of the deposit:  ");
  136.         atof(add_cash, gets(str));
  137.         atof(price[w_o], "1");  /* set price per share to $1 */
  138.         fpadd(cost[w_o],cost[w_o],add_cash);
  139.         fpadd(control[w_o],control[w_o],add_cash);
  140.         fpadd(shares[w_o],shares[w_o],add_cash);
  141.         fpadd(value[w_o],value[w_o],add_cash);
  142.  
  143. }
  144.  
  145. org_pur()
  146. {
  147. int i;
  148.  
  149.         ++iss_num;
  150.         w_o = iss_num;
  151.         puts(CLEARS);
  152.         puts("\n\n\tEqual amounts of money should be deposited in\n");
  153.         puts("\tstock or mutual funds and money market funds.\n");
  154.         puts("\n\tEnter name of stock or fund:\n");
  155.         puts("\tFill all blanks with spaces.\n");
  156.         puts("\tThen press space bar to continue..\n");
  157.         puts("\n\n\t[..........]\b\b\b\b\b\b\b\b\b\b\b");
  158.         for(i=0;(name[iss_num][i] = getchar())!='\n' && i<MAX_LET;++i);
  159.         name[iss_num] [10] ='\0';
  160. }
  161. shs_pur()
  162. {
  163. char add_shs[5];
  164. char new_con[5];
  165. char add_cash[5];
  166.         puts(CLEARS);
  167.         printf("\nWorking on: %s", name[w_o]);
  168.         puts("\n======================\n\n");
  169.         puts("(enter all negative figures with a minus)\n\n");
  170.         puts("\nEnter number of shares bought/sold....\t");
  171.         atof(add_shs, gets(str));
  172.         puts("Enter current price per share..........\t");
  173.         atof(price[w_o], gets(str));
  174.         fpmult(tot_inv,add_shs,price[w_o]);
  175.         printf("\nThis transaction = %10.3f", tot_inv);
  176.         fpadd(shares[w_o],shares[w_o],add_shs);
  177.         fpmult(value[w_o],price[w_o],shares[w_o]);
  178.         if(x==1){
  179.                 fpmult(control[w_o],price[w_o],shares[w_o]);
  180.                 fpmult(cost[w_o],price[w_o],shares[w_o]);
  181.         }
  182.         if(x==3){
  183.                 fpmult(new_con,tot_inv,m1);
  184.                 fpadd(control[w_o],control[w_o],new_con);
  185.                 fpadd(cost[w_o],cost[w_o],tot_inv);
  186.         }
  187.         if(x==4){
  188.                 fpadd(cost[w_o],cost[w_o],tot_inv);
  189.         }
  190.         if(x==5){
  191.                 fpmult(new_con,tot_inv,m2);
  192.                 fpadd(control[w_o],control[w_o],new_con);                       fpadd(cost[w_o],cost[w_o],tot_inv);
  193.         }
  194.         hold();
  195. }
  196.  
  197. hold()
  198. {
  199.         puts("\n\nPress <RETURN> to continue...");
  200.         getchar();
  201. }
  202.  
  203. list()
  204. {
  205. int i;
  206.         puts(CLEARS);
  207.         i = 0;
  208.         printf("\n\n\t\tNumber\t\tName\n");
  209.         while(i != iss_num+1){
  210.                 printf("\n\t\t%6d\t\t%s",i,name[i]);
  211.         ++i;
  212.         }
  213. }
  214. ind_rep()
  215. {
  216. char p_l[5];
  217. char ave_cost[5];
  218. char port_val[5];
  219.  
  220.         atof(port_val,"0");
  221.         atof(p_l, "0");
  222.         puts(CLEARS);
  223. puts("Name of    Shares    Cur       Cur       Ave       Control    Buy/Sell\n");
  224. puts("Issue      Owned     Price     Value     Cost      Amount     Advice\n");
  225. puts("========== ========= ========  ========= ========  ========== =============");
  226. puts("\n\n");
  227.         for(w_o=0; w_o < iss_num +1; ++w_o){
  228.                 aim();
  229.                 fpsub(p_l, value[w_o], cost[w_o]);
  230.                 fpdiv(ave_cost,cost[w_o],shares[w_o]);
  231.                 printf("%s",name[w_o]);
  232.                 printf("%10.3f",shares[w_o]);
  233.                 printf("%9.3f",price[w_o]);
  234.                 printf("%11.3f",value[w_o]);
  235.                 printf("%9.3f",ave_cost);
  236.                 printf("%11.3f",control[w_o]);
  237.                 printf("%10.2f %s\n",aim_rec[w_o],bs[w_o]);
  238.                 fpadd(port_val,port_val,value[w_o]);
  239.         }
  240. puts("\n\n");
  241. puts("===========================================================================");
  242.         printf("\nPorfolio  Value: %11.3f",port_val);
  243.         hold();
  244. }
  245. sel_iss()
  246. {
  247.         puts("\n\nSelect issue number:  ");
  248.         scanf("%d", &w_o);
  249. }
  250.  
  251. new_add()
  252. {
  253. int z;
  254.         puts(CLEARS);
  255.         puts("Select 1) New issue or 2) Additional stock\n");
  256.         scanf("%d", &z);
  257.         switch(z){
  258.                 case 1:
  259.                         org_pur();
  260.                         shs_pur();
  261.                         break;
  262.                 case 2:
  263.                         list();
  264.                         sel_iss();
  265.                         shs_pur();
  266.                         break;
  267.                 default:
  268.                         new_add();
  269.         }
  270. }
  271. up_date()
  272. {
  273.         puts(CLEARS);
  274.         printf("\nEnter price for:  %s: ", name[w_o]);
  275.         atof(price[w_o], gets(str));
  276.         fpmult(value[w_o],price[w_o],shares[w_o]);
  277. }
  278. save()
  279. {
  280. char iobuf[BUFSIZ];
  281. int a,b,c;
  282.         puts(CLEARS);
  283.         puts("Saving file to disk ...");
  284.         if(iss_num < 0){
  285.                 puts("CAUTION !!! file is empty.");
  286.                 hold();
  287.                 menu();
  288.         }
  289.         if(fcreat("AIM.FIL",iobuf) == ERROR){
  290.                 puts("\nCan't create AIM.FIL\n");
  291.                 return(ERROR);
  292.         }
  293.         putw(iss_num,iobuf);
  294.         for(a=0; a < iss_num +1; ++a){
  295.                 for(b=0; b < MAX_LET; ++b){
  296.                         c = name[a] [b];
  297.                         putw(c,iobuf);
  298.                 }
  299.         }
  300.         for(a=0; a< iss_num + 1; ++a){
  301.                 for(b=0; b < 5; ++b){
  302.                         c = shares[a] [b];
  303.                         putw(c,iobuf);
  304.                         c = price[a] [b];
  305.                         putw(c,iobuf);
  306.                         c = cost[a] [b];
  307.                         putw(c,iobuf);
  308.                         c = value[a] [b];
  309.                         putw(c,iobuf);
  310.                         c = control[a] [b];
  311.                         putw(c,iobuf);
  312.                         c = aim_rec[a] [b];
  313.                         putw(c,iobuf);
  314.                 }
  315.         }
  316.         fflush(iobuf);
  317.         fclose(iobuf);
  318. }
  319. load()
  320. {
  321. char iobuf[BUFSIZ];
  322. int a,b,c;
  323.         puts(CLEARS);
  324.         puts("Loading file ...");
  325.         if(fopen("AIM.FIL",iobuf) == ERROR){
  326.                 puts("\nCan't open AIM.FIL\n");
  327.                 return(ERROR);
  328.         }
  329.         iss_num = getw(iobuf);
  330.         for(a=0; a < iss_num +1; ++a){
  331.                 for(b=0; b < MAX_LET; ++b)
  332.                         name[a] [b] = getw(iobuf);
  333.         }
  334.         for(a=0; a < iss_num +1; ++a){
  335.                 for(b=0; b < 5; ++b){
  336.                         shares[a] [b] = getw(iobuf);
  337.                         price[a] [b] = getw(iobuf);
  338.                         cost[a] [b] = getw(iobuf);
  339.                         value[a] [b] = getw(iobuf);
  340.                         control[a] [b] = getw(iobuf);
  341.                         aim_rec[a] [b] = getw(iobuf);
  342.                 }
  343.         }
  344.         fclose(iobuf);
  345. }
  346. aim()
  347. {
  348. char safe[5];
  349. char test[5];
  350. int y;
  351.         fpmult(safe,value[w_o],m4);
  352.         atof(test, "100");
  353.         y = fpcomp(value[w_o],control[w_o]);
  354.         if(y==1){
  355.                 fpsub(aim_rec[w_o],value[w_o],control[w_o]);
  356.                 fpsub(aim_rec[w_o],aim_rec[w_o],safe);
  357.                 strcpy(bs[w_o], "Sell");
  358.         }
  359.         if(y==-1){
  360.                 fpsub(aim_rec[w_o],control[w_o],value[w_o]);
  361.                 fpsub(aim_rec[w_o],aim_rec[w_o],safe);
  362.                 strcpy(bs[w_o], "Buy ");
  363.         }
  364.         if(y==0)
  365.                 atof(aim_rec[w_o], "0");
  366.         y = fpcomp(aim_rec[w_o], test);
  367.         if(y==-1){
  368.                 atof(aim_rec[w_o], "0");
  369.                 strcpy(bs[w_o], "None");
  370.         }
  371. }
  372. delete()
  373. {
  374. int i,y;
  375.                 puts(CLEARS);
  376.                 list();
  377.                 sel_iss();
  378.                 while(w_o < iss_num+1){
  379.                         for(i=0; i < 6; ++i){
  380.                                 name[w_o] [i] = name[w_o +1] [i];
  381.                                 shares[w_o] [i] = shares[w_o + 1] [i];
  382.                                 price[w_o] [i] = price[w_o +1] [i];
  383.                                 cost[w_o] [i] = cost [w_o +1] [i];
  384.                                 value[w_o] [i] = value[w_o +1] [i];
  385.                                 control[w_o] [i] = control[w_o +1] [i];
  386.                                 aim_rec[w_o] [i] = aim_rec[w_o +1] [i];
  387.                         }
  388.                 ++w_o;
  389.                 }
  390.                 iss_num = iss_num -1;
  391. }
  392.  
  393. /* remark end of file aim.c */
  394. es_num = iss_num -1;
  395. }
  396.  
  397.