Dear Quantopians,
I would like you all for a huge favor again. Building my first algorithm here and I've got a lot of coding-related questions.
Below is the link to the strategy that I was trying to code:
https://allocatesmartly.com/protective-asset-allocation/
I use this strategy in my paper trading and it is a simple and conservative strategy with a relatively smooth equity curve and low drawdowns. I tested it multiple times in Excel and saw tests by other people which were consistent with my tests.
In brief, the rules are the following:
- On the last trading day of each month (t), calculate a momentum score
(MOM) for each of 12 global asset classes, where MOMt = [(closet / SMA(t..t-12)) – 1]. Note that
the SMA is calculated based on month-end values, so t..t-12
represents the most recent 13 month-end values, including today. - To determine the % of the portfolio to allocate to the crash
protection asset (CP) at the close, first calculate n where n equals
the number of asset classes where MOM > 0. If n <= 6, then allocate
the entire portfolio to the CP asset, otherwise CP % = [(12 – n) /
6]. More on the CP asset in a moment. - If n >= 7 (or put another way, if CP % < 100%), select the 6 asset
class with the highest MOM value, and allocate 1/6 of the remaining
portfolio to each at the close. - Hold positions until the final trading day of the following month.
Rebalance the entire portfolio monthly, regardless of whether there
is a change in position.
The questions that I have are the following:
1) The results are way different from my previous tests - I was hoping to fix it through answering the questions below, but if you see other flaws, please let me know.
2) I am getting a lot of logs like "2016-04-13 16:00 WARN Your order for 1 shares of EWJ failed to fill by the end of day and was canceled." I am really confused why I am getting those, especially given that my handle_data function is scheduled for the beginning of the month only.
3) My leverage is well above 1, often closer to 2 - not sure why my positions get leveraged.
4) Should I be using the Pipeline API? Still trying to wrap my head around it and understand the while Pipeline concept. If you could point me in the right direction as to how the code should look like with the Pipeline, I would really appreciate.
5) I have introduced 3 functions (compute_weight_risk, and ranking) - all are doing similar things, I just need slightly different outputs. Just wondering if there is a way to optimize the code to do everything at once?
Many thanks in advance for all your help, very much appreciate it!
Alexey