* Use new lang feats: nullable, and 'init' prop setters * Group 'sod', 'day', and 'working' members in respective groups * Run formatter
142 lines
5.8 KiB
C#
142 lines
5.8 KiB
C#
#nullable enable
|
|
namespace bts.shell.pnl {
|
|
using bts.utils;
|
|
|
|
using System;
|
|
|
|
readonly struct PNLNormalizedData : IEquatable<PNLNormalizedData> {
|
|
public static readonly PNLNormalizedData zero =
|
|
new() {
|
|
// sod
|
|
sod_pnl = 0,
|
|
sod_long_pos = 0,
|
|
sod_short_pos = 0,
|
|
display_sod_long_pos = 0,
|
|
display_sod_short_pos = 0,
|
|
|
|
// day
|
|
day_pnl = 0,
|
|
day_long_pos = 0,
|
|
day_short_pos = 0,
|
|
display_day_long_pos = 0,
|
|
display_day_short_pos = 0,
|
|
|
|
// working
|
|
working_long_pos = 0,
|
|
working_short_pos = 0,
|
|
display_working_long_pos = 0,
|
|
display_working_short_pos = 0
|
|
};
|
|
|
|
// sod
|
|
public decimal sod_pnl { get; init; }
|
|
public decimal sod_long_pos { get; init; }
|
|
public decimal sod_short_pos { get; init; }
|
|
public decimal sod_net_pos => sod_long_pos - sod_short_pos;
|
|
public decimal display_sod_long_pos { get; init; }
|
|
public decimal display_sod_short_pos { get; init; }
|
|
public decimal display_sod_net_pos => display_sod_long_pos - display_sod_short_pos;
|
|
|
|
// day
|
|
public decimal day_pnl { get; init; }
|
|
public decimal day_long_pos { get; init; }
|
|
public decimal day_short_pos { get; init; }
|
|
public decimal day_net_pos => day_long_pos - day_short_pos;
|
|
public decimal display_day_long_pos { get; init; }
|
|
public decimal display_day_short_pos { get; init; }
|
|
public decimal display_day_net_pos => display_day_long_pos - display_day_short_pos;
|
|
|
|
// total
|
|
public decimal total_pnl => sod_pnl + day_pnl;
|
|
public decimal total_net_pos => total_long_pos - total_short_pos;
|
|
public decimal total_long_pos => sod_long_pos + day_long_pos;
|
|
public decimal total_short_pos => sod_short_pos + day_short_pos;
|
|
public decimal display_total_long_pos => display_sod_long_pos + display_day_long_pos;
|
|
public decimal display_total_short_pos => display_sod_short_pos + display_day_short_pos;
|
|
public decimal display_total_net_pos => display_total_long_pos - display_total_short_pos;
|
|
|
|
// working
|
|
public decimal working_long_pos { get; init; }
|
|
public decimal working_short_pos { get; init; }
|
|
public decimal working_net_pos => working_long_pos - working_short_pos;
|
|
public decimal display_working_long_pos { get; init; }
|
|
public decimal display_working_short_pos { get; init; }
|
|
public decimal display_working_net_pos => display_working_long_pos - display_working_short_pos;
|
|
|
|
public bool Equals(PNLNormalizedData other) =>
|
|
// sod
|
|
sod_pnl == other.sod_pnl &&
|
|
sod_long_pos == other.sod_long_pos &&
|
|
sod_short_pos == other.sod_short_pos &&
|
|
display_sod_long_pos == other.display_sod_long_pos &&
|
|
display_sod_short_pos == other.display_sod_short_pos &&
|
|
|
|
// day
|
|
day_pnl == other.day_pnl &&
|
|
day_long_pos == other.day_long_pos &&
|
|
day_short_pos == other.day_short_pos &&
|
|
display_day_long_pos == other.display_day_long_pos &&
|
|
display_day_short_pos == other.display_day_short_pos &&
|
|
|
|
// working
|
|
working_long_pos == other.working_long_pos &&
|
|
working_short_pos == other.working_short_pos &&
|
|
display_working_long_pos == other.display_working_long_pos &&
|
|
display_working_short_pos == other.display_working_short_pos;
|
|
|
|
public override bool Equals(object? obj) =>
|
|
obj is PNLNormalizedData other && Equals(other);
|
|
|
|
public override int GetHashCode() =>
|
|
EqualityComparer.aggregate_hash(
|
|
day_pnl.GetHashCode(),
|
|
sod_pnl.GetHashCode());
|
|
|
|
public override string ToString() =>
|
|
string.Join(",", new[] {
|
|
$"SOD PNL: {sod_pnl}",
|
|
$"SOD Long: {sod_long_pos}",
|
|
$"SOD Short: {sod_short_pos}",
|
|
$"Day PNL: {day_pnl}",
|
|
$"Day Long: {day_long_pos}",
|
|
$"Day Short: {day_short_pos}",
|
|
$"Wrk Long: {working_long_pos}",
|
|
$"Wrk Short: {working_short_pos}",
|
|
});
|
|
|
|
public static bool operator ==(PNLNormalizedData a, PNLNormalizedData b) => a.Equals(b);
|
|
public static bool operator !=(PNLNormalizedData a, PNLNormalizedData b) => !a.Equals(b);
|
|
|
|
public static PNLNormalizedData operator +(PNLNormalizedData a, PNLNormalizedData b) =>
|
|
_operate(a, b, (ax, bx) => ax + bx);
|
|
|
|
public static PNLNormalizedData operator -(PNLNormalizedData a, PNLNormalizedData b) =>
|
|
_operate(a, b, (ax, bx) => ax - bx);
|
|
|
|
static PNLNormalizedData _operate(
|
|
PNLNormalizedData a, PNLNormalizedData b, Func<decimal, decimal, decimal> op) =>
|
|
new() {
|
|
// sod
|
|
sod_pnl = op(a.sod_pnl, b.sod_pnl),
|
|
sod_long_pos = op(a.sod_long_pos, b.sod_long_pos),
|
|
sod_short_pos = op(a.sod_short_pos, b.sod_short_pos),
|
|
display_sod_long_pos = op(a.display_sod_long_pos, b.display_sod_long_pos),
|
|
display_sod_short_pos = op(a.display_sod_short_pos, b.display_sod_short_pos),
|
|
|
|
// day
|
|
day_pnl = op(a.day_pnl, b.day_pnl),
|
|
day_long_pos = op(a.day_long_pos, b.day_long_pos),
|
|
day_short_pos = op(a.day_short_pos, b.day_short_pos),
|
|
display_day_long_pos = op(a.display_day_long_pos, b.display_day_long_pos),
|
|
display_day_short_pos = op(a.display_day_short_pos, b.display_day_short_pos),
|
|
|
|
// working
|
|
working_long_pos = op(a.working_long_pos, b.working_long_pos),
|
|
working_short_pos = op(a.working_short_pos, b.working_short_pos),
|
|
display_working_long_pos = op(a.display_working_long_pos, b.display_working_long_pos),
|
|
display_working_short_pos = op(
|
|
a.display_working_short_pos, b.display_working_short_pos),
|
|
};
|
|
}
|
|
}
|