updates from mac

This commit is contained in:
Miha Kralj
2025-11-28 13:35:16 -08:00
parent 74b49d2bb4
commit acac3e610c
55 changed files with 126278 additions and 126081 deletions
+51 -51
View File
@@ -1,51 +1,51 @@
using System;
using Xunit;
using QuanTAlib;
namespace QuanTAlib.Tests
{
public class TValueTests
{
[Fact]
public void Constructor_SetsPropertiesCorrectly()
{
long time = DateTime.UtcNow.Ticks;
double value = 123.45;
var tValue = new TValue(time, value);
Assert.Equal(time, tValue.Time);
Assert.Equal(value, tValue.Value);
}
[Fact]
public void AsDateTime_ReturnsCorrectDateTime()
{
DateTime dt = new DateTime(2023, 1, 1, 12, 0, 0, DateTimeKind.Utc);
long ticks = dt.Ticks;
var tValue = new TValue(ticks, 100.0);
Assert.Equal(dt, tValue.AsDateTime);
}
[Fact]
public void ToString_FormatsCorrectly()
{
DateTime dt = new DateTime(2023, 1, 1, 12, 0, 0, DateTimeKind.Utc);
var tValue = new TValue(dt.Ticks, 123.456);
string result = tValue.ToString();
Assert.Contains(dt.ToString("yyyy-MM-dd HH:mm:ss"), result);
Assert.Contains("123.46", result); // Default formatting usually 2 decimals or similar
}
[Fact]
public void ImplicitConversion_ToDouble()
{
var tValue = new TValue(DateTime.UtcNow.Ticks, 42.0);
double val = tValue;
Assert.Equal(42.0, val);
}
}
}
using System;
using Xunit;
using QuanTAlib;
namespace QuanTAlib.Tests
{
public class TValueTests
{
[Fact]
public void Constructor_SetsPropertiesCorrectly()
{
long time = DateTime.UtcNow.Ticks;
double value = 123.45;
var tValue = new TValue(time, value);
Assert.Equal(time, tValue.Time);
Assert.Equal(value, tValue.Value);
}
[Fact]
public void AsDateTime_ReturnsCorrectDateTime()
{
DateTime dt = new DateTime(2023, 1, 1, 12, 0, 0, DateTimeKind.Utc);
long ticks = dt.Ticks;
var tValue = new TValue(ticks, 100.0);
Assert.Equal(dt, tValue.AsDateTime);
}
[Fact]
public void ToString_FormatsCorrectly()
{
DateTime dt = new DateTime(2023, 1, 1, 12, 0, 0, DateTimeKind.Utc);
var tValue = new TValue(dt.Ticks, 123.456);
string result = tValue.ToString();
Assert.Contains(dt.ToString("yyyy-MM-dd HH:mm:ss"), result);
Assert.Contains("123.46", result); // Default formatting usually 2 decimals or similar
}
[Fact]
public void ImplicitConversion_ToDouble()
{
var tValue = new TValue(DateTime.UtcNow.Ticks, 42.0);
double val = tValue;
Assert.Equal(42.0, val);
}
}
}
+37 -37
View File
@@ -1,37 +1,37 @@
# TValue: Time-Value Pair
## Overview
`TValue` is the fundamental building block of QuanTAlib. It represents a single data point in a time series, consisting of a timestamp and a double-precision floating-point value.
It is implemented as a lightweight `readonly struct` to ensure immutability and high performance (stack allocation, no GC overhead).
## Structure
```csharp
public readonly struct TValue
{
public readonly long Time; // Ticks (UTC)
public readonly double Value; // Data value
public readonly bool IsNew; // Metadata for streaming (optional usage)
}
```
## Key Features
* **Lightweight**: 24 bytes (long + double + bool + padding).
* **Immutable**: Thread-safe by design.
* **Implicit Conversions**: Can be implicitly converted to `double` (returns Value) and `DateTime` (returns Time).
* **Performance**: Designed for high-frequency trading and large dataset processing.
## Usage
`TValue` is used throughout the library for:
* Input to indicators (`Update(TValue)`).
* Output from indicators (`Value` property).
* Elements in `TSeries`.
## Constructors
* `new TValue(long time, double value, bool isNew = true)`
* `new TValue(DateTime time, double value, bool isNew = true)`
# TValue: Time-Value Pair
## Overview
`TValue` is the fundamental building block of QuanTAlib. It represents a single data point in a time series, consisting of a timestamp and a double-precision floating-point value.
It is implemented as a lightweight `readonly struct` to ensure immutability and high performance (stack allocation, no GC overhead).
## Structure
```csharp
public readonly struct TValue
{
public readonly long Time; // Ticks (UTC)
public readonly double Value; // Data value
public readonly bool IsNew; // Metadata for streaming (optional usage)
}
```
## Key Features
* **Lightweight**: 24 bytes (long + double + bool + padding).
* **Immutable**: Thread-safe by design.
* **Implicit Conversions**: Can be implicitly converted to `double` (returns Value) and `DateTime` (returns Time).
* **Performance**: Designed for high-frequency trading and large dataset processing.
## Usage
`TValue` is used throughout the library for:
* Input to indicators (`Update(TValue)`).
* Output from indicators (`Value` property).
* Elements in `TSeries`.
## Constructors
* `new TValue(long time, double value, bool isNew = true)`
* `new TValue(DateTime time, double value, bool isNew = true)`
+57 -57
View File
@@ -1,57 +1,57 @@
using System.Runtime.CompilerServices;
namespace QuanTAlib;
/// <summary>
/// A lightweight struct representing a time-value pair.
/// Pure data type: 16 bytes (long + double).
/// </summary>
[SkipLocalsInit]
public readonly struct TValue : IEquatable<TValue>
{
/// <summary>
/// Time in ticks (UTC).
/// </summary>
public readonly long Time;
/// <summary>
/// The value.
/// </summary>
public readonly double Value;
/// <summary>
/// Convenience property to get DateTime from Ticks.
/// </summary>
public DateTime AsDateTime => new(Time, DateTimeKind.Utc);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue(long time, double value)
{
Time = time;
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue(DateTime time, double value)
{
Time = time.Ticks;
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator double(TValue tv) => tv.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator DateTime(TValue tv) => new(tv.Time, DateTimeKind.Utc);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {Value:F2}]";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(TValue other) => Time == other.Time && Value == other.Value;
public override bool Equals(object? obj) => obj is TValue other && Equals(other);
public override int GetHashCode() => HashCode.Combine(Time, Value);
public static bool operator ==(TValue left, TValue right) => left.Equals(right);
public static bool operator !=(TValue left, TValue right) => !left.Equals(right);
}
using System.Runtime.CompilerServices;
namespace QuanTAlib;
/// <summary>
/// A lightweight struct representing a time-value pair.
/// Pure data type: 16 bytes (long + double).
/// </summary>
[SkipLocalsInit]
public readonly struct TValue : IEquatable<TValue>
{
/// <summary>
/// Time in ticks (UTC).
/// </summary>
public readonly long Time;
/// <summary>
/// The value.
/// </summary>
public readonly double Value;
/// <summary>
/// Convenience property to get DateTime from Ticks.
/// </summary>
public DateTime AsDateTime => new(Time, DateTimeKind.Utc);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue(long time, double value)
{
Time = time;
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue(DateTime time, double value)
{
Time = time.Ticks;
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator double(TValue tv) => tv.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator DateTime(TValue tv) => new(tv.Time, DateTimeKind.Utc);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {Value:F2}]";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(TValue other) => Time == other.Time && Value == other.Value;
public override bool Equals(object? obj) => obj is TValue other && Equals(other);
public override int GetHashCode() => HashCode.Combine(Time, Value);
public static bool operator ==(TValue left, TValue right) => left.Equals(right);
public static bool operator !=(TValue left, TValue right) => !left.Equals(right);
}