[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

spread logic



PureBytes Links

Trading Reference Links

spread logic:

If you can program in an outside language it's pretty easy. You can even use the old DOS basic compiler and run it under the Win prompt. Say you want to trade the bean spread S04N-S04X. Each day create with your data collection program (ie Csi) S04N and S04X as ascii files. You can just capture the date and close if you want to since that's all you need. For example call them s04n.txt and s04x.txt. This syntax isn't exactly right but you may notice how simple it is.

'program logic
file1=s04n.txt           'Jul Beans
file2=s04x.txt           'Nov Beans 
file3=ss04n04x.txt    'tradable spread file
open file1 as input
open file2 as input
open file3 as output


LogicLoop:

Get file1,date1,close1   'get means read a record and store date and close
Get file2,date2,close2    'ditto

DateLogic:
if date1<date2 then  
   ' file2 starts later than file1 so get next record in file1
     Get file1 (date1, close1) 
endif

if date1>date2 then
      'file2 starts before file1 so get next record in file2
      Get file2 (date2, close2)
endif

if date1=date2 then
    'two dates match so continue
     goto WriteLogic
else
   'two date do not match so keep trying
     goto DateLogic	
endif

WriteLogic:
'now the two dates match so check for valid closes
if close1>0 and close2>0 then
   'we're ok so write out a record
    close=close1-close2  'this is your spread
   Put (or write) file3(date1, close)
endif
 	
'loop back to top if not the eof (end of file1)
if eof(file1)=true then goto Exit else goto LogicLoop

Exit:
close file1, file2,file3
system  'or quit

Now you have your tradable spread stored in ss04N04X.txt so just open it with TS and have at it. Hope this helps.
Robin