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

RE: [amibroker] Disable stocks with a PositionScore


  • To: "AmiBroker" <amibroker@xxxxxxxxxxxxxxx>
  • Subject: [amibroker] Ready OSAKA/AFL functions: Ranking, Watchlists, Static Variables, etc.
  • From: "Herman vandenBergen" <psytek@xxxxxxxx>
  • Date: Tue, 20 Jan 2004 16:42:47 -0800

PureBytes Links

Trading Reference Links




Here is my 
first attempt at using the OSAKA DLL to solve some of the current problems 
discussed on the list. The OSAKA DLL turns out to be very powerful 
and pretty fast too. Many thanks to Joe Osaka, for contributing this nice 
DLL! 
I show only 
three functions to see what interest there is on the list. Typical tasks 
that can be performed by the thre functions are:
  <SPAN 
  class=840460112-20012004>save optimized 
  parameters (numbers, not arrays) for individual stocks during in-line 
  optimizations,  <FONT 
  size=2>Typical <SPAN 
  class=840460112-20012004>parameters saved for each stock might be 
  a RSI Period, LongThreshold, ShortThreshold, ProfitStop and StopLoss.<SPAN 
  class=840460112-20012004> 
  <SPAN 
  class=840460112-20012004>simulate Static variables that can be 
  accessed while performing various AA 
  operations, <SPAN 
  class=840460112-20012004>simply save the parameters 
  under a variable name of your choice.
  <SPAN 
  class=840460112-20012004>create/save Ranking related data for stocks, 
  whatever you like to have in a table for Excel analysis and 
  recall.
  <SPAN 
  class=840460112-20012004>dynamic Watchlists, i.e. enable stocks on the basis 
  of their being consituent in an Index. You could Explore all annual lists 
  to built a master table for all stocks ever traded in the index and 
  save the start-trading and stop trading dates for each stock. When 
  backtesting you use this data to enable trading the stock or not. To 
  do this properly this must be done using the PositionScore, perhaps set a very 
  High scrore for Short positions and a very Low score for Long positions to 
  disable stocks. That way they will be skipped but your portfolio keeps trading 
  the same number of stocks. 
  <SPAN 
  class=840460112-20012004>You could probably use the functions to develop code 
  to skip top-ranked stocks .... but i haven't tried 
  it. 
<SPAN 
class=840460112-20012004>There is no limit to the number of parameter-sets that 
can be saved. To use the functions you must copy the 
ParameterTableInclude001.afl program listed below to your Include Directory. The 
functions are designed for ease of use, not for speed. For more complicated 
tasks and better speed you should learn to call the OSAKA functions 
directly. To use multiple tables just substitute other names for 
"ParamaterTable"
<SPAN 
class=840460112-20012004> 
1) 
SaveParameters( "Name", Number1, Number2, Number3, Number4, Number5 
); 
<FONT 
face=Arial size=2>This function saves 5 different parameters under one name 
a ticker name, a variable name, or a dynamically created name. If you set 
one or more numbers to NULL then that particular number will not change in 
the table and the previous value will remain valid. The length of the name is 
limited to 30 char. 
<FONT 
face=Arial size=2><FONT 
face=Arial>2) 
P=GetParameters( "Name" 
); 
The function returns 
an array; the parameters are stored in elements1-5. To use the variables 
under their original names you would use P1=O[1]; P2=P[2]; P3=P[3]; P4=P[4]; and 
P5=P[5]; I reserved P[0] for other uses.
 
3) 
OutputParameterTable( Flag 
); 
Flag = 0 dumps 
the parameter table to the interpretation window from an indicator or using the 
Equity button in the AA.
Flag = 1 use the 
Explorer to display the table contents for the stocks in the current Watchlist, 
does not list names not in the Watchlist.
Flag = 2 creates a 
ParameterTable.csv file in the AmiBroker directory for import into 
Excel.
<FONT face=Arial 
size=2> 
For a quick 
test:
<FONT face=Arial 
size=2> 
1) Copy the 
Include file to your Include Directory and load the code in your AA, select a 
Watch list, set a range, and Run the OldBacktester, click Equity to run the 
formula as an Indicator to display the table in your interpretation window. Note 
that the current stock, if it is not in your Watchlist, is still included in 
your ParameterTable. I do almost all my system/indicator development from the AA 
window but the functions should work from anywhere in 
AmiBroker.
<FONT face=Arial 
size=2> 
2) Run the 
Exporer on you Watchlist to display all variable save for it's 
membership.
<FONT face=Arial 
size=2> 
3) Run Excel 
and import the ParameterTable.csv file.
<FONT face=Arial 
size=2> 
have 
fun!
<FONT face=Arial 
size=2>herman
<FONT face=Arial 
size=2> 



