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

[amibroker] Re: Automation to load an AFL and run Portfolio Optimization



PureBytes Links

Trading Reference Links

Thanks for the input so far. Searched the group for Jscript automation
examples and found a handful. They've helped but I'm still trying to
figure out the last piece...

What I want to automate is:

(a) Load an AFL and run a portfolio optimization for a given date
range. [done]

(b) From the above optimization, sort by an optimization metric, e.g.
Net Profit, and then save to a text file, in a single column, all of
the optimized variables that correspond to a minimum level of Net Profit.

So for example, if the loaded AFL optimizes the single variable
"FastMALength", and my Net Profit target min is $500, then save all
values of "FastMALength" that correspond to a Net Profit > $500.

I'm having trouble with (b). Do I first need to export the AA report
to csv, using AA.Export()and then build some kind of Excel automation
to import, parse and save the values I want? Or is there an easier
(and faster) way to achieve this? 

Once an AA report is run, does it reside in memory somewhere, and can
it be parsed and manipulated with either AFL or Jscript code?



--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> wrote:
>
> You can only automate AA from OUTSIDE of AA.
> 
> I.e. the script should be EXTERNAL JScript, not an AFL run from AA
befcause it will be
> immediatelly overwritten in first iteration.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
>   ----- Original Message ----- 
>   From: ozzyapeman 
>   To: amibroker@xxxxxxxxxxxxxxx 
>   Sent: Friday, December 19, 2008 3:12 AM
>   Subject: [amibroker] Re: Automation to load an AFL and run
Portfolio Optimization
> 
> 
>   The simplified code below runs without any syntax error. However,
instead of optimizing through all 100 steps, it only does a single
step. Any idea why doesn't it do all 100 steps, as coded in the Simple
MA Cross afl?:
> 
> 
>  
//----------------------------------------------------------------------------
>   // AUTOMATION CODE: Load an AFL and Run a Portfolio Optimization 
>  
//----------------------------------------------------------------------------
> 
>   EnableScript("jscript");
>   <%
> 
>   database  = "C:\\Program Files\\Amibroker\\Data";
>   formula_1 = "C:\\Simple MA Cross.afl";
> 
>   AB  = new ActiveXObject( "Broker.Application" );   
>   AB.LoadDatabase( database );
>   AA  = AB.Analysis;    
> 
>   AA.LoadFormula( formula_1 );              // load formula from
external file 
> 
>   AA.ApplyTo       = 1;                     // use current symbol
>   AA.RangeMode     = 3;                     // use 'From' and 'To'
dates 
>   AA.RangeFromDate = "11/01/2005";
>   AA.RangeToDate   = "12/31/2005";
>   AA.Optimize( 0 );                         // run Optimize for the
portfolio, which is just one symbol
>   //AA.Backtest();
> 
>   %>
>   //---------END AUTOMATION
AFL-------------------------------------------------
> 
> 
>    
>   --- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@> wrote:
>   >
>   > Hoping someone can chime in here to let me know what I might be
doing
>   > wrong. I'm currently testing out some simple automation code. The
>   > objective is to load an AFL and then run a portfolio
optimization for a
>   > specified date range.
>   > 
>   > I am using a simple MA crossover trading system for testing
purposes. I
>   > can of course optimize it manually in AA without any problem.
But when I
>   > try to run and control that optimization from a piece of automation
>   > code, I get a whole range of syntax errors.
>   > 
>   > Below are the two *separate* AFL codes. I imagine the first AFL
has some
>   > errors in it that is preventing the actions from being carried out
>   > properly. What am I missing or doing wrong? Any input much
appreciated:
>   > 
>   >
//----------------------------------------------------------------------\
>   > ------
>   > // AUTOMATION CODE: Load an AFL and Run a Portfolio Optimization
>   >
//----------------------------------------------------------------------\
>   > ------
>   > 
>   > EnableScript("jscript");
>   > <%
>   > 
>   > database = "C:\\Program Files\\Amibroker\\Data";
>   > formula_1 = "C:\\Simple MA Cross.afl";
>   > 
>   > AB = new ActiveXObject( "Broker.Application" );
>   > AB.LoadDatabase( database );
>   > AA = AB.Analysis;
>   > Stk = AB.Stocks
>   > Doc = AB.Documents.Open( Stk.Ticker );
>   > 
>   > AA.LoadFormula( formula_1 ); // load formula from external
>   > file
>   > 
>   > AA.ApplyTo = 1; // use current symbol
>   > AA.RangeMode = 3; // use 'From' and 'To' dates
>   > AA.RangeFromDate = "11/01/2005";
>   > AA.RangeToDate = "12/31/2005";
>   > AA.Optimize( 0 ); // run Optimize for the
>   > portfolio, which is just one symbol
>   > AA.Backtest();
>   > 
>   > %>
>   > //---------END AUTOMATION
>   > AFL-------------------------------------------------
>   > 
>   > 
>   > 
>   > 
>   > 
>   >
//----------------------------------------------------------------------\
>   > ------
>   > // Simple MA Cross: THIS IS A SEPARATE AFL SAVED AT: "C:\\Simple MA
>   > Cross.afl"
>   >
//----------------------------------------------------------------------\
>   > ------
>   > 
>   > 
>   > FastMALength = Optimize("FastMALength", 1, 1, 100, 1);
>   > SlowMALength = 20;
>   > 
>   >
//----------------------------------------------------------------------\
>   > ------
>   > // BACKTESTER SETTINGS
>   >
//----------------------------------------------------------------------\
>   > ------
>   > 
>   > SetBarsRequired(10000, 0);
>   > SetOption("AllowPositionShrinking", False);
>   > SetOption("AllowSameBarExit", True);
>   > SetOption("CommissionAmount", 3.00);
>   > SetOption("CommissionMode", 3);
>   > SetOption("FuturesMode", 1);
>   > SetOption("InitialEquity", 100000);
>   > SetOption("InterestRate",0);
>   > SetOption("MaxOpenPositions", 1);
>   > SetOption("MinPosValue", 0);
>   > SetOption("MinShares", 1);
>   > SetOption("PriceBoundChecking", False );
>   > SetOption("ReverseSignalForcesExit", False);
>   > SetOption("UsePrevBarEquityForPosSizing", True );
>   > SetTradeDelays(0, 0, 0, 0);
>   > SetPositionSize(1, spsShares);
>   > TickSize = 0.0001; // The minimum price move of symbol for Forex
>   > PointValue = 100000;
>   > RoundLotSize = 1;
>   > MarginDeposit = 2500;
>   > BuyPrice = SellPrice = ShortPrice = CoverPrice = Close;
>   > 
>   >
//----------------------------------------------------------------------\
>   > --
>   > // TRADING SYSTEM
>   >
//----------------------------------------------------------------------\
>   > --
>   > 
>   > FastMA = MA( C, FastMALength );
>   > SlowMA = MA( C, SlowMALength );
>   > Buy = Cross( FastMA, SlowMA );
>   > Sell = Cross( SlowMA, FastMA );
>   >
>



------------------------------------

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

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

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

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/