mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 03:28:05 +00:00
normalization of methods
This commit is contained in:
@@ -187,7 +187,7 @@ public class ExptransTests
|
||||
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 40000);
|
||||
var bars = gbm.Fetch(count, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
// Use log of close prices to stay in reasonable exp range
|
||||
var logSource = Logtrans.Calculate(bars.Close);
|
||||
var logSource = Logtrans.Batch(bars.Close);
|
||||
|
||||
// Streaming
|
||||
var streaming = new Exptrans();
|
||||
@@ -199,7 +199,7 @@ public class ExptransTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batch = Exptrans.Calculate(logSource);
|
||||
var batch = Exptrans.Batch(logSource);
|
||||
|
||||
// Compare all values
|
||||
for (int i = 0; i < logSource.Count; i++)
|
||||
@@ -214,15 +214,15 @@ public class ExptransTests
|
||||
int count = 50;
|
||||
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 40001);
|
||||
var bars = gbm.Fetch(count, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var logSource = Logtrans.Calculate(bars.Close);
|
||||
var logSource = Logtrans.Batch(bars.Close);
|
||||
|
||||
// TSeries batch
|
||||
var batchResult = Exptrans.Calculate(logSource);
|
||||
var batchResult = Exptrans.Batch(logSource);
|
||||
|
||||
// Span calculation
|
||||
var values = logSource.Values.ToArray();
|
||||
var output = new double[count];
|
||||
Exptrans.Calculate(values, output);
|
||||
Exptrans.Batch(values, output);
|
||||
|
||||
for (int i = 0; i < logSource.Count; i++)
|
||||
{
|
||||
@@ -236,14 +236,14 @@ public class ExptransTests
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
Span<double> output = stackalloc double[10];
|
||||
Exptrans.Calculate(ReadOnlySpan<double>.Empty, output);
|
||||
Exptrans.Batch(ReadOnlySpan<double>.Empty, output);
|
||||
});
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
ReadOnlySpan<double> source = stackalloc double[10];
|
||||
Span<double> output = stackalloc double[5];
|
||||
Exptrans.Calculate(source, output);
|
||||
Exptrans.Batch(source, output);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ public class ExptransValidationTests
|
||||
// Use log-transformed prices to keep exp in reasonable range
|
||||
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 50000);
|
||||
var bars = gbm.Fetch(count, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var logSource = Logtrans.Calculate(bars.Close);
|
||||
var logSource = Logtrans.Batch(bars.Close);
|
||||
|
||||
var result = Exptrans.Calculate(logSource);
|
||||
var result = Exptrans.Batch(logSource);
|
||||
|
||||
for (int i = 0; i < logSource.Count; i++)
|
||||
{
|
||||
@@ -33,7 +33,7 @@ public class ExptransValidationTests
|
||||
int count = 100;
|
||||
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 50001);
|
||||
var bars = gbm.Fetch(count, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var logSource = Logtrans.Calculate(bars.Close);
|
||||
var logSource = Logtrans.Batch(bars.Close);
|
||||
|
||||
var indicator = new Exptrans();
|
||||
|
||||
@@ -51,11 +51,11 @@ public class ExptransValidationTests
|
||||
int count = 100;
|
||||
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 50002);
|
||||
var bars = gbm.Fetch(count, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var logSource = Logtrans.Calculate(bars.Close);
|
||||
var logSource = Logtrans.Batch(bars.Close);
|
||||
|
||||
var values = logSource.Values.ToArray();
|
||||
var output = new double[count];
|
||||
Exptrans.Calculate(values, output);
|
||||
Exptrans.Batch(values, output);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
@@ -94,8 +94,8 @@ public class ExptransValidationTests
|
||||
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var source = bars.Close;
|
||||
|
||||
var logResult = Logtrans.Calculate(source);
|
||||
var expResult = Exptrans.Calculate(logResult);
|
||||
var logResult = Logtrans.Batch(source);
|
||||
var expResult = Exptrans.Batch(logResult);
|
||||
|
||||
for (int i = 0; i < source.Count; i++)
|
||||
{
|
||||
|
||||
@@ -106,7 +106,7 @@ public sealed class Exptrans : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static TSeries Calculate(TSeries source)
|
||||
public static TSeries Batch(TSeries source)
|
||||
{
|
||||
var indicator = new Exptrans();
|
||||
return indicator.Update(source);
|
||||
@@ -115,7 +115,7 @@ public sealed class Exptrans : AbstractBase
|
||||
/// <summary>
|
||||
/// Calculates exponential over a span of values.
|
||||
/// </summary>
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> output)
|
||||
public static void Batch(ReadOnlySpan<double> source, Span<double> output)
|
||||
{
|
||||
if (source.Length == 0)
|
||||
{
|
||||
@@ -152,10 +152,17 @@ public sealed class Exptrans : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Exptrans Indicator) Calculate(TSeries source)
|
||||
{
|
||||
var indicator = new Exptrans();
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_state = new(1.0);
|
||||
_p_state = new(1.0);
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user