Back

Complete newbie - looking for some help

Hi,

Brand new to this. I'm looking for a few code snippets to get me pointed in the right direction. I went through the boot camp already, but I'm still feeling unclear about how the system works overall.

As a basic setup to get started on my ideas, I'd like to see if something like this is accomplishable:

1: Create a universe of, say, 5 stocks using coarse & fine filtering (any arbitrary filter will work for now)

2: Invest evenly between those stocks

3: Hold on to those stocks until it increases or decreases by a certain amount (say 10% in either direction)

4: Sell that stock and re-invest in a new stock provided by the universe

 

I've looked at some universe samples available here, so I can accomplish items 1 and 2, but I have no idea where to get started with items 3 & 4. Any help would be greatly appreciated!

As a starting point, you can reference the sample provided by Micheal at this link

Thanks in advance!

Update Backtest








Also, in the line below, what does the m represent in 0.25m?

SetHoldings(security.Symbol, 0.25m);
0

This section of Docs contains example called "Weather Based Rebalancing", maybe it is what you need.

SetHoldings(ticker, percents) should define how much percents this asset takes in your portfolio, "m" means this number is decimal and will always be rounded to 2 characters after dot ".", the value itself 0.25 means 25%.

Possible methods to open position - MarketOrder, SetHoldings, Order ... close positions - Liquidate

Possible methods to control everything related to open positions - class Portfolio

SetCash(1000);
SetHoldings("MSFT", 0.25m); // buy shares of MSFT worth o $250, because 0.25m = 25% of $1000

if (Portfolio["MSFT"].TotalUnrealizedProfit < 15m) // lost too much, close position
{
Liquidate("MSFT");
}
1

Thanks, I'll play around with this and look at that sample. Have a good one!

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