mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-06 13:07:44 +00:00
74b49d2bb4
- 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.
70 lines
2.1 KiB
Plaintext
70 lines
2.1 KiB
Plaintext
#!meta
|
|
|
|
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"name":"csharp","languageName":"csharp"},{"name":"fsharp","languageName":"F#","aliases":["f#","fs"]},{"name":"html","languageName":"HTML"},{"name":"http","languageName":"HTTP"},{"name":"javascript","languageName":"JavaScript","aliases":["js"]},{"name":"mermaid","languageName":"Mermaid"},{"name":"pwsh","languageName":"PowerShell","aliases":["powershell"]},{"name":"value"}]}}
|
|
|
|
#!csharp
|
|
|
|
// Reference the library
|
|
#r "..\..\bin\QuanTAlib.dll"
|
|
|
|
using QuanTAlib;
|
|
|
|
// 1. Initialize GBM Generator
|
|
// GBM simulates price movements using Geometric Brownian Motion
|
|
// Parameters: Start Price, Drift (mu), Volatility (sigma)
|
|
|
|
var gbm = new GBM(startPrice: 100.0, mu: 0.05, sigma: 0.2);
|
|
Console.WriteLine("GBM Generator initialized (Start=100, Drift=5%, Vol=20%)");
|
|
|
|
#!csharp
|
|
|
|
// 2. Batch Generation
|
|
// Generate a sequence of bars at once
|
|
// Useful for backtesting or initializing indicators
|
|
|
|
long startTime = DateTime.UtcNow.Ticks;
|
|
var interval = TimeSpan.FromMinutes(1);
|
|
|
|
var history = gbm.Fetch(10, startTime, interval);
|
|
|
|
Console.WriteLine($"Generated {history.Count} bars:");
|
|
for (int i = 0; i < history.Count; i++)
|
|
{
|
|
Console.WriteLine($" Bar {i}: Time={history[i].AsDateTime:HH:mm}, Close={history[i].Close:F2}");
|
|
}
|
|
|
|
#!csharp
|
|
|
|
// 3. Streaming Generation
|
|
// Simulate real-time data feed bar by bar
|
|
|
|
Console.WriteLine("\nStreaming new bars:");
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
var bar = gbm.Next(isNew: true);
|
|
Console.WriteLine($" New Bar: {bar.Close:F2}");
|
|
}
|
|
|
|
#!csharp
|
|
|
|
// 4. Intra-bar Updates
|
|
// Simulate real-time price ticks within a single bar
|
|
// The High/Low will expand, and Close will update
|
|
|
|
Console.WriteLine("\nSimulating intra-bar updates:");
|
|
|
|
// Start a new bar
|
|
var liveBar = gbm.Next(isNew: true);
|
|
Console.WriteLine($" Open: {liveBar.Open:F2}, Close: {liveBar.Close:F2}");
|
|
|
|
// Simulate 5 ticks
|
|
for (int i = 1; i <= 5; i++)
|
|
{
|
|
liveBar = gbm.Next(isNew: false);
|
|
Console.WriteLine($" Tick {i}: Close={liveBar.Close:F2}, High={liveBar.High:F2}, Low={liveBar.Low:F2}");
|
|
}
|
|
|
|
// Finalize bar
|
|
liveBar = gbm.Next(isNew: true);
|
|
Console.WriteLine($" Finalized Previous, Started New: {liveBar.Open:F2}");
|