Back

How to implement a simple execution module

Here is what I am trying to do.

I create an insight

  • Symbol: IEF, Direction: Up, Duration: 100000 days, Magnitude: 1.

This means I want to hold 100% of IEF. In the portfolio, I overrid the function DetermineTargetPercent().

  • The percentage returned is 100% for IEF. I then use ImmediateExecutionModel().

The result of orders I get are:

  • IEF, Buy Market on Open, ......, Quantity: 1906, Filled
  • IEF, Buy Market on Open, ......, Quantity: 15, Filled

Question:

My question is that I have 1 insight, but there are 2 orders executed. Why is it? and how to reduce it?

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

After the first insight, here comes my second insight

  • Symbol: IEF, Direction: Flat, Duration: 100000 days, Magnitude: 0.5.

This means I want to hold 50% of IEF. From the portfolio, function DetermineTargetPercent().

  • I assign 50% for IEF

The result of orders I get are:

  • IEF, Sell Market on Open, ......, Quantity: -1921, Filled
  • IEF, Buy Market, ......, Quantity: 962, Filled

Question:

Again there are 2 orders.

-------------------------------------------------------------------------------------------------------------For the rest of the backtest, there are many orders like this:

  • 2003-05-14 14:00, IEF, Sell Market, ......, Quantity: -1, Filled
  • 2003-05-14 16:00, IEF, Sell Market, ......, Quantity: -1, Filled
  • ......

Seems that the portfolio and execution module will be called when data is updated. I have data updated in every hour. 

Question:

If I want to call portfolio and execution for the rebalance process only when I have insights updated, what can I do? Thank you very much.

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Sulfred,

Please attach a backtest, this will help us identify the problem.

Best,
Shile Wen

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Shile,

Thank you for your reply, I am trying to create a shorter example to repeat my problem so that it is easier for others to read. I will update as soon as possible.

Thanks,

0

Hi Shile,

I attached an example backtest. For the second orders, an insight is emitted. What I want to do is that the percentage of GOOG reduced to 50% from 100%. The action now become sell all stock frist and then buy 50% again.

Thanks,

0


Hi Sulfred,

Instead of using DetermineTargetPercent, we need to set the percentages in the CreateTargets method instead.I've shown how to do this in the attached backtest.

Best,
Shile Wen

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Shile,

Thank you very much. I would like to have a follow up question. When should I use DetermineTargetPercent ?

Thanks,

Sulfred

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed