Handle price discontinuity on volatility models (#7058)
Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled

* Apply splits and dividends to volatility models

* Apply splits and dividends to volatility models using history requests

* Add new ScaleRaw data normalization mode

Handling the new mode in the price scale enumerator.

* DataNormalizationMode.ScaledRaw history requests

* Minor changes

* Minor changes

* Disable new normalization mode in AddSecurity methods and other minor changes

* Peer review

* Minor changes

* Peer review

* Minor changes

* Peer review

* Peer review

* Peer review

* Add scaled raw history regression algorithm

* Add more regression algorithms

* Add more regression algorithms

* Add Slice.TryGet unit tests

* Peer review

* Peer review

* Peer review

* Peer review

* Peer review

* Update algorithms stats

* Peer review

* Peer review
This commit is contained in:
Jhonathan Abreu
2023-03-13 12:11:30 -04:00
committed by GitHub
parent c6322956d9
commit fbf8ffd924
39 changed files with 1485 additions and 149 deletions
@@ -23,7 +23,7 @@ using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Example of custom volatility model
/// Example of custom volatility model
/// </summary>
/// <meta name="tag" content="using quantconnect" />
/// <meta name="tag" content="indicators" />
@@ -56,8 +56,8 @@ namespace QuantConnect.Algorithm.CSharp
private bool _needsUpdate = false;
private TimeSpan _periodSpan = TimeSpan.FromDays(1);
private RollingWindow<decimal> _window;
// Volatility is a mandatory fleid
// Volatility is a mandatory field
public decimal Volatility { get; set; } = 0m;
public CustomVolatilityModel(int periods)
{
@@ -91,17 +91,17 @@ namespace QuantConnect.Algorithm.CSharp
{
_needsUpdate = false;
var mean = _window.Average();
var std = Math.Sqrt((double)_window.Sum(x => (x - mean)*(x - mean)) / _window.Count());
Volatility = Convert.ToDecimal(std * Math.Sqrt(252d));
var std = Math.Sqrt((double)_window.Sum(x => (x - mean)*(x - mean)) / _window.Count());
Volatility = (std * Math.Sqrt(252d)).SafeDecimalCast();
}
}
// Returns history requirements for the volatility model expressed in the form of history request
// GetHistoryRequirements is a mandatory method
public IEnumerable<HistoryRequest> GetHistoryRequirements(Security security, DateTime utcTime)
// For simplicity's sake, we will not set a history requirement
// For simplicity's sake, we will not set a history requirement
{
return Enumerable.Empty<HistoryRequest>();
}
}
}
}