mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-19 19:18:05 +00:00
style: format code with dotnet-format
This commit fixes the style issues introduced in ed45c9e according to the output
from dotnet-format.
Details: None
This commit is contained in:
@@ -3,45 +3,44 @@ using System;
|
||||
public readonly record struct TValue(DateTime Time, double Value, bool IsNew = true, bool IsHot = true)
|
||||
{
|
||||
public DateTime Time { get; init; } = Time;
|
||||
public double Value { get; init; } = Value;
|
||||
public bool IsNew { get; init; } = IsNew;
|
||||
public bool IsHot { get; init; } = IsHot;
|
||||
public double Value { get; init; } = Value;
|
||||
public bool IsNew { get; init; } = IsNew;
|
||||
public bool IsHot { get; init; } = IsHot;
|
||||
|
||||
public TValue() : this(DateTime.UtcNow, 0) { }
|
||||
public TValue(double value) : this(DateTime.UtcNow, value) { }
|
||||
public TValue((DateTime time, double value) tuple) : this(tuple.time, tuple.value) { }
|
||||
public TValue() : this(DateTime.UtcNow, 0) { }
|
||||
public TValue(double value) : this(DateTime.UtcNow, value) { }
|
||||
public TValue((DateTime time, double value) tuple) : this(tuple.time, tuple.value) { }
|
||||
|
||||
public static implicit operator double(TValue tv) => tv.Value;
|
||||
public static implicit operator DateTime(TValue tv) => tv.Time;
|
||||
public static implicit operator TValue(double value) => new TValue(DateTime.UtcNow, value);
|
||||
public static implicit operator double(TValue tv) => tv.Value;
|
||||
public static implicit operator DateTime(TValue tv) => tv.Time;
|
||||
public static implicit operator TValue(double value) => new TValue(DateTime.UtcNow, value);
|
||||
|
||||
public override string ToString() => $"[{Time:yyyy-MM-dd HH:mm:ss}: {Value:F2}]";
|
||||
public override string ToString() => $"[{Time:yyyy-MM-dd HH:mm:ss}: {Value:F2}]";
|
||||
}
|
||||
|
||||
|
||||
public readonly record struct TBar(DateTime Time, double Open, double High, double Low, double Close, double Volume, bool IsNew = true)
|
||||
{
|
||||
public DateTime Time { get; init; } = Time;
|
||||
public double Open { get; init; } = Open;
|
||||
public double High { get; init; } = High;
|
||||
public double Low { get; init; } = Low;
|
||||
public double Close { get; init; } = Close;
|
||||
public double Volume { get; init; } = Volume;
|
||||
public bool IsNew { get; init; } = IsNew;
|
||||
public double Open { get; init; } = Open;
|
||||
public double High { get; init; } = High;
|
||||
public double Low { get; init; } = Low;
|
||||
public double Close { get; init; } = Close;
|
||||
public double Volume { get; init; } = Volume;
|
||||
public bool IsNew { get; init; } = IsNew;
|
||||
|
||||
public TBar() : this(DateTime.UtcNow, 0, 0, 0, 0, 0) { }
|
||||
public TBar(double open, double high, double low, double close, double volume) : this(DateTime.UtcNow, open, high, low, close, volume) { }
|
||||
public TBar((DateTime time, double open, double high, double low, double close, double volume) tuple) : this(tuple.time, tuple.open, tuple.high, tuple.low, tuple.close, tuple.volume) { }
|
||||
public TBar() : this(DateTime.UtcNow, 0, 0, 0, 0, 0) { }
|
||||
public TBar(double open, double high, double low, double close, double volume) : this(DateTime.UtcNow, open, high, low, close, volume) { }
|
||||
public TBar((DateTime time, double open, double high, double low, double close, double volume) tuple) : this(tuple.time, tuple.open, tuple.high, tuple.low, tuple.close, tuple.volume) { }
|
||||
|
||||
public override string ToString() => $"[{Time:yyyy-MM-dd HH:mm:ss}: O={Open:F2}, H={High:F2}, L={Low:F2}, C={Close:F2}, V={Volume:F2}]";
|
||||
public override string ToString() => $"[{Time:yyyy-MM-dd HH:mm:ss}: O={Open:F2}, H={High:F2}, L={Low:F2}, C={Close:F2}, V={Volume:F2}]";
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
///
|
||||
/////////////////////
|
||||
|
||||
public class GBM_Feed
|
||||
{
|
||||
public class GBM_Feed {
|
||||
private readonly double _mu;
|
||||
private readonly double _sigma;
|
||||
private readonly Random _random;
|
||||
@@ -49,8 +48,7 @@ public class GBM_Feed
|
||||
private double _lastHigh;
|
||||
private double _lastLow;
|
||||
|
||||
public GBM_Feed(double initialPrice, double mu, double sigma)
|
||||
{
|
||||
public GBM_Feed(double initialPrice, double mu, double sigma) {
|
||||
_lastClose = initialPrice;
|
||||
_lastHigh = initialPrice;
|
||||
_lastLow = initialPrice;
|
||||
@@ -59,8 +57,7 @@ public class GBM_Feed
|
||||
_random = Random.Shared;
|
||||
}
|
||||
|
||||
public TBar Generate(bool IsNew = true)
|
||||
{
|
||||
public TBar Generate(bool IsNew = true) {
|
||||
DateTime time = DateTime.UtcNow;
|
||||
double dt = 1.0 / 252; // Assuming daily steps in a trading year of 252 days
|
||||
double drift = (_mu - 0.5 * _sigma * _sigma) * dt;
|
||||
@@ -72,13 +69,10 @@ public class GBM_Feed
|
||||
double low = Math.Min(open, newClose) * (1 - _random.NextDouble() * 0.01);
|
||||
double volume = 1000 + _random.NextDouble() * 1000; // Random volume between 1000 and 2000
|
||||
|
||||
if (!IsNew)
|
||||
{
|
||||
if (!IsNew) {
|
||||
high = Math.Max(_lastHigh, high);
|
||||
low = Math.Min(_lastLow, low);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_lastClose = newClose;
|
||||
}
|
||||
|
||||
@@ -88,8 +82,7 @@ public class GBM_Feed
|
||||
return new TBar(time, open, high, low, newClose, volume, IsNew);
|
||||
}
|
||||
|
||||
private double NormalRandom()
|
||||
{
|
||||
private double NormalRandom() {
|
||||
// Box-Muller transform to generate standard normal random variable
|
||||
double u1 = 1.0 - _random.NextDouble(); // Uniform(0,1] random doubles
|
||||
double u2 = 1.0 - _random.NextDouble();
|
||||
@@ -102,8 +95,7 @@ public class GBM_Feed
|
||||
/// ////////////////
|
||||
/// </summary>
|
||||
|
||||
public class EMA
|
||||
{
|
||||
public class EMA {
|
||||
private double lastEma, lastEmaCandidate, k;
|
||||
private int period, i;
|
||||
public TValue Value { get; private set; }
|
||||
@@ -113,8 +105,7 @@ public class EMA
|
||||
Init(period);
|
||||
}
|
||||
|
||||
public void Init(int period)
|
||||
{
|
||||
public void Init(int period) {
|
||||
this.period = period;
|
||||
this.k = 2.0 / (period + 1);
|
||||
this.lastEma = this.lastEmaCandidate = double.NaN;
|
||||
@@ -130,7 +121,7 @@ public class EMA
|
||||
i++;
|
||||
}
|
||||
|
||||
double kk = (i<period)?(2.0/(i+1)):k;
|
||||
double kk = (i < period) ? (2.0 / (i + 1)) : k;
|
||||
ema = lastEma + kk * (input.Value - lastEma);
|
||||
lastEmaCandidate = ema;
|
||||
|
||||
@@ -143,21 +134,18 @@ public class EMA
|
||||
/////////////////
|
||||
///
|
||||
|
||||
public class SMA
|
||||
{
|
||||
public class SMA {
|
||||
private CircularBuffer<double> buffer;
|
||||
private int period;
|
||||
private double sum;
|
||||
public TValue Value { get; private set; }
|
||||
public bool IsHot { get; private set; }
|
||||
|
||||
public SMA(int period)
|
||||
{
|
||||
public SMA(int period) {
|
||||
Init(period);
|
||||
}
|
||||
|
||||
public void Init(int period)
|
||||
{
|
||||
public void Init(int period) {
|
||||
this.period = period;
|
||||
this.buffer = new CircularBuffer<double>(period);
|
||||
this.sum = 0;
|
||||
@@ -165,10 +153,8 @@ public class SMA
|
||||
this.Value = default;
|
||||
}
|
||||
|
||||
public TValue Update(TValue input, bool IsNew = true)
|
||||
{
|
||||
if (IsNew)
|
||||
{
|
||||
public TValue Update(TValue input, bool IsNew = true) {
|
||||
if (IsNew) {
|
||||
if (buffer.Count == period) {
|
||||
sum -= buffer[0];
|
||||
}
|
||||
@@ -197,8 +183,7 @@ public class SMA
|
||||
/////////////////////
|
||||
|
||||
|
||||
public class CircularBuffer<double>
|
||||
{
|
||||
public class CircularBuffer<double> {
|
||||
private double[] _buffer;
|
||||
private int _start;
|
||||
private int _size;
|
||||
|
||||
Reference in New Issue
Block a user