mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-13 08:08:05 +00:00
70 lines
1.9 KiB
Plaintext
70 lines
1.9 KiB
Plaintext
#!meta
|
|||
|
|
|
||
|
|
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"name":"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"}]}}
|
||
|
|
|
||
|
|
#!markdown
|
||
|
|
|
||
|
|
# TValue Examples
|
||
|
|
|
||
|
|
This notebook demonstrates the usage of `TValue`, the fundamental data structure in QuanTAlib.
|
||
|
|
|
||
|
|
For detailed documentation, see [TValue.md](TValue.md).
|
||
|
|
|
||
|
|
#!csharp
|
||
|
|
|
||
|
|
// Reference the library
|
||
|
|
#r "..\..\bin\QuanTAlib.dll"
|
||
|
|
|
||
|
|
using System;
|
||
|
|
using QuanTAlib;
|
||
|
|
|
||
|
|
#!markdown
|
||
|
|
|
||
|
|
## Creating TValue
|
||
|
|
|
||
|
|
You can create a `TValue` using `DateTime` or `ticks`.
|
||
|
|
|
||
|
|
#!csharp
|
||
|
|
|
||
|
|
// Using DateTime
|
||
|
|
var now = DateTime.UtcNow;
|
||
|
|
var val1 = new TValue(now, 100.5);
|
||
|
|
Console.WriteLine($"Created TValue: Time={val1.AsDateTime}, Value={val1.Value}");
|
||
|
|
|
||
|
|
// Using Ticks
|
||
|
|
long ticks = now.AddMinutes(1).Ticks;
|
||
|
|
var val2 = new TValue(ticks, 101.0);
|
||
|
|
Console.WriteLine($"Created TValue: Time={val2.AsDateTime}, Value={val2.Value}");
|
||
|
|
|
||
|
|
#!markdown
|
||
|
|
|
||
|
|
## Implicit Conversions
|
||
|
|
|
||
|
|
`TValue` supports implicit conversions to `double` and `DateTime` for convenience.
|
||
|
|
|
||
|
|
#!csharp
|
||
|
|
|
||
|
|
double d = val1; // Implicitly gets Value
|
||
|
|
DateTime t = val1; // Implicitly gets Time (as DateTime)
|
||
|
|
|
||
|
|
Console.WriteLine($"Double: {d}");
|
||
|
|
Console.WriteLine($"DateTime: {t}");
|
||
|
|
|
||
|
|
// Arithmetic operations using implicit conversion
|
||
|
|
double result = val1 + 5.0;
|
||
|
|
Console.WriteLine($"Result (100.5 + 5.0): {result}");
|
||
|
|
|
||
|
|
#!markdown
|
||
|
|
|
||
|
|
## Immutability
|
||
|
|
|
||
|
|
`TValue` is immutable. You cannot change its properties after creation.
|
||
|
|
|
||
|
|
#!csharp
|
||
|
|
|
||
|
|
// val1.Value = 200; // Error: Property or indexer 'TValue.Value' cannot be assigned to -- it is read only
|
||
|
|
|
||
|
|
// To "change" a value, create a new instance
|
||
|
|
var val3 = new TValue(val1.Time, 200.0);
|
||
|
|
Console.WriteLine($"New TValue: {val3.Value}");
|