Hello can someone please show me in C# how to make a basic put shorting algorithim?
Hello can someone please show me in C# how to make a basic put shorting algorithim?
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.
namespace QuantConnect.Algorithm.CSharp
{
public class VerticalResistanceThrustAssembly : QCAlgorithm
{
private Symbol spySymbol;
public override void Initialize()
{
SetStartDate(2016, 12, 7); //Set Start Date
SetEndDate(2017,1,21);
SetCash(1000000); //Set Strategy Cash
var spy = AddEquity("SPY", Resolution.Minute);
var symbols = new [] {QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)};
SetUniverseSelection(new ManualUniverseSelectionModel(symbols));
spy.SetDataNormalizationMode(DataNormalizationMode.Raw);
spySymbol = spy.Symbol;
var option = AddOption("SPY");
option.SetFilter(-5, 5, TimeSpan.Zero, TimeSpan.FromDays(10));
SetBenchmark(spy.Symbol);
}
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// Slice object keyed by symbol containing the stock data
public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
OptionChain chain;
if (data.OptionChains.TryGetValue("SPY", out chain))
{
// find the second call strike under market price expiring today
var contract = (
from optionContract in chain.OrderByDescending(x => x.Strike)
where optionContract.Right == OptionRight.Put
where optionContract.Strike < chain.Underlying.Price
select optionContract
).FirstOrDefault();
if (contract != null)
{
SetHoldings(contract.Symbol, -1);
}
}
}
}
}
}
I tried programming it but nothing happens, here is my code.
This discussion is old, but you could take a look here
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!