-
-
Notifications
You must be signed in to change notification settings - Fork 5k
feature: Implements SFX #8801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
feature: Implements SFX #8801
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ec642d
initial_commit
SaiRevanth25 504ea05
Update QuantConnect.Tests.csproj
SaiRevanth25 2c14fc2
data_file_name
SaiRevanth25 fa0dde7
talipp data
SaiRevanth25 9b6882d
sfx column
SaiRevanth25 417b31c
changes
SaiRevanth25 f40c4a9
test_file
SaiRevanth25 9b0b1b2
delta_value
SaiRevanth25 5dfd2a0
test changes
SaiRevanth25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
| * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| using System; | ||
| using QuantConnect.Data.Market; | ||
|
|
||
| namespace QuantConnect.Indicators | ||
| { | ||
| /// <summary> | ||
| /// The Smoothed Force Index (SFX) is a composite volatility indicator. | ||
| /// It combines the Average True Range (ATR), Standard Deviation of close prices, | ||
| /// and a moving average of the Standard Deviation to provide a smoother volatility measure. | ||
| /// SFX is designed to filter out noise and help detect changes in volatility regimes. | ||
| /// </summary> | ||
| public class SmoothedForceIndex : TradeBarIndicator, IIndicatorWarmUpPeriodProvider | ||
| { | ||
| ///<summary> | ||
| /// Gets the average true range | ||
| /// </summary> | ||
| public AverageTrueRange AverageTrueRange { get; } | ||
|
|
||
| ///<summary> | ||
| /// Gets the standard deviation | ||
| /// </summary> | ||
| public StandardDeviation StandardDeviation { get; } | ||
|
|
||
| ///<summary> | ||
| /// Gets the moving average standard deviation | ||
| /// </summary> | ||
| public IndicatorBase<IndicatorDataPoint> MovingAverageStandardDeviation { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a flag indicating when this indicator is ready and fully initialized | ||
| /// </summary> | ||
| public override bool IsReady => AverageTrueRange.IsReady && StandardDeviation.IsReady && MovingAverageStandardDeviation.IsReady; | ||
|
|
||
| /// <summary> | ||
| /// Required period, in data points, for the indicator to be ready and fully initialized. | ||
| /// </summary> | ||
| public int WarmUpPeriod { get; } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new Smoothed Force Index (SFX) indicator. | ||
| /// </summary> | ||
| /// <param name="name">The name of this indicator</param> | ||
| /// <param name="atrPeriod">The period used to calculate the Average True Range (ATR)</param> | ||
| /// <param name="stdDevPeriod">The period used to calculate the Standard Deviation of close prices</param> | ||
| /// <param name="stdDevSmoothingPeriod">The period used to smooth the Standard Deviation with a moving average</param> | ||
| /// <param name="maType">The type of moving average used to smooth the Standard Deviation</param> | ||
| public SmoothedForceIndex(string name, int atrPeriod, int stdDevPeriod, int stdDevSmoothingPeriod, MovingAverageType maType = MovingAverageType.Simple) | ||
| : base(name) | ||
| { | ||
| AverageTrueRange = new AverageTrueRange(atrPeriod, MovingAverageType.Wilders); | ||
| StandardDeviation = new StandardDeviation(stdDevPeriod); | ||
| MovingAverageStandardDeviation = maType.AsIndicator($"{name}_{maType}", stdDevSmoothingPeriod).Of(StandardDeviation, waitForFirstToReady: false); | ||
|
|
||
| WarmUpPeriod = Math.Max(AverageTrueRange.WarmUpPeriod, Math.Max(StandardDeviation.WarmUpPeriod, stdDevSmoothingPeriod)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new Smoothed Force Index (SFX) indicator with a default name. | ||
| /// </summary> | ||
| /// <param name="atrPeriod">The period used to calculate the Average True Range (ATR)</param> | ||
| /// <param name="stdDevPeriod">The period used to calculate the Standard Deviation of close prices</param> | ||
| /// <param name="stdDevSmoothingPeriod">The period used to smooth the Standard Deviation with a moving average</param> | ||
| /// <param name="maType">The type of moving average used to smooth the Standard Deviation</param> | ||
| public SmoothedForceIndex(int atrPeriod, int stdDevPeriod, int stdDevSmoothingPeriod, MovingAverageType maType = MovingAverageType.Simple) | ||
| : this($"SFX({atrPeriod},{stdDevPeriod},{stdDevSmoothingPeriod})", atrPeriod, stdDevPeriod, stdDevSmoothingPeriod, maType) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Computes the next value of this indicator from the given trade bar input. | ||
| /// </summary> | ||
| /// <param name="input">The input given to the indicator</param> | ||
| /// <returns>The input is returned unmodified.</returns> | ||
| protected override decimal ComputeNextValue(TradeBar input) | ||
| { | ||
| AverageTrueRange.Update(input); | ||
| StandardDeviation.Update(new IndicatorDataPoint(input.EndTime, input.Close)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor but why not just call |
||
|
|
||
| return input.Value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resets this indicator to its initial state | ||
| /// </summary> | ||
| public override void Reset() | ||
| { | ||
| AverageTrueRange.Reset(); | ||
| StandardDeviation.Reset(); | ||
| MovingAverageStandardDeviation.Reset(); | ||
| base.Reset(); | ||
| } | ||
| } | ||
| } | ||
|
SaiRevanth25 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
| * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| using System; | ||
| using NUnit.Framework; | ||
| using QuantConnect.Data.Market; | ||
| using QuantConnect.Indicators; | ||
|
|
||
| namespace QuantConnect.Tests.Indicators | ||
| { | ||
| [TestFixture] | ||
| public class SmoothedForceIndexTests : CommonIndicatorTests<TradeBar> | ||
|
SaiRevanth25 marked this conversation as resolved.
|
||
| { | ||
| protected override IndicatorBase<TradeBar> CreateIndicator() | ||
| { | ||
| RenkoBarSize = 1m; | ||
| // VolumeRenkoBarSize = 0.5m; // when uncommented test AcceptsVolumeRenkoBarsAsInput in hanging | ||
| return new SmoothedForceIndex(12, 12, 3); | ||
| } | ||
|
|
||
| protected override string TestFileName => "spy_with_SmoothedForceIndex.csv"; | ||
|
|
||
| protected override string TestColumnName => "atr"; | ||
|
|
||
| protected override Action<IndicatorBase<TradeBar>, double> Assertion => | ||
| (indicator, expected) => | ||
| Assert.AreEqual(expected, (double) ((SmoothedForceIndex) indicator).AverageTrueRange.Current.Value, 1e-3); | ||
|
|
||
| [Test] | ||
| public void CompareWithExternalDataAverageTrueRange() | ||
| { | ||
| TestHelper.TestIndicator( | ||
| CreateIndicator() as SmoothedForceIndex, | ||
| TestFileName, | ||
| "atr", | ||
| (ind, expected) => Assert.AreEqual(expected, | ||
| (double)((SmoothedForceIndex)ind).AverageTrueRange.Current.Value, 1e-3) | ||
| ); | ||
| } | ||
|
|
||
| [Test] | ||
| public void CompareWithExternalStandardDeviation() | ||
| { | ||
| TestHelper.TestIndicator( | ||
| CreateIndicator() as SmoothedForceIndex, | ||
| TestFileName, | ||
| "std_dev", | ||
| (ind, expected) => Assert.AreEqual(expected, | ||
| (double)((SmoothedForceIndex)ind).StandardDeviation.Current.Value, 1e-3) | ||
| ); | ||
| } | ||
|
|
||
| [Test] | ||
| public void CompareWithExternalMovingAverageStandardDeviation() | ||
| { | ||
| TestHelper.TestIndicator( | ||
| CreateIndicator() as SmoothedForceIndex, | ||
| TestFileName, | ||
| "ma_std_dev", | ||
| (ind, expected) => Assert.AreEqual(expected, | ||
| (double)((SmoothedForceIndex)ind).MovingAverageStandardDeviation.Current.Value, 1e-3) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Volume isn't required for SFX implementation? the base type should be the more generic BarIndicator instead of TradeBarIndicator
maType-> should be expanded tomovingAverageTypesee other similar arguments in this file2027 empty line should be removed