I have an indicator that requires tangent, is there any built in tan(x) function in quantconnect?
Thanks
QUANTCONNECT COMMUNITY
I have an indicator that requires tangent, is there any built in tan(x) function in quantconnect?
Thanks
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.
Alexandre Catarino
You can use Math.Tan method from the System.Math class.
For other trigonometric functions, please checkout the Math Class (System).
Additionaly, say we want to use a moving average cross over of the tangents of the closing price, we could implement it like this:
private const string Symbol = "SPY"; private ExponentialMovingAverage fast; private ExponentialMovingAverage slow; public override void Initialize() { /* Setup methods */ AddSecurity(SecurityType.Equity, Symbol, Resolution.Minute); // create a 15 day exponential moving average fast = EMA(Symbol, 15, Resolution.Daily, x => (decimal)Math.Tan((double)x.Price)); // create a 30 day exponential moving average slow = EMA(Symbol, 30, Resolution.Daily, x => (decimal)Math.Tan((double)x.Price)); } public void OnData(TradeBars data) { if (!slow.IsReady) return; const decimal tolerance = 0.00015m; var holdings = Portfolio[Symbol].Quantity; if (holdings <= 0 && fast > slow * (1 + tolerance)) { Log("BUY >> " + Securities[Symbol].Price); SetHoldings(Symbol, 1.0); } if (holdings > 0 && fast < slow) { Log("SELL >> " + Securities[Symbol].Price); Liquidate(Symbol); } }
Jonathan Helander
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!