Adaptive Asset Allocation (AAA)
Author: crk31174
Creation Date: 7/3/2015 10:13 AM
profile picture

crk31174

#1
Folks,

I have a rotation strategy in Amibroker which is based on AAA. It was developed in collaboration with TrendXplorer,(http://indexswingtrader.blogspot.com/) Would like to convert to a Wealth-Lab strategy

It is based on deriving a composite rank from Momentum, Correlation and Volatility Ranks. In the Fidelity Sector Fund Rotation strategy code, I see it ranks by Momentum. But I need a way to rank by Correlation and Volatility as well and be able to derive a composite rank for every symbol in the DataSet. Composite rank can then be used to pick the top 1,2, or 3 symbols from the DataSet.

Can this be done in Wealth-Lab? If so, can someone provide a sample code.

if you like, I can share the Amibroker code.I am new to Wealthlabs and still learning the ropes.



Many Thanks,
profile picture

Eugene

#2
QUOTE:
But I need a way to rank by Correlation and Volatility as well and be able to derive a composite rank for every symbol in the DataSet. Composite rank can then be used to pick the top 1,2, or 3 symbols from the DataSet.


Please check out this FAQ > Rotation strategies > I need other rotation rule other than the built-in RSI.

This downloadable strategy presents an example of combined ranking by averaging an indicator with 3 periods: Efficient Rotation Strategy (Rev. C)

Mixing two rankings to arrive at a new list (medium complexity): Combined rotation/ranking question
profile picture

crk31174

#3
Thanks Eugene.

Do you know how to code for triggering the rotation strategy to enter/exit positions before close on the last day of the month? Basically I would like to have the strategy evaluate only on the last day of the month.


profile picture

Eugene

#4
QUOTE:
Do you know how to code for triggering the rotation strategy to enter/exit positions before close on the last day of the month?


Naturally, the simplest solution is to change the entries/exits to *AtClose and switch the chart to be run on Monthly scale:

Monthly or Quarterly Rotation strategy from basket of three ETFs (SPY,EFA,EEM)

P.S. A couple more ideas if you don't mind some coding:

SetScaleMonthly with Rotation strategy
Fidelity Select Sector Fund Rotation System, posts #17-23
profile picture

crk31174

#5
Thanks, Eugene. Much appreciated. I think the coding approach may suit my needs.

Next question is about position sizing. Strategy that i am considering to build, will pick a maximum number of 3 symbols based on relative strength only if absolute momentum (i.e. 3 months ROC) > 0. So, the selection may return etiher 1 or 2 or 3 symbols. If selection returns 3 symbols, then i would like to invest 33% equity in in each of the symbol

But if it returns only 1 or 2 symbols, I would like to allocate remaining equity to one of the cash proxy ( IEF, SHY, BIL) based on their 3 month ROC > 0 as per the following pseudo-code:

CODE:
Please log in to see this code.

How can I achieve this in Wealthlab?

Thanks,

profile picture

Eugene

#6
Canned solution does not exist. You may want to check out Cone's reply #6 to a similar problem here:

Trade Specific External Symbol if Conditions are met / not met

profile picture

crk31174

#7
Thanks for pointing in the right direction, Eugene.

Using the Priority Pos Sizer, I was able to define 33% allocation for each of the 1, or 2 or 3 symbols selected. But on running the strategy, I see a popup saying "some of the trades were not included". Need your help !!!!

Please find the code below for your reference.



CODE:
Please log in to see this code.
profile picture

Eugene

#8
Nice code. Unfortunately, there's not much I can suggest (and this FAQ doesn't really apply):

1. Reduce the position size as much as possible (25%, 20% etc.)
2. Bump up Margin Factor slightly above 1 (or any even number for this matter) e.g. 1.05, 2.05 etc.
3. If you weren't using the Position Priority PosSizer, I'd recommend activating the following options in the Position Options PosSizer: "Skipped Trade Solution" (but here it's not applicable due to use of AtClose orders) and Max Open Positions > "For last position, use all what's left".
profile picture

crk31174

#9
Both your suggestions 1. and 2. works - When I reduce the position size to 15%, OR increase margin factor to 2.01.

But, I am unsure if system performance is getting reduced by doing so. Do you know if this workaround is due to a Wealth lab issue OR should I consider developing a custom PosSizer?

Thanks,
profile picture

Eugene

#10
The system performance is certainly affected by reducing the position size twice to 15% due to a lower exposure (this leaves a lot of cash uninvested). I'm fine if MF 1.01 (2.01 etc.) works for you.
profile picture

crk31174

#11
In live trading, will MF set to 2.01 cause rmargin trades? Is there any other alternative to ensure cash trades only and optimal fully invested system? Do you think writing a custom PosSizer is a solution?

Also, noticed that on changing the number of positions to 2 in lieu of 3, increasing Margin Factor to 2 or even 10 doesn't work
profile picture

Eugene

#12
QUOTE:
In live trading, will MF set to 2.01 cause rmargin trades?

In live trading, you'd rather use Raw Profit. Please find more insight in the User Guide: Reference > Data Panel > Position Size Control.

QUOTE:
Also, noticed that on changing the number of positions to 2 in lieu of 3, increasing Margin Factor to 2 or even 10 doesn't work

If that means there's no effect on the trades not taken after reducing the number of allowed open trades to 2 and leaving the 15-25% position size, then it's expected. Like I said, the effect of reduced exposure is taking place. Your system's exposure % can be seen on the Performance tab.

Re: vague "doesn't work" - recommended reading: How to Report Bugs Effectively > "It doesn't work". ;)