<FONT face=Arial 
size=2> 
// Test 
program for the OSAKA parameter functions 
<FONT 
color=#ff0000>Buy=<FONT 
color=#ff0000>Sell=<FONT 
color=#ff0000>Short=<FONT 
color=#ff0000>Cover=<FONT 
color=#ff00ff>0<FONT 
color=#000000>; Filter<FONT 
color=#000000> = Status<FONT 
color=#000000>("LastBarInRange"<FONT 
color=#000000>); // Or set n-Last-Quotations to 
1 
#include<FONT 
size=2> 
<ParameterTableInclude001.afl> // 
Create some dummy data...<FONT 
face=Arial> T1=<FONT 
color=#0000ff>Status(<FONT 
color=#ff00ff>"StockNum"<FONT 
color=#000000>); T2=LastValue<FONT 
color=#000000>(DateNum<FONT 
size=2>()); T3=<FONT 
color=#ff0000>BarCount<FONT 
face=Arial>; T4=<FONT 
color=#0000ff>LastValue(<FONT 
color=#0000ff>Random<FONT 
color=#000000>()); T5=<FONT 
color=#ff00ff>12345<FONT 
color=#000000>; SaveParameters( <FONT 
color=#0000ff>Name(), T1, T2, T3, T4, T5 ); 
   // Save 5 parameters under 
ticker<FONT 
color=#000000> SaveParameters( Name<FONT 
color=#000000>(), T1, Null<FONT 
color=#000000>, T3, Null<FONT 
color=#000000>, T5 );// Update only 3 of 
them 
SaveParameters( "Test1"<FONT 
color=#000000>, 1<FONT 
color=#000000>,2<FONT 
color=#000000>,3<FONT 
color=#000000>,4<FONT 
color=#000000>,5<FONT 
color=#000000>);      <FONT 
color=#000000>// Save an arbitrary variable<FONT 
size=2> 
OutputParameterTable(1<FONT 
color=#000000>|2<FONT 
color=#000000>|4); 
         <FONT 
color=#000000>// Review table in various 
formats<FONT 
color=#000000> P=GetParameters( Name<FONT 
color=#000000>() 
);         <FONT 
color=#000000>// Read ticker parameters from 
table 
T=GetParameters("Test1"<FONT 
color=#000000>);         <FONT 
color=#000000>// Read arbitrary variable from 
table 




 
// ParameterTableInclude001.afl --- Copy 
this file to your AmiBroker Include Directory
osInitialize<FONT 
size=2>(); <FONT 
color=#ff0000>function<FONT 
face=Arial> SaveParameters( Ticker, P1, P2,P3,P4,P5 ) 
   {    <FONT 
color=#ff0000>global<FONT 
face=Arial> ParameterTable; 
   <FONT 
color=#ff0000>local<FONT 
face=Arial> RowCount, TickerRow, Row, P1, P2, P3, P4, P5; 
   ParameterTable = <FONT 
color=#0000ff>osTabCreate<FONT 
face=Arial>();    <FONT 
color=#ff0000>if( <FONT 
color=#0000ff>osTabLoad(<FONT 
== 0<FONT 
face=Arial> )       { 
      <FONT 
color=#0000ff>osTabAddColumn( <FONT 
color=#ff00ff>"Symbol", <FONT 
color=#ff00ff>2, 
ParameterTable,  <FONT 
color=#ff00ff>30<FONT 
color=#000000> );       <FONT 
color=#0000ff>osTabAddColumn( <FONT 
color=#ff00ff>"P1", <FONT 
color=#ff00ff>1<FONT 
color=#000000>, ParameterTable ); 
      <FONT 
color=#0000ff>osTabAddColumn( <FONT 
color=#ff00ff>"P2", <FONT 
color=#ff00ff>1<FONT 
color=#000000>, ParameterTable ); 
      <FONT 
color=#0000ff>osTabAddColumn( <FONT 
color=#ff00ff>"P3", <FONT 
color=#ff00ff>1<FONT 
color=#000000>, ParameterTable ); 
      <FONT 
color=#0000ff>osTabAddColumn( <FONT 
color=#ff00ff>"P4", <FONT 
color=#ff00ff>1<FONT 
color=#000000>, ParameterTable ); 
      <FONT 
color=#0000ff>osTabAddColumn( <FONT 
color=#ff00ff>"P5", <FONT 
color=#ff00ff>1<FONT 
color=#000000>, ParameterTable ); 
      <FONT 
color=#0000ff>osTabSave(<FONT 
face=Arial>, ParameterTable ); 
      }    RowCount = 
osTabGetRowCount<FONT 
size=2>( ParameterTable ); 
   TickerRow = -<FONT 
color=#ff00ff>1<FONT 
color=#000000>;    <FONT 
color=#ff0000>for( Row = <FONT 
color=#ff00ff>0<FONT 
color=#000000>; Row <= RowCount; Row++ ) 
      { 
      <FONT 
color=#ff0000>if( Ticker == <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>0<FONT 
color=#000000>,  ParameterTable )) TickerRow = Row; 
      }    <FONT 
color=#ff0000>if(TickerRow < <FONT 
color=#ff00ff>0<FONT 
color=#000000>)       Row=RowCount; 
   <FONT 
color=#ff0000>else<FONT 
face=Arial>       Row = 
TickerRow;    <FONT 
color=#0000ff>osTabSetString( Ticker, Row, 
0<FONT 
face=Arial>, ParameterTable ); 
   if<FONT 
