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

[amibroker] Re: How to import XYZ csv data into AB 3D optimization graph?



PureBytes Links

Trading Reference Links



Strictly speaking, the answer is yes. But, from a practical standpoint the answer is probably no.

The 3-d rendering works off of the current .afl file loaded in the AA window. You would have to have an .afl script with exactly two Optimize statements, and two of your data columns would have to exactly match the combinations of the Optimize values. For example;

Given

column1 = Optimize( "Column1", 1, 1, 4, 1 );
column2 = Optimize( "Column2", 1, 1, 4, 1
);

AmiBroker will expect your data to have 16 rows of data with the following combinations (column1, column2, ?) where ? is whatever third value you want to graph:

1,1,?
2,1
,?
3,1
,?
4,1
,?
1,2
,?
2,2
,?
3,2
,?
4,2
,?
1,3
,?
2,3
,?
3,3
,?
4,3
,?
1,4
,?
2,4
,?
3,4
,?
4,4
,?

If your data is able to respect that limitation, then you can:

  1. Run an optimization on "current symbol" which reads the .csv file and generates a .html file
  2. Import the generated .html file
  3. Sort by the data originally found in the 3rd column of the .csv file
  4. Open the 3-d viewer.

Below is a sample script (not the most efficient, but it will do) that will do step 1 for you (hard coded to 16 rows at the moment, assumes linear values 1-4 for each of column1 and column2, can use any value for column3). Note too that it is brittle in that any change to the format by Tomasz will impact the script.

Mike

procedure WriteHeader()
{
    
local
fh;

    fh =
fopen( "c:\\temp\\mydata.html", "w"
);

    
if
( fh )
    {
        
fputs( "<HTML>\n"
, fh );
        
fputs( "<STYLE>\n"
, fh );
        
fputs( "<!--\n"
, fh );
        
fputs( "BODY { font-family:\"Tahoma,Arial,Helvetica,Sans Serif\"; }\n"
, fh );
        
fputs( "TD { text-align: right; }\n"
, fh );
        
fputs( "-->\n"
, fh );
        
fputs( "</STYLE>\n"
, fh );
        
fputs( "<!-- ABEXC: Type=7, ReportPath= --><BODY>\n"
, fh );
        
fputs( "<TABLE border=0>\n"
, fh );
        
fputs( "<TR><TH id=1>No.</TH><TH id=1>Net Profit</TH><TH id=1>Net % Profit</TH><TH id=1>Exposure %</TH><TH id=1>CAR</TH><TH id=1>RAR</TH><TH id=1>Max. Trade Drawdown</TH><TH id=1>Max. Trade % Drawdown</TH><TH id=1>Max. Sys Drawdown</TH><TH id=1>Max. Sys % Drawdown</TH><TH id=1>Recovery Factor</TH><TH id=1>CAR/MDD</TH><TH id=1>RAR/MDD</TH><TH id=1>Profit Factor</TH><TH id=1>Payoff Ratio</TH><TH id=1>Standard Error</TH><TH id=1>RRR</TH><TH id=1>Ulcer Index</TH><TH id=1>Ulcer Perf. Index</TH><TH id=1>Sharpe Ratio</TH><TH id=1>K-Ratio</TH><TH id=1># Trades</TH><TH id=1>Avg Profit/Loss</TH><TH id=1>Avg % Profit/Loss</TH><TH id=1>Avg Bars Held</TH><TH id=1># of winners</TH><TH id=1>% of Winners</TH><TH id=1>W. Tot. Profit</TH><TH id=1>W. Avg. Profit</TH><TH id=1>W. Avg % Profit</TH><TH id=1>W. Avg. Bars Held</TH><TH id=1># of losers</TH><TH id=1>% of Losers</TH><TH id=1>L. Tot. Loss</TH><TH id=1>L. Avg. Loss</TH><TH id=1>L. Avg % Loss</TH><TH id=1>L. Avg. Bars Held</TH><TH id=1>Value</TH><TH id=1>Column1</TH><TH id=1>Column2</TH></TR>\n"
, fh );
        
fclose
( fh );
    }
}

function
ReadLine( line )
{
    
local
fh, i, values;

    fh =
fopen( "c:\\temp\\mydata.csv", "r"
);

    
if
( fh )
    {
        
for ( i = 0
; i < line; i++ )
        {
            
if ( feof
( fh ) )
            {
                values =
"0,0,0"
;
                
break
;
            }
            
else

            {
                values =
fgets
( fh );
            }
        }

        
fclose
( fh );
    }
    
else

    {
        values =
"0,0,0"
;
    }

    
_TRACE
( values ); 
    
return
values;
}

procedure
WriteLine( line )
{
    
local
values, col1, col2, col3;
    
local
fh, i;

    values = ReadLine( line );
    col1 =
StrExtract( values, 0
);
    col2 =
StrExtract( values, 1
);
    col3 =
StrExtract( values, 2
);

    fh =
fopen( "c:\\temp\\mydata.html", "a"
);

    
if
( fh )
    {
        
fputs( "<TR><TD>" + line + "</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>" + col3 + "</TD><TD>" + col1 + "</TD><TD>" + col2 + "</TD></TR>\n"
, fh );
        
fclose
( fh );
    }
}

procedure
WriteFooter()
{
    
local
fh;

    fh =
fopen( "c:\\temp\\mydata.html", "a"
);

    
if
( fh )
    {
        
fputs( "</TABLE>\n"
, fh );
        
fputs( "</BODY>\n"
, fh );
        
fputs( "</HTML>\n"
, fh );
        
fclose
( fh );
    }
}

rows =
16
;
column1Max =
sqrt
( rows );
column2Max =
sqrt
( rows );
column1 = Optimize( "Column1", 1, 1, column1Max, 1
);
column2 = Optimize( "Column2", 1, 1, column2Max, 1
);
counter = ( (
column2 - 1 ) * column1Max ) + column1
;

if ( counter == 1
)
{
    WriteHeader();
}

Buy = Sell = 1
;
SetCustomBacktestProc( ""
);

if ( Status( "action" ) == actionPortfolio
)
{
    bo =
GetBacktesterObject
();
    bo.Backtest();
    bo.AddCustomMetric(
"Value", 0
);

    WriteLine( counter );

    
if
( counter == rows )
    {
        WriteFooter();
    }
}


--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> Hello, wondering if anyone has done this before - If I have a csv data file containing three data columns, is there a way to import this into the AA so I can use AB's 3D graphing utility to see the 3D plot?
>
> It seems that AB can only import it's own specific HTML format, not plain old CSV.
>
> So then an alternate question is - can a CSV file, as previously described, be easily converted into AB's required HTML format, either with a utility or via some kind of scripting? Can anyone point me to a basic methodology? The only scripting language I have a basic handle on is _vbscript_. Hoping this is not too complex.
>



__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___