QUOTE:
Do you think writing a custom PosSizer is a solution?

Let's say that we've developed two workarounds for this peculiarity (in Position Options, "skipped trade solution" and "use all what's left") and neither of them is the silver bullet.
profile picture

crk31174

#13
Sorry, I should have been more explicit. By saying "doesn't work", I meant it resulted in the original problem of reduced exposure, as you alluded to.

Basically, I would like to invest the remaining cash after allocation into a cash proxy ETF.
For example:
if the number of positions parameter is set to 2 and if only 1 is selected, then 50% goes into the selected position and the other 50% goes into cash proxy ETF.
If the number of positions parameter is set to 3 and if 2 are selected, then 33% goes into each of the selected position(i.e total 66% for 2 positions) and remaining 33% goes into cash proxy ETF


Can Position Options, help me with this? Earlier, with Priority Position sizer, i was planning to simply set the priority for cash etf for system to allocate remaining funds.

Thanks,

profile picture

Eugene

#14
Position Options supports an ability to set % equity for a Position programmatically:

QUOTE:
The "Use .Tag" button, when enabled, allows to define the Percent-Equity or Max % Risk input programmatically i.e. in your Strategy: for instance, according to some technical or fundamental event. The combo box switches the position sizing from percent equity to max % risk. You have two options for passing the percent as a double value to the PosSizer:

Either in the LastPosition.Tag property
Or, if your Strategy employs .Tag for its own purposes, as the parameter of the SetShareSize method. For this to work, together with Use .Tag you should click on the Use SetShareSize button on the left.
profile picture

crk31174

#15
Thanks, my friend. Perhaps, Use.Tag is the solution. Will try it out and let you know.

Can I get around the limitation of "Skipped trade position", with use of "AtClose" orders if I try to allocating 100% of equity using the Use .Tag feature?



profile picture

Eugene

#16
No.
profile picture

crk31174

#17
If Raw Profit mode which is recommended for live trading is using Fixed Size, then I feel all efforts to achieve dynamic allocation is not quite useful, unless we develop a Custom PosSizer that can be used consistently in both backtesting and realtime environments.

Any thoughts?
profile picture

crk31174

#18
I stumbled upon this Position Tracking code from Cone that appears to enable granular, dynamic allocation of funds. This maybe the solution to my problem. Will try and see how it goes.

Portfolio Equity Tracker

Thanks,
profile picture

cal777

#19
Thank you for sharing this AAA strategy code. I am trying to test the code on a set of ETFs using raw profit mode and got lots of identical buy orders on the same bar. I could not figure out why, please help me. Thank you in advance!
profile picture

Eugene

#20
QUOTE:
lots of identical buy orders on the same bar

This FAQ should explain what went wrong: A Rotation strategy isn't working like it should. Scroll down to "Rotation strategies".
profile picture

cal777

#21
Yes it does, thank you Eugene!
profile picture

rmpwealth

#22
Hi, crk31174 and cal777,

I have been observing the TrendX strategy live on their website for several months. TrendX does not publish any long term historical or simulated results for the strategy, and I have been wishing for said results in order to better evaluate the strategy.

Lo and behold, I stumbled upon this thread! If you have successfully backtested the TrendX strategy (or even a good approximation), what is your opinion? Does the strategy backtest well?
profile picture

Kagei

#23
With a typical weekly basis rotation strategy, I would like to signal the closing price on Friday and execute at the opening price on Monday.
Also, I would like to have an alert, but what should I fix in this code?


CODE:
Please log in to see this code.
profile picture

Eugene

#24
QUOTE:
With a typical weekly basis rotation strategy, I would like to signal the closing price on Friday and execute at the opening price on Monday.
Also, I would like to have an alert, but what should I fix in this code?

As suggests the Wiki FAQ (Alerts are not triggered):

Are your strategy using AtClose orders? These are not going to produce an alert. Check out the WealthScript Programming Guide: Programming Trading Strategies > Alerts > How to: Alert for AtClose Signals.

As a simple alternative, tweak the code to trigger at next open:

CODE:
Please log in to see this code.
profile picture

Kagei

#25
Thank you. It worked well on a weekly basis,

>Are your strategy using AtClose orders?
No. I use AtMarket orders.

profile picture

Eugene

#26
QUOTE:
>Are your strategy using AtClose orders?
No. I use AtMarket orders.

But your code in post #23 did use AtClose orders. Anyway I believe you've changed that now.
profile picture

Kagei

#27
I tried a quarterly AAA using code in post #23 in the default index folder, is this a realistic trade?
In other words, is it possible to trade according to the backtest?

The strategy parameters are
CODE:
Please log in to see this code.
profile picture

Eugene

#28
On the surface, I don't see any blunt peeking into the future here.

It would be off topic to discuss it in this thread but I'll mention that not all symbols in the Indexes DataSet are tradable e.g. ^VIX. Many indices not necessarily trade in Dollars e.g. ^GDAXI. So it may be a comparison of apples to oranges.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).