mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-15 00:58:04 +00:00
Add TBar, TBarSeries, TSeries, TValue, and IFeed implementations with comprehensive documentation and examples
- Introduced TBar struct for efficient OHLCV data representation. - Implemented TBarSeries class for high-performance collection of TBar instances using Structure of Arrays (SoA) layout. - Added TSeries class for time-series data management with zero-copy access. - Created TValue struct for time-value pairs with implicit conversions. - Defined IFeed interface for consistent data feed implementations. - Developed CsvFeed class for loading historical OHLCV data from CSV files. - Implemented GBM class for generating synthetic financial data using Geometric Brownian Motion. - Added Quantower project files for Averages indicator with necessary dependencies and configurations. - Included extensive usage examples and notebooks for TBar, TBarSeries, TSeries, TValue, and feed implementations.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#!meta
|
||||
|
||||
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"languageName":"csharp","name":"csharp"}]}}
|
||||
|
||||
#!csharp
|
||||
|
||||
// Reference the library
|
||||
#r "..\..\bin\QuanTAlib.dll"
|
||||
|
||||
using QuanTAlib;
|
||||
|
||||
// 1. Creating a TBarSeries
|
||||
// TBarSeries is a collection of bars stored in Structure of Arrays (SoA) format
|
||||
// This layout is optimized for performance and SIMD operations
|
||||
|
||||
var bars = new TBarSeries();
|
||||
long now = DateTime.UtcNow.Ticks;
|
||||
|
||||
// Add a new bar
|
||||
var bar1 = new TBar(now, 100, 105, 95, 102, 1000);
|
||||
bars.Add(bar1, isNew: true);
|
||||
|
||||
Console.WriteLine($"Added Bar 1: Count={bars.Count}");
|
||||
Console.WriteLine($"Last Close: {bars.Last.Close}");
|
||||
|
||||
#!csharp
|
||||
|
||||
// 2. Streaming Updates
|
||||
// TBarSeries supports updating the last bar in place
|
||||
// This is crucial for real-time feeds where the current bar changes until it closes
|
||||
|
||||
// Update the bar (e.g. price changed within the same minute)
|
||||
var bar1Update = new TBar(now, 100, 106, 95, 104, 1500);
|
||||
bars.Add(bar1Update, isNew: false);
|
||||
|
||||
Console.WriteLine($"Updated Bar 1: Count={bars.Count} (Count should not increase)");
|
||||
Console.WriteLine($"Last Close: {bars.Last.Close}");
|
||||
Console.WriteLine($"Last High: {bars.Last.High}");
|
||||
|
||||
#!csharp
|
||||
|
||||
// 3. Zero-Copy Views
|
||||
// You can access individual components (Open, High, Low, Close, Volume) as TSeries
|
||||
// These views share the underlying memory, so no copying is involved
|
||||
|
||||
Console.WriteLine($"Bars Count: {bars.Count}");
|
||||
Console.WriteLine($"Close Series Count: {bars.Close.Count}");
|
||||
Console.WriteLine($"Close Series Last: {bars.Close.Last.Value}");
|
||||
|
||||
// Verify view updates automatically
|
||||
Console.WriteLine("\nAdding new bar...");
|
||||
bars.Add(now + TimeSpan.TicksPerMinute, 104, 108, 103, 107, 2000, isNew: true);
|
||||
|
||||
Console.WriteLine($"Bars Count: {bars.Count}");
|
||||
Console.WriteLine($"Close Series Count: {bars.Close.Count} (Should match Bars Count)");
|
||||
Console.WriteLine($"Close Series Last: {bars.Close.Last.Value} (Should be 107)");
|
||||
|
||||
#!csharp
|
||||
|
||||
// 4. Aliases and Direct Access
|
||||
// TBarSeries provides short aliases (O, H, L, C, V) and direct access properties
|
||||
|
||||
Console.WriteLine($"Alias Access (C.Last): {bars.C.Last.Value}");
|
||||
Console.WriteLine($"Direct Last Access (LastClose): {bars.LastClose}");
|
||||
Console.WriteLine($"Direct Last Time (LastTime): {new DateTime(bars.LastTime)}");
|
||||
|
||||
#!csharp
|
||||
|
||||
// 5. Iteration
|
||||
// You can iterate over the bars or individual series
|
||||
|
||||
Console.WriteLine("\nIterating over bars:");
|
||||
foreach (var bar in bars)
|
||||
{
|
||||
Console.WriteLine($" {bar}");
|
||||
}
|
||||
|
||||
Console.WriteLine("\nIterating over Close prices:");
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
Console.WriteLine($" Bar {i}: Close={bars.Close[i].Value}");
|
||||
}
|
||||
Reference in New Issue
Block a user