{"id":13,"date":"2006-03-11T14:32:51","date_gmt":"2006-03-11T19:32:51","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/2006\/03\/11\/how-to-create-copy-of-portfolio-equity\/"},"modified":"2014-12-06T06:53:48","modified_gmt":"2014-12-06T11:53:48","slug":"how-to-create-copy-of-portfolio-equity","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2006\/03\/11\/how-to-create-copy-of-portfolio-equity\/","title":{"rendered":"How to create copy of portfolio equity?"},"content":{"rendered":"

As you know Portfolio backtester creates special ticker “~~~EQUITY” which holds portfolio-level equity of the system under test. Some may find it useful to save this equity into another symbol after backtest for future analysis and\/or comparison. Good news is that it is possible to do that automatically using custom backtester procedure<\/a> and AddToComposite<\/a> function. The formula below shows how.

<\/span>\/\/ A pre-5.50 way of making portfolio copy
\/\/ YOUR TRADING SYSTEM HERE
\/\/ ....
<\/span>SetCustomBacktestProc<\/span>(<\/span>""<\/span>);
if( <\/span>Status<\/span>(<\/span>"action"<\/span>) == <\/span>actionPortfolio <\/span>)
{
 <\/span>bo <\/span>= <\/span>GetBacktesterObject<\/span>();
 <\/span>bo<\/span>.<\/span>Backtest<\/span>();
 <\/span>AddToComposite<\/span>( <\/span>Foreign<\/span>(<\/span>"~~~EQUITY"<\/span>,<\/span>"C"<\/span>),
                 <\/span>"~~~MY_EQUITY_COPY"<\/span>, <\/span>"X"<\/span>,
                 <\/span>atcFlagDeleteValues <\/span>| <\/span>atcFlagEnableInPortfolio <\/span>);
<\/code>

Please note that prior to version 4.78.1 BETA, atcFlagEnableInPortfolio did not work in combination with atcFlagCompositeGroup (or atcFlagDefaults) so we needed to avoid this flag in the code above, to make it work fine with previous versions of AmiBroker. In version 4.78.1 it works with all combinations of flags, so you don’t need to worry about this any more.As you know Portfolio backtester creates special ticker <\/p>

IMPORTANT UPDATE<\/strong>: As of AmiBroker version 5.50 a new property of Backtester object is available: EquityArray that should be used instead of Foreign(“~~~EQUITY”,”C”). This is so because now backtester can be run in many instances and each instance has its own, private equity. So for AmiBroker 5.50 correct code looks as follows:
<\/span>\/\/ The code for AmiBroker 5.50 and above
\/\/ YOUR TRADING SYSTEM HERE
\/\/ ....
<\/span>SetCustomBacktestProc<\/span>(<\/span>""<\/span>);
if( <\/span>Status<\/span>(<\/span>"action"<\/span>) == <\/span>actionPortfolio <\/span>)
{
 <\/span>bo <\/span>= <\/span>GetBacktesterObject<\/span>();
 <\/span>bo<\/span>.<\/span>Backtest<\/span>();
 <\/span>AddToComposite<\/span>( <\/span>bo<\/span>.<\/span>EquityArray<\/span>,
                 <\/span>"~~~MY_EQUITY_COPY"<\/span>, <\/span>"X"<\/span>,
                 <\/span>atcFlagDeleteValues <\/span>| <\/span>atcFlagEnableInPortfolio <\/span>);
<\/code>","protected":false},"excerpt":{"rendered":"

As you know Portfolio backtester creates special ticker “~~~EQUITY” which holds portfolio-level equity of the system under test. Some may find it useful to save this equity into another symbol after backtest for future analysis and\/or comparison. Good news is that it is possible to do that automatically using custom backtester procedure and AddToComposite function. […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[43,53,14,15,30],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/13"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":806,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/13\/revisions\/806"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}