color=#000000>(Nz<FONT 
color=#000000>(P1,0)==P1) 
   osTabSetNumber<FONT 
color=#000000>( P1, Row, 1<FONT 
size=2>, ParameterTable ); 
   if<FONT 
color=#000000>(Nz<FONT 
color=#000000>(P2,0)==P2) 
   osTabSetNumber<FONT 
color=#000000>( P2, Row, 2<FONT 
size=2>, ParameterTable ); 
   if<FONT 
color=#000000>(Nz<FONT 
color=#000000>(P3,0)==P3) 
   osTabSetNumber<FONT 
color=#000000>( P3, Row, 3<FONT 
size=2>, ParameterTable ); 
   if<FONT 
color=#000000>(Nz<FONT 
color=#000000>(P4,0)==P4) 
   osTabSetNumber<FONT 
color=#000000>( P4, Row, 4<FONT 
size=2>, ParameterTable ); 
   if<FONT 
color=#000000>(Nz<FONT 
color=#000000>(P5,0)==P5) 
   osTabSetNumber<FONT 
color=#000000>( P5, Row, 5<FONT 
size=2>, ParameterTable ); 
   osTabSave<FONT 
color=#000000>(<FONT 
face=Arial>, ParameterTable ); 
   <FONT 
color=#0000ff>osTabDelete<FONT 
face=Arial>( ParameterTable );    } 
function<FONT 
size=2> OutputParameterTable( Destination ) 
   {    <FONT 
color=#ff0000>local<FONT 
face=Arial> Row, RowCount, NOTable, Destination, OutPut; 
   <FONT 
color=#ff0000>global<FONT 
face=Arial> ParameterTable; 
   ParameterTable = <FONT 
color=#0000ff>osTabCreate<FONT 
face=Arial>();    <FONT 
color=#ff0000>if( <FONT 
color=#0000ff>osTabLoad(<FONT 
== 1<FONT 
face=Arial> ) 
      RowCount = <FONT 
color=#0000ff>osTabGetRowCount<FONT 
face=Arial>( ParameterTable );    OutPut 
= ""<FONT 
face=Arial>;    <FONT 
color=#ff0000>if( Destination & 
1  ) 
// To Interpretation 
window<FONT 
color=#000000>       { 
      <FONT 
color=#ff0000>for( Row = <FONT 
color=#ff00ff>0<FONT 
color=#000000>; Row < RowCount; Row++ ) 
         { 
         OutPut = OutPut + 
         <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>0,  ParameterTable 
)+", "<FONT 
face=Arial>+ 
         <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>1,  ParameterTable 
)+", "<FONT 
face=Arial>+ 
         <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>2,  ParameterTable 
)+", "<FONT 
face=Arial>+ 
         <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>3,  ParameterTable 
)+", "<FONT 
face=Arial>+ 
         <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>4,  ParameterTable 
)+", "<FONT 
face=Arial>+ 
         <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>5,  ParameterTable 
)+"\n"<FONT 
face=Arial>; 
         } 
      }    <FONT 
color=#ff0000>if( Destination & 
2  ) 
// To Exploration Results 
window<FONT 
color=#000000>       { 
      <FONT 
color=#0000ff>SetOption(<FONT 
color=#ff00ff>"NoDefaultColumns",<FONT 
color=#ff0000>True<FONT 
face=Arial>); 
      TickerRow = -<FONT 
color=#ff00ff>1<FONT 
color=#000000>;       <FONT 
color=#ff0000>for( Row = <FONT 
color=#ff00ff>0; Row < <FONT 
color=#0000ff>osTabGetRowCount<FONT 
face=Arial>( ParameterTable ); Row++ ) 
         <FONT 
color=#ff0000>if( <FONT 
color=#0000ff>Name() == <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>0<FONT 
color=#000000>,  ParameterTable )) TickerRow = Row; 
      <FONT 
color=#ff0000>if(TickerRow >= <FONT 
color=#ff00ff>0<FONT 
color=#000000> )       <FONT 
color=#0000ff>AddTextColumn<FONT 
face=Arial>( 
             <FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>0<FONT 
color=#000000>,  ParameterTable),<FONT 
color=#ff00ff>"WLTicker",<FONT 
color=#ff00ff>1.0<FONT 
color=#000000>);       <FONT 
color=#0000ff>AddColumn(<FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>1,  ParameterTable 
),"Par1",<FONT 
color=#ff00ff>1.4<FONT 
color=#000000>);       <FONT 
color=#0000ff>AddColumn(<FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>2,  ParameterTable 
),"Par2",<FONT 
color=#ff00ff>1.4<FONT 
color=#000000>);       <FONT 
color=#0000ff>AddColumn(<FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>3,  ParameterTable 
),"Par3",<FONT 
color=#ff00ff>1.4<FONT 
color=#000000>);       <FONT 
color=#0000ff>AddColumn(<FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>4,  ParameterTable 
),"Par4",<FONT 
color=#ff00ff>1.4<FONT 
color=#000000>);       <FONT 
color=#0000ff>AddColumn(<FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>5,  ParameterTable 
),"Par5",<FONT 
color=#ff00ff>1.4<FONT 
color=#000000>);          } 
   if<FONT 
color=#000000>(Destination & 4<FONT 
color=#000000> ) // To csv 
file 
      { 
      <FONT 
color=#0000ff>osTabExport( <FONT 
color=#ff00ff>"ParameterTable.csv", <FONT 
color=#ff00ff>","<FONT 
color=#000000>, ParameterTable);       } 
   <FONT 
color=#ff0000>return<FONT 
face=Arial> Output;    } 
function<FONT 
size=2> GetParameters( Ticker ) 
   {    <FONT 
color=#ff0000>local<FONT 
face=Arial> Row, RowCount, NOTable, Destination, OutPut, 
TickerRow;    <FONT 
color=#ff0000>global<FONT 
face=Arial> ParameterTable; 
   ParameterTable = <FONT 
color=#0000ff>osTabCreate<FONT 
face=Arial>();    Parameter[<FONT 
color=#ff00ff>0] = -<FONT 
color=#ff00ff>1; // 
First Element is used to pass table status<FONT 
size=2>    <FONT 
color=#ff0000>if( <FONT 
color=#0000ff>osTabLoad(<FONT 
== 1<FONT 
face=Arial> )       { 
      ParameterArray = <FONT 
color=#ff00ff>0<FONT 
color=#000000>;       RowCount = <FONT 
color=#0000ff>osTabGetRowCount<FONT 
face=Arial>( ParameterTable ); 
      <FONT 
color=#ff0000>for( Row = <FONT 
color=#ff00ff>0; Row < <FONT 
color=#0000ff>osTabGetRowCount<FONT 
face=Arial>( ParameterTable ); Row++ ) 
         <FONT 
color=#ff0000>if( <FONT 
color=#0000ff>Name() == <FONT 
color=#0000ff>osTabGet( Row, <FONT 
color=#ff00ff>0<FONT 
color=#000000>,  ParameterTable )) TickerRow = Row; 
      ParameterArray[<FONT 
color=#ff00ff>1] = <FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>1<FONT 
color=#000000> , ParameterTable ); 
      ParameterArray[<FONT 
color=#ff00ff>2] = <FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>2<FONT 
color=#000000> , ParameterTable ); 
      ParameterArray[<FONT 
color=#ff00ff>3] = <FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>3<FONT 
color=#000000> , ParameterTable ); 
      ParameterArray[<FONT 
color=#ff00ff>4] = <FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>4<FONT 
color=#000000> , ParameterTable ); 
      ParameterArray[<FONT 
color=#ff00ff>5] = <FONT 
color=#0000ff>osTabGet( TickerRow, <FONT 
color=#ff00ff>5<FONT 
color=#000000> , ParameterTable ); 
      }    
   <FONT 
color=#ff0000>return<FONT 
face=Arial size=2> ParameterArray;    } 
 
 
 

<FONT face=Arial 
size=2> 
<FONT face=Arial 
size=2> 
<FONT face=Arial 
size=2> 
<FONT face=Arial 
size=2> 
<FONT face=Arial 
size=2> 


Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html





Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.