Files

45 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-10-12 20:36:37 -07:00
using System.Drawing;
2024-10-04 21:31:25 -07:00
using TradingPlatform.BusinessLayer;
2024-10-12 20:36:37 -07:00
2024-10-04 21:31:25 -07:00
namespace QuanTAlib;
2024-10-12 20:36:37 -07:00
public class RealizedIndicator : Indicator, IWatchlistIndicator
2024-10-04 21:31:25 -07:00
{
2024-10-12 20:36:37 -07:00
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
public int Periods { get; set; } = 20;
2024-10-04 21:31:25 -07:00
[InputParameter("Annualized", sortIndex: 2)]
public bool IsAnnualized { get; set; } = true;
2024-10-26 23:54:55 -07:00
private Rv? realized;
2024-10-12 20:36:37 -07:00
protected LineSeries? RvSeries;
public int MinHistoryDepths => Periods;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
2024-10-04 21:31:25 -07:00
2024-10-12 20:36:37 -07:00
public RealizedIndicator()
2024-10-04 21:31:25 -07:00
{
Name = "RV - Realized Volatility";
2024-10-11 18:02:09 -07:00
Description = "Measures actual price volatility over a specific period, useful for risk assessment and forecasting.";
2024-10-04 21:31:25 -07:00
SeparateWindow = true;
2024-10-12 20:36:37 -07:00
2024-11-06 20:56:32 -08:00
RvSeries = new("RV", color: IndicatorExtensions.Volatility, 2, LineStyle.Solid);
2024-10-12 20:36:37 -07:00
AddLineSeries(RvSeries);
2024-10-04 21:31:25 -07:00
}
2024-10-12 20:36:37 -07:00
protected override void OnInit()
2024-10-04 21:31:25 -07:00
{
2024-10-26 23:54:55 -07:00
realized = new(Periods, IsAnnualized);
2024-10-12 20:36:37 -07:00
base.OnInit();
2024-10-04 21:31:25 -07:00
}
2024-10-12 20:36:37 -07:00
protected override void OnUpdate(UpdateArgs args)
{
TBar input = IndicatorExtensions.GetInputBar(this, args);
TValue result = realized!.Calc(input);
RvSeries!.SetValue(result.Value);
}
public override string ShortName => $"RV ({Periods}{(IsAnnualized ? " - Annualized" : "")})";
2024-10-11 18:02:09 -07:00
}