• Jueves 25 de Abril de 2024, 14:04

Autor Tema:  Re: un fallido intento de simulacion de bolsa  (Leído 1653 veces)

keko

  • Nuevo Miembro
  • *
  • Mensajes: 9
    • Ver Perfil
Re: un fallido intento de simulacion de bolsa
« en: Lunes 13 de Enero de 2003, 12:43 »
0
un programilla en pascal intenta ser un simulador pero se queda en juego malillo

program bolsa;
uses crt,dos;
var
te:char;
xxg,cug,dg:word;
gra:array[1..23,1..300] of word;
ddd,dd1,dd2,dd3,mo,mu,cu,ka,di,a,b,c,cc,d:longint;
cox,sub,baj,can:longinT;
ibe:array[1..23] of word;
xs:array[1..5] of byte;
xss:array[1..5] of longint;
ibc:array[1..23] of byte;
con,xx:real;
procedure grafico;
var
rgg:registers;
colo,xgg,ygg:word;
c1gg,c2gg:word;
begin
colo:=random(5);
if colo=0 then colo:=11;
if colo=1 then colo:=12;
if colo=2 then colo:=13;
if colo=3 then colo:=14;
if colo=4 then colo:=15;
{modo vga}
with rgg do
begin
ah:=0;
al:=19;
end;
intr($10,rgg);
for c1gg:=1 to dg do
begin
 ygg:=0;
 for c2gg:=199 downto 0 do
  begin
  if (gra[cug,c1gg]>=ygg) and (gra[cug,c1gg]<=ygg+32) then break;
  ygg:=ygg+33; {de 20c arriba o abajo en 300dias}
  end;
mem[$a000:c2gg*320+c1gg]:=colo;
end;
readln;
with rgg do
begin
ah:=0;
al:=1;
end;
{volver a texto}
intr($10,rgg);
end;

procedure jorna;
begin
{sube2 baja3 mantiene01}
{las 23 del nasti}
for A:=1 to 23 do
 begin
 b:=random(4);
 if (b=0) or (b=1) then
  begin
  ibc[a]:=15;
  if ibe[a]<30 then ibe[a]:=30;
  gra[a,dg]:=ibe[a];
  end;
 if b=2 then
  begin
  c:=random(70); {<---pesetas}
  if c=0 then c:=1;
  ibe[a]:=ibe[a]+c;
  if ibe[a]<30 then ibe[a]:=30;
  gra[a,dg]:=ibe[a];
  ibc[a]:=lightgreen;
  end;
 if b=3 then
  begin
  c:=random(70);
  if c=0 then c:=1;
  d:=ibe[a];
  d:=D-c;
  if d<30 then d:=30; {la accion +baja si baja tanto tanto no se puede quedar en 0 o si,meten papel q dicen no?}
  ibe[a]:=d;
  gra[a,dg]:=ibe[a];
  ibc[a]:=lightred;
  end;
 end;
{-------------}
end;{de proc}

begin
randomize;
clrscr;
textmode(co40);

di:=1;
ka:=0;
can:=1000000-1684;
{---------}
{cada accion a?}
for a:=1 to 35 do
 begin
 b:=random(6001);
 if b<500 then b:=500;{minimo 500pts 3e}
 ibe[a]:=b;
 end;
xs[1]:=0;xss[1]:=0;
xs[2]:=0;xss[2]:=0;
xs[3]:=0;xss[3]:=0;
xs[4]:=0;xss[4]:=0;
xs[5]:=0;xss[5]:=0;

repeat
b:=1;
for a:=1 to 23 do
begin
textcolor(ibc[a]);
xx:=ibe[a]/166.386;
gotoxy(1,b);write('(',a,')',xx:4:2);
b:=b+1
end;
{------tus movimientos----}
textcolor(7);
gotoxy(20,1);write('dia:',di);
gotoxy(14,2);write('op? c:compra v:vende s:sal');
con:=can/166.386;
gotoxy(14,3);write('cantidad:',con:4:2,'$');
gotoxy(14,6);write('cartera');
gotoxy(14,7);write('(',xs[1],')......',xss[1]);
gotoxy(14,8);write('(',xs[2],')......',xss[2]);
gotoxy(14,9);write('(',xs[3],')......',xss[3]);
gotoxy(14,10);write('(',xs[4],')......',xss[4]);
gotoxy(14,11);write('(',xs[5],')......',xss[5]);
gotoxy(14,12);write('f1: para ver grafico');
te:=' ';
te:=readkey;
if te=chr(59) then
 BEGIN
 sound(1000);
 delay(40);
 nosound;
 gotoxy(14,12);write('                    ');
 gotoxy(14,12);write('numero(x)? ');
 readln(cug);
 grafico;
 END; {de grafico}

if te='c' then
 BEGIN
 gotoxy(14,4);write('numero (x)?');
 readln(a);
 gotoxy(14,5);write('cuantos titulos? ');
 readln(cu);
dd1:=0;
dd2:=0;
for ddd:=1 to cu do
 begin
 if ddd>dd1 then
  begin
  dd2:=dd2+332;
  dd1:=dd1+4000;
  end;
 end;
dd1:=0;
dd3:=0;
for ddd:=1 to cu do
 begin
 if ddd>dd3 then
  begin
  dd3:=dd3+1000;
  dd1:=dd1+500;
  end;
 end;
d:=can-(cu*ibe[a])-(cu div 4)-dd2-dd1;
 {-----}
{ clrscr;
 writeln('can ',can);
 writeln('can ',d);
 writeln('ibe ',ibe[a]);
 writeln('dd2 ',dd2);
 writeln('dd1 ',dd1);
 readln;
 clrscr; }
 {-----}

if (a>23) or (a<1) then d:=-20;
if (xs[1]<>0) and (xs[2]<>0) and (xs[3]<>0) and (xs[4]<>0) and (xs[5]<>0) and
   (xs[1]<>a) and (xs[2]<>a) and (xs[3]<>a) and (xs[4]<>a) and (xs[5]<>a)
   then d:=-20;

if d<0 then
 begin
 gotoxy(14,5);write('no puede realizar compra---');
 readln;
 enD;
if d>0 then
begin
dd1:=0;
dd2:=0;
for ddd:=1 to cu do
 begin
 if ddd>dd1 then
  begin
  dd2:=dd2+2;
  dd1:=dd1+4000;
  end;
 end;
dd1:=0;
dd3:=0;
for ddd:=1 to cu do
 begin
 if ddd>dd3 then
  begin
  dd3:=dd3+1000;
  dd1:=dd1+500;
  end;
 end;
d:=can-(cu*ibe[a])-(cu div 4)-dd2-dd1;
can:=d;
mu:=0;
for d:=1 to 5 do
 begin
 if xs[d]=a then
  begin
  xss[d]:=xss[d]+cu;
  mu:=1;
  cu:=0;
  break;
  end;
 end;
if mu=0 then
 begin
   for cc:=1 to 5 do
    begin
     if xs[cc]=0 then
      begin
      xs[cc]:=a;
      xss[cc]:=cu;
      break;
      end;
    end;
cu:=0;
 end;
end;
 END; {de compra}
if te='v' then
 BEGIN
 mo:=0;
 gotoxy(14,4);write('numero (x)?');
 read(a);
 gotoxy(14,5);write('cuantos titulos? ');
 readln(cu);
{buscar en cartera}
for cc:=1 to 5 do
 begin
 if (a=xs[cc]) and (cu<=xss[cc]) then
  begin
{  d:=can+(ibe[xs[cc]]*xss[cc]);
  can:=d;
  xss[cc]:=xss[cc]-cu;}
  if xss[cc]=0 then xs[cc]:=0;
  mo:=1;
  ka:=ka-1;
  break;
  end;
 end;
if mo=1 then
 begin
dd1:=0;
dd2:=0;
for ddd:=1 to xss[cc] do
 begin
 if ddd>dd1 then
  begin
  dd2:=dd2+2;
  dd1:=dd1+4000;
  end;
 end;
dd1:=0;
dd3:=0;
for ddd:=1 to xss[cc] do
 begin
 if ddd>dd3 then
  begin
  dd3:=dd3+1000;
  dd1:=dd1+500;
  end;
 end;
{d:=can+(ibe[xs[cc]]*xss[cc])-(xss[cc] div 4)-dd2-dd1;}
d:=(ibe[xs[cc]]*xss[cc])-(xss[cc] div 4)-dd2-dd1;
if d<0 then mo:=0;
 end;

if mo=0 then
 begin
 gotoxy(14,5);write('no puede realizar venta---');
 readln;
 end;
if mo=1 then
 begin
dd1:=0;
dd2:=0;
for ddd:=1 to xss[cc] do
 begin
 if ddd>dd1 then
  begin
  dd2:=dd2+2;
  dd1:=dd1+4000;
  end;
 end;
dd1:=0;
dd3:=0;
for ddd:=1 to xss[cc] do
 begin
 if ddd>dd3 then
  begin
  dd3:=dd3+1000;
  dd1:=dd1+500;
  end;
 end;
d:=(ibe[xs[cc]]*xss[cc])-(xss[cc] div 4)-dd2-dd1;
can:=can+d;
xss[cc]:=xss[cc]-cu;
if xss[cc]=0 then xs[cc]:=0;
 end;

mo:=0;
END; {de venta}

clrscr;
di:=di+1;
dg:=dg+1;
if dg>300 then dg:=1;
jorna;
until te='s';
clrscr;
textmode(co80);
WRITELN('Gracias x jugar a este sucedaneo de bolsa ojala fuese tan facil criticas,comentarios al responsable de esta parida');
writeln('intro');
readlN;
end.

t21

  • Nuevo Miembro
  • *
  • Mensajes: 7
    • Ver Perfil
un fallido intento de simulacion de bolsa
« Respuesta #1 en: Lunes 11 de Agosto de 2003, 06:43 »
0
si quieres hacer simulacion podrias utilizar redes neuronales.buscar informacion sobre algoritmos d aprendizaje