Back

SetHoldings question

Hi All,

Lets say we start with $100,000
We go short MSFT 50% of the money (sold shares worth $50,000)
Next week MSFT loses let's say 10%, then Portfolio will have $105,000, and the cash is $50,000, but 50% in this case is $52,500.

Then we execute Setholdings("MSFT", 0.5).
Does this lead to buying back all the shares we were short and on top of this buying some MSFT shares for remaining $2500 in order to reach trading for $52,000 ?

Thanks
Nik
Update Backtest






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.



That is what it should do yes :) But it looks like its not perfect with short-gain scenario.

We figure out the difference in margin required, and then if its negative make it a short. We also made a key change recently to change it from "Buying Power" to Cash (where 1.0 = Starting Cash, 2.0 = 2xLeveraged Cash). That change greatly simplified the math involved, and hopefully makes it more predictable!

I'll write some tests tonight to future proof it and push a new version ASAP: GitHub
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.


For your interest we spent a full 24 hours on this and wrote lots of tests for various conditions. You can see the new implementation and tests on github. Essentially we came to conclusion shorts works a little differently to how you might expect intuitively and the only real way to model it is with debt:

Using the example you provided above; pushed a little higher for bigger numbers: you hold $50,000 @ $25/share MSFT. When you short we pay you the cash, and the short is treated as debt.

MSFT drops 50% to $12.5/share making you $25,000 on the position. Your new portfolio is $125k. The short position is now only -$25k of debt + the original +$50k cash. The short has reduced as a total fraction of your portfolio.

You call set holdings again; aiming for 50% debt / margin used in MSFT. This means 50% of 125k = $62.5k total holdings. We currently only have -$25k so the difference is $37.5k @ 12.5/share = -3000 more shares.
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.


Just to clarify regarding behavior of SetHoldings: When I say SetHoldings("AAPL", .7), this allocates 70% of available cash, not 70% of portfolio value, correct? So in order to rebalance to a fixed percent, I would need to for example

Liquidate(symbolA);
Liquidate(symbolB);
SetHoldings(symbolA, .50);
SetHoldings(symbolB, .50);


As I understand it, this is the simplest way to model rebalancing would be to use the above, although I realize it adds extra transactions. For actual implenetation I would want to use a Rebalance method that would only add/subtract the appropriate number of shares.

Am I understanding the SetHoldings method correctly?
0

Hey @Reuben,

SetHoldings aims to set your holdings as a percentage of your total portfolio value. So if you currently hold 25% of your portfolio in AAPL and call SetHoldings(AAPL, 0.50), then the algorithm will attempt to purchase an extra 25% worth (the delta) to achieve the 50% target. The amount of cash your algorithm holds plays into the TotalPortfolioValue, but is not directly used in calculating the order quantity required to achieve the desired target percentage.

The one thing the algorithm won't do, is reduce existing holdings to make room for new holdings.

For those who are more implementation centric, here's the code from github.

For a view of the cases we've written tests for, have a peak at the test file in github.

One final note, SetHoldings takes an optional flag that will liquidate your existing positions first.
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.


Thank you guys for the quick turn around!
What I was not sure was cleared in Jared's example and MichaelH explanation.
"SetHoldings aims to set your holdings as a percentage of your total portfolio value."
0

The one thing the algorithm won't do, is reduce existing holdings to make room for new holdings.

Michael, to expound on this: if you set liquidateexistingholdings = false (which it is by default), what will it do if you ask it to set AAPL to 20% holdings, but you only have 10% of your account in cash? Will it ditch the order altogether or will it attempt to buy as much as possible with whatever is left?

Note, I'm not asking for functionality to be altered either way to accomplish this; I'm just trying to understand SetHolding's default behavior :-)
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