Hi,
I'm wondering if it's possible to be able to buy and sell multiple lots of the same security with each lot having it's own strategy.
For example if I had a strategy that buys x amount of shares (lot 1) at a target price "a" and another strategy that buys y amount of shares (lot 2) at target price "b".
Then say that each lot has its own trailing stop set based on that lots respective purchase price.
My sell rules would have to be tied to their respective lot or their respective buy rules. For example I don't want to sell lot 2's shares if lot 1's sell rules are fulfilled. Each lot's specific sell rules would only be active when I'm holding a lot based on a it's respective buy strategy. So basically I would need sell rules that are tied to the specific lot that was bought.
Both strategies would need to be in one algorithm and for the same security. Is there a simple way to do this?
(I'm writing in python and fairly new to it)
Luke Algo
Anyone have any ideas on how I could try to solve this problem? Is there any way to pull all previous buy order data such as buy price and quantity. I know I can get the average price of what I'm holding in a single security, but that won't work to help me keep track of the seperate lots. I would really like to try to make this work. Thanks
Shile Wen
Hi Luke,
One idea would be to have multiple dicts, one for each strategy, with share count or a SymbolData class that wraps all the information you'd want, keyed by Symbol. Then when buying and selling shares for a specific strategy, all you'd need to do is update the dict as well as buy/sell the appropriate amount of shares.
However, please note that the portfolio positions may cancel out, so if one strategy goes long 100 shares and other strategy goes short 100 shares, they will cancel out and you won't have any open positions on SPY.
Best,
Shile Wen
Luke Algo
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!