I would need to export positions/exposure for each symbol for each bar from Amibroker (in some .afl writing to csv file). The resulting export should look something like:
index AMD CERN COST DELL GPS INTC MMM cash
2004-01-09 6961.92 21017.07875 7282.266152 21264.55188 7091.08002 21259.33389 21316.12961 -6192.360298
2004-01-12 18198.58 18071.25 17675.8364 10804.31924 10685.41187 17872.47748 10882.0264 -3329.289887
2004-01-13 12060.86 11942.24625 12838.47745 16078.9038 16272.139 12465.39251 12579.13576 4708.039735
2004-01-14 13102.4 15534.28125 14447.42264 15414.4508 15666.44019 14884.06962 13454.54262 -2749.47003
2004-01-15 15518.4 14547.05 14164.03968 14407.48813 14926.12262 14422.38586 13929.15905 -2462.919316
2004-01-16 15670.6 14817.6875 14164.03968 14359.58256 13890.35178 14251.92581 14507.59497 -715.717096
How can this be done?
Does there perhaps already exist some afl code somewhere doing similar thing?
I can see that getting "cash" is straightforward since it is part of ~~~EQUITY (Low). But there is also Backtester object property: double Cash - available funds (cash) in your portfolio (does this hold cash for each bar?)
For the positions/exposure per symbol per bar the only thing that comes to mind is mid level custom backtester as per the post here: MarketPosition and alternate exit condition - #4 by Tomasz
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject(); // Get backtester object
bo.PreProcess(); // Do pre-processing (always required)
for ( i = 0; i < BarCount; i++ ) // Loop through all bars
{
bo.ProcessTradeSignals( i ); // Process trades at bar (always required)
for ( openpos = bo.GetFirstOpenPos(); openpos; openpos = bo.GetNextOpenPos() )
{
// openpos variable now holds Trade object - you can query it
}
} // End of for loop over bars
bo.PostProcess(); // Do post-processing (always required)
}
Thanks.