190 lines
8.6 KiB
C#
190 lines
8.6 KiB
C#
using bts.utils;
|
|
using System;
|
|
|
|
namespace bts.shell.pnl {
|
|
readonly struct PNLNormalizedData : IEquatable<PNLNormalizedData> {
|
|
public static readonly PNLNormalizedData zero =
|
|
new PNLNormalizedData(0, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
public PNLNormalizedData(
|
|
decimal day_pnl,
|
|
decimal day_long_pos,
|
|
decimal day_short_pos,
|
|
decimal raw_day_long_pos,
|
|
decimal raw_day_short_pos,
|
|
decimal sod_pnl,
|
|
decimal sod_long_pos,
|
|
decimal sod_short_pos,
|
|
decimal working_long_pos = 0,
|
|
decimal working_short_pos = 0,
|
|
decimal? display_day_long_pos = null,
|
|
decimal? display_day_short_pos = null,
|
|
decimal? display_raw_day_long_pos = null,
|
|
decimal? display_raw_day_short_pos = null,
|
|
decimal? display_sod_long_pos = null,
|
|
decimal? display_sod_short_pos = null,
|
|
decimal? display_working_long_pos = null,
|
|
decimal? display_working_short_pos = null) {
|
|
//
|
|
this.day_pnl = day_pnl;
|
|
this.day_long_pos = day_long_pos;
|
|
this.day_short_pos = day_short_pos;
|
|
this.raw_day_long_pos = raw_day_long_pos;
|
|
this.raw_day_short_pos = raw_day_short_pos;
|
|
this.sod_pnl = sod_pnl;
|
|
this.sod_long_pos = sod_long_pos;
|
|
this.sod_short_pos = sod_short_pos;
|
|
this.working_long_pos = working_long_pos;
|
|
this.working_short_pos = working_short_pos;
|
|
// display
|
|
this.display_day_long_pos = display_day_long_pos ?? day_long_pos;
|
|
this.display_day_short_pos = display_day_short_pos ?? day_short_pos;
|
|
this.display_raw_day_long_pos = display_raw_day_long_pos ?? raw_day_long_pos;
|
|
this.display_raw_day_short_pos = display_raw_day_short_pos ?? raw_day_short_pos;
|
|
this.display_sod_long_pos = display_sod_long_pos ?? sod_long_pos;
|
|
this.display_sod_short_pos = display_sod_short_pos ?? sod_short_pos;
|
|
this.display_working_long_pos = display_working_long_pos ?? working_long_pos;
|
|
this.display_working_short_pos = display_working_short_pos ?? working_short_pos;
|
|
}
|
|
|
|
// sod
|
|
public decimal sod_pnl { get; }
|
|
public decimal sod_long_pos { get; }
|
|
public decimal sod_short_pos { get; }
|
|
public decimal sod_net_pos => sod_long_pos - sod_short_pos;
|
|
// sod display
|
|
public decimal display_sod_long_pos { get; }
|
|
public decimal display_sod_short_pos { get; }
|
|
public decimal display_sod_net_pos => display_sod_long_pos - display_sod_short_pos;
|
|
|
|
// day
|
|
public decimal day_pnl { get; }
|
|
public decimal day_long_pos { get; }
|
|
public decimal day_short_pos { get; }
|
|
public decimal day_net_pos => day_long_pos - day_short_pos;
|
|
// display
|
|
public decimal display_day_long_pos { get; }
|
|
public decimal display_day_short_pos { get; }
|
|
public decimal display_day_net_pos => display_day_long_pos - display_day_short_pos;
|
|
|
|
// raw day
|
|
public decimal raw_day_long_pos { get; }
|
|
public decimal raw_day_short_pos { get; }
|
|
public decimal raw_day_net_pos => raw_day_long_pos - raw_day_short_pos;
|
|
// display
|
|
public decimal display_raw_day_long_pos { get; }
|
|
public decimal display_raw_day_short_pos { get; }
|
|
public decimal display_raw_day_net_pos => display_raw_day_long_pos - display_raw_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;
|
|
// display
|
|
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; }
|
|
public decimal working_short_pos { get; }
|
|
public decimal working_net_pos => working_long_pos - working_short_pos;
|
|
// display
|
|
public decimal display_working_long_pos { get; }
|
|
public decimal display_working_short_pos { get; }
|
|
public decimal display_working_net_pos => display_working_long_pos - display_working_short_pos;
|
|
|
|
public bool Equals(PNLNormalizedData other) =>
|
|
day_pnl == other.day_pnl &&
|
|
day_long_pos == other.day_long_pos &&
|
|
day_short_pos == other.day_short_pos &&
|
|
raw_day_long_pos == other.raw_day_long_pos &&
|
|
raw_day_short_pos == other.raw_day_short_pos &&
|
|
sod_pnl == other.sod_pnl &&
|
|
sod_long_pos == other.sod_long_pos &&
|
|
sod_short_pos == other.sod_short_pos &&
|
|
working_long_pos == other.working_long_pos &&
|
|
working_short_pos == other.working_short_pos &&
|
|
// display
|
|
sod_long_pos == other.sod_long_pos &&
|
|
sod_short_pos == other.sod_short_pos &&
|
|
day_long_pos == other.day_long_pos &&
|
|
day_short_pos == other.day_short_pos &&
|
|
raw_day_long_pos == other.raw_day_long_pos &&
|
|
raw_day_short_pos == other.raw_day_short_pos &&
|
|
total_long_pos == other.total_long_pos &&
|
|
total_short_pos == other.total_short_pos &&
|
|
working_long_pos == other.working_long_pos &&
|
|
working_short_pos == other.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}",
|
|
$"Raw Day Long : {raw_day_long_pos}",
|
|
$"Raw Day Short: {raw_day_short_pos}",
|
|
$"Work Long : {working_long_pos}",
|
|
$"Work 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) =>
|
|
new PNLNormalizedData(
|
|
a.day_pnl + b.day_pnl,
|
|
a.day_long_pos + b.day_long_pos,
|
|
a.day_short_pos + b.day_short_pos,
|
|
a.raw_day_long_pos + b.raw_day_long_pos,
|
|
a.raw_day_short_pos + b.raw_day_short_pos,
|
|
a.sod_pnl + b.sod_pnl,
|
|
a.sod_long_pos + b.sod_long_pos,
|
|
a.sod_short_pos + b.sod_short_pos,
|
|
a.working_long_pos + b.working_long_pos,
|
|
a.working_short_pos + b.working_short_pos,
|
|
// display
|
|
a.display_day_long_pos + b.display_day_long_pos,
|
|
a.display_day_short_pos + b.display_day_short_pos,
|
|
a.display_raw_day_long_pos + b.display_raw_day_long_pos,
|
|
a.display_raw_day_short_pos + b.display_raw_day_short_pos,
|
|
a.display_sod_long_pos + b.display_sod_long_pos,
|
|
a.display_sod_short_pos + b.display_sod_short_pos,
|
|
a.display_working_long_pos + b.display_working_long_pos,
|
|
a.display_working_short_pos + b.display_working_short_pos);
|
|
|
|
public static PNLNormalizedData operator -(PNLNormalizedData a, PNLNormalizedData b) =>
|
|
new PNLNormalizedData(
|
|
a.day_pnl - b.day_pnl,
|
|
a.day_long_pos - b.day_long_pos,
|
|
a.day_short_pos - b.day_short_pos,
|
|
a.raw_day_long_pos - b.raw_day_long_pos,
|
|
a.raw_day_short_pos - b.raw_day_short_pos,
|
|
a.sod_pnl - b.sod_pnl,
|
|
a.sod_long_pos - b.sod_long_pos,
|
|
a.sod_short_pos - b.sod_short_pos,
|
|
a.working_long_pos - b.working_long_pos,
|
|
a.working_short_pos - b.working_short_pos,
|
|
// display
|
|
a.display_day_long_pos - b.display_day_long_pos,
|
|
a.display_day_short_pos - b.display_day_short_pos,
|
|
a.display_raw_day_long_pos - b.display_raw_day_long_pos,
|
|
a.display_raw_day_short_pos - b.display_raw_day_short_pos,
|
|
a.display_sod_long_pos - b.display_sod_long_pos,
|
|
a.display_sod_short_pos - b.display_sod_short_pos,
|
|
a.display_working_long_pos - b.display_working_long_pos,
|
|
a.display_working_short_pos - b.display_working_short_pos);
|
|
}
|
|
} |