Skip to content

Commit

Permalink
Merge branch 'b-seite-ewmaTrend'
Browse files Browse the repository at this point in the history
Free Software Free Society

To support commits by ctubio,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <[email protected]>
  • Loading branch information
ctubio committed Feb 3, 2018
2 parents a821c61 + 9961548 commit 38134c8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
28 changes: 27 additions & 1 deletion src/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ class DisplayOrder {
<th title="Use a quote protection of periods smoothed line of the fair value to limit the price while sending new orders.">ewmaPrice?</th>
<th title="Maximum amount of values collected in the sequences used to calculate the ewmaPrice? and ewmaWidth? quote protection." *ngIf="pair.quotingParameters.display.protectionEwmaQuotePrice || pair.quotingParameters.display.protectionEwmaWidthPing">periodsᵉʷᵐᵃ</th>
<th title="Use a quote protection of periods smoothed line of the width (between the top bid and the top ask) to limit the widthPing while sending new orders.">ewmaWidth?</th>
<th title="To do..">ewmaTrend?</th>
<th title="To do.." *ngIf="pair.quotingParameters.display.quotingEwmaTrendProtection">threshold</th>
<th title="To do.." *ngIf="pair.quotingParameters.display.quotingEwmaTrendProtection">micro</th>
<th title="To do.." *ngIf="pair.quotingParameters.display.quotingEwmaTrendProtection">ultra</th>
<th title="Limit the price of new orders.">stdev</th>
<th title="Maximum amount of values collected in the sequences used to calculate the STDEV, each side may have its own STDEV calculation with the same amount of periods." *ngIf="pair.quotingParameters.display.quotingStdevProtection">periodsˢᵗᵈᶜᵛ</th>
<th title="Multiplier used to increase or decrease the value of the selected stdev calculation, a factor of 1 does effectively nothing." *ngIf="pair.quotingParameters.display.quotingStdevProtection">factor</th>
Expand Down Expand Up @@ -430,10 +434,32 @@ class DisplayOrder {
<input type="checkbox"
[(ngModel)]="pair.quotingParameters.display.protectionEwmaWidthPing">
</td>
<td style="text-align: center;border-bottom: 3px solid #fd00ff;">
<input type="checkbox"
[(ngModel)]="pair.quotingParameters.display.quotingEwmaTrendProtection">
</td>
<td style="width:60px;border-bottom: 3px solid #fd00ff;" *ngIf="pair.quotingParameters.display.quotingEwmaTrendProtection">
<input class="form-control input-sm"
type="number" step="0.1" min="0.1"
onClick="this.select()"
[(ngModel)]="pair.quotingParameters.display.quotingEwmaTrendThreshold">
</td>
<td style="width:60px;border-bottom: 3px solid #fd00ff;" *ngIf="pair.quotingParameters.display.quotingEwmaTrendProtection">
<input class="form-control input-sm"
type="number" step="1" min="1"
onClick="this.select()"
[(ngModel)]="pair.quotingParameters.display.extraShortEwmaPeriods">
</td>
<td style="width:60px;border-bottom: 3px solid #fd00ff;" *ngIf="pair.quotingParameters.display.quotingEwmaTrendProtection">
<input class="form-control input-sm"
type="number" step="1" min="1"
onClick="this.select()"
[(ngModel)]="pair.quotingParameters.display.ultraShortEwmaPeriods">
</td>
<td style="width:121px;border-bottom: 3px solid #AF451E;">
<select class="form-control input-sm"
[(ngModel)]="pair.quotingParameters.display.quotingStdevProtection">
<option *ngFor="let option of pair.quotingParameters.availableSTDEV" [ngValue]="option.val">{{option.str}}</option>
<option *ngFor="let option of pair.quotingParameters.availableSTDEV" [ngValue]="option.val">{{option.str}}</option>
</select>
</td>
<td style="width:88px;border-bottom: 3px solid #AF451E;" *ngIf="pair.quotingParameters.display.quotingStdevProtection">
Expand Down
7 changes: 6 additions & 1 deletion src/client/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class EWMAChart {
public ewmaMedium: number,
public ewmaLong: number,
public ewmaVeryLong: number,
public ewmaTrendDiff: number,
public tradesBuySize: number,
public tradesSellSize: number,
public fairValue: number) {}
Expand Down Expand Up @@ -163,7 +164,7 @@ export class TwoSidedQuote {
constructor(public bid: Quote, public ask: Quote) {}
}

export enum QuoteStatus { Live, Disconnected, DisabledQuotes, MissingData, UnknownHeld, TBPHeld, MaxTradesSeconds, WaitingPing, DepletedFunds, Crossed }
export enum QuoteStatus { Live, Disconnected, DisabledQuotes, MissingData, UnknownHeld, TBPHeld, MaxTradesSeconds, WaitingPing, DepletedFunds, Crossed, UpTrendHeld, DownTrendHeld }

export class TwoSidedQuoteStatus {
constructor(public bidStatus: QuoteStatus, public askStatus: QuoteStatus, public quotesInMemoryNew: number, public quotesInMemoryWorking: number, public quotesInMemoryDone: number) {}
Expand Down Expand Up @@ -217,6 +218,8 @@ export interface QuotingParameters {
tradeRateSeconds?: number;
protectionEwmaWidthPing?: boolean;
protectionEwmaQuotePrice?: boolean;
quotingEwmaTrendProtection?: boolean;
quotingEwmaTrendThreshold?: number;
quotingStdevProtection?: STDEV;
quotingStdevBollingerBands?: boolean;
audio?: boolean;
Expand All @@ -228,6 +231,8 @@ export interface QuotingParameters {
longEwmaPeriods?: number;
mediumEwmaPeriods?: number;
shortEwmaPeriods?: number;
microEwmaPeriods?: number;
ultraEwmaPeriods?: number;
protectionEwmaPeriods?: number;
quotingStdevProtectionFactor?: number;
quotingStdevProtectionPeriods?: number;
Expand Down
10 changes: 10 additions & 0 deletions src/client/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class StatsComponent implements OnInit {
public ewmaMedium: number;
public ewmaLong: number;
public ewmaVeryLong: number;
public ewmaTrendDiff: number;
public stdevWidth: Models.IStdev;
public tradesBuySize: number;
public tradesSellSize: number;
Expand Down Expand Up @@ -279,6 +280,13 @@ export class StatsComponent implements OnInit {
colorIndex:5,
data: [],
zIndex: -2
},{
name: 'EWMA SMU Diff',
type: 'spline',
color: '#fd00ff',
tooltip: {pointFormatter: this.pointFormatterBase},
yAxis: 1,
data: []
}]
};
public quoteChartOptions = {
Expand Down Expand Up @@ -482,6 +490,7 @@ export class StatsComponent implements OnInit {
if (o.stdevWidth) this.stdevWidth = o.stdevWidth;
if (o.tradesBuySize) this.tradesBuySize = o.tradesBuySize;
if (o.tradesSellSize) this.tradesSellSize = o.tradesSellSize;
if (o.ewmaTrendDiff) this.ewmaTrendDiff = o.ewmaTrendDiff;
}

@Input() set setTradesChartData(t: Models.TradeChart) {
Expand Down Expand Up @@ -610,6 +619,7 @@ export class StatsComponent implements OnInit {
if (this.ewmaMedium) Highcharts.charts[this.fvChart].series[9].addPoint([time, this.ewmaMedium], false);
if (this.ewmaShort) Highcharts.charts[this.fvChart].series[10].addPoint([time, this.ewmaShort], false);
Highcharts.charts[this.fvChart].series[0].addPoint([time, this.fairValue], this.showStats);
if (this.ewmaTrendDiff) Highcharts.charts[this.fvChart].series[20].addPoint([time, this.ewmaTrendDiff], false);
if ((<any>Highcharts).quotingParameters.protectionEwmaWidthPing && this.ewmaWidth) Highcharts.charts[this.fvChart].series[1].addPoint([time, this.fairValue-this.ewmaWidth, this.fairValue+this.ewmaWidth], this.showStats, false, false);
else if (this.width) Highcharts.charts[this.fvChart].series[1].addPoint([time, this.fairValue-this.width, this.fairValue+this.width], this.showStats, false, false);
}
Expand Down
20 changes: 18 additions & 2 deletions src/server/km.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace K {
enum class mPongAt: unsigned int { ShortPingFair, LongPingFair, ShortPingAggressive, LongPingAggressive };
enum class mQuotingMode: unsigned int { Top, Mid, Join, InverseJoin, InverseTop, HamelinRat, Depth };
enum class mQuotingSafety: unsigned int { Off, PingPong, Boomerang, AK47 };
enum class mQuoteState: unsigned int { Live, Disconnected, DisabledQuotes, MissingData, UnknownHeld, TBPHeld, MaxTradesSeconds, WaitingPing, DepletedFunds, Crossed };
enum class mQuoteState: unsigned int { Live, Disconnected, DisabledQuotes, MissingData, UnknownHeld, TBPHeld, MaxTradesSeconds, WaitingPing, DepletedFunds, Crossed, UpTrendHeld, DownTrendHeld };
enum class mFairValueModel: unsigned int { BBO, wBBO };
enum class mAutoPositionMode: unsigned int { Manual, EWMA_LS, EWMA_LMS, EWMA_4 };
enum class mPDivMode: unsigned int { Manual, Linear, Sine, SQRT, Switch};
Expand Down Expand Up @@ -80,10 +80,14 @@ namespace K {
double quotingStdevProtectionFactor = 1.0;
unsigned int quotingStdevProtectionPeriods = 1200;
double ewmaSensiblityPercentage = 0.5;
bool quotingEwmaTrendProtection = false;
double quotingEwmaTrendThreshold = 2.0;
unsigned int veryLongEwmaPeriods = 400;
unsigned int longEwmaPeriods = 200;
unsigned int mediumEwmaPeriods = 100;
unsigned int shortEwmaPeriods = 50;
unsigned int extraShortEwmaPeriods = 12;
unsigned int ultraShortEwmaPeriods = 3;
double aprMultiplier = 2;
double sopWidthMultiplier = 2;
double sopSizeMultiplier = 2;
Expand All @@ -98,6 +102,8 @@ namespace K {
bool _diffLEP = false;
bool _diffMEP = false;
bool _diffSEP = false;
bool _diffXSEP = false;
bool _diffUEP = false;
void tidy() {
if (mode == mQuotingMode::Depth) widthPercentage = false;
};
Expand All @@ -109,6 +115,8 @@ namespace K {
_diffLEP = prev.longEwmaPeriods != longEwmaPeriods;
_diffMEP = prev.mediumEwmaPeriods != mediumEwmaPeriods;
_diffSEP = prev.shortEwmaPeriods != shortEwmaPeriods;
_diffXSEP = prev.extraShortEwmaPeriods != shortEwmaPeriods;
_diffUEP = prev.ultraShortEwmaPeriods != shortEwmaPeriods;
};
bool diffOnce(bool *k) {
bool ret = *k;
Expand Down Expand Up @@ -159,10 +167,14 @@ namespace K {
{ "quotingStdevProtectionFactor", k.quotingStdevProtectionFactor },
{ "quotingStdevProtectionPeriods", k.quotingStdevProtectionPeriods },
{ "ewmaSensiblityPercentage", k.ewmaSensiblityPercentage },
{ "quotingEwmaTrendProtection ", k.quotingEwmaTrendProtection },
{ "quotingEwmaTrendThreshold", k.quotingEwmaTrendThreshold },
{ "veryLongEwmaPeriods", k.veryLongEwmaPeriods },
{ "longEwmaPeriods", k.longEwmaPeriods },
{ "mediumEwmaPeriods", k.mediumEwmaPeriods },
{ "shortEwmaPeriods", k.shortEwmaPeriods },
{ "extraShortEwmaPeriods", k.extraShortEwmaPeriods },
{ "ultraShortEwmaPeriods", k.ultraShortEwmaPeriods },
{ "aprMultiplier", k.aprMultiplier },
{ "sopWidthMultiplier", k.sopWidthMultiplier },
{ "sopSizeMultiplier", k.sopSizeMultiplier },
Expand Down Expand Up @@ -216,10 +228,14 @@ namespace K {
k.quotingStdevProtectionFactor = j.value("quotingStdevProtectionFactor", k.quotingStdevProtectionFactor);
k.quotingStdevProtectionPeriods = fmax(1, j.value("quotingStdevProtectionPeriods", k.quotingStdevProtectionPeriods));
k.ewmaSensiblityPercentage = j.value("ewmaSensiblityPercentage", k.ewmaSensiblityPercentage);
k.veryLongEwmaPeriods = fmax(1, j.value("veryLongEwmaPeriods", k.veryLongEwmaPeriods));
k.quotingEwmaTrendProtection = j.value("quotingEwmaTrendProtection", k.quotingEwmaTrendProtection);
k.quotingEwmaTrendThreshold = j.value("quotingEwmaTrendThreshold ", k.quotingEwmaTrendThreshold);
k.veryLongEwmaPeriods = fmax(1, j.value("veryLongEwmaPeriods", k.veryLongEwmaPeriods));
k.longEwmaPeriods = fmax(1, j.value("longEwmaPeriods", k.longEwmaPeriods));
k.mediumEwmaPeriods = fmax(1, j.value("mediumEwmaPeriods", k.mediumEwmaPeriods));
k.shortEwmaPeriods = fmax(1, j.value("shortEwmaPeriods", k.shortEwmaPeriods));
k.extraShortEwmaPeriods = fmax(1, j.value("extraShortEwmaPeriods", k.extraShortEwmaPeriods));
k.ultraShortEwmaPeriods = fmax(1, j.value("ultraShortEwmaPeriods", k.ultraShortEwmaPeriods));
k.aprMultiplier = j.value("aprMultiplier", k.aprMultiplier);
k.sopWidthMultiplier = j.value("sopWidthMultiplier", k.sopWidthMultiplier);
k.sopSizeMultiplier = j.value("sopSizeMultiplier", k.sopSizeMultiplier);
Expand Down
13 changes: 12 additions & 1 deletion src/server/mg.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace K {
mPrice mgEwmaVL = 0,
mgEwmaL = 0,
mgEwmaM = 0,
mgEwmaS = 0;
mgEwmaS = 0,
mgEwmaXS = 0,
mgEwmaU = 0;
vector<mPrice> mgSMA3,
mgStatFV,
mgStatBid,
Expand Down Expand Up @@ -93,6 +95,7 @@ namespace K {
calcStatsTrades();
calcStatsEwmaProtection();
calcStatsEwmaPosition();
calcStatsEwmaTrendProtection();
} else if (mgT_60s == 60) mgT_60s = 0;
calcStatsStdevProtection();
};
Expand Down Expand Up @@ -236,11 +239,19 @@ namespace K {
{"ewmaMedium", mgEwmaM},
{"ewmaLong", mgEwmaL},
{"ewmaVeryLong", mgEwmaVL},
{"ewmaTrendDiff", mgEwmaTrendDiff},
{"tradesBuySize", takersBuySize60s},
{"tradesSellSize", takersSellSize60s},
{"fairValue", fairValue}
};
};
void calcStatsEwmaTrendProtection() {
calcEwma(&mgEwmaXS, qp.quotingEwmaSMPeriods, fairValue);
calcEwma(&mgEwmaU, qp.quotingEwmaSUPeriods, fairValue);
if(mgEwmaXS && mgEwmaU)
mgEwmaTrendDiff = ((mgEwmaU * 100) / mgEwmaXS) - 100;
ev_mgEwmaSMUProtection();
};
void cleanStdev() {
size_t periods = (size_t)qp->quotingStdevProtectionPeriods;
if (mgStatFV.size()>periods) mgStatFV.erase(mgStatFV.begin(), mgStatFV.end()-periods);
Expand Down

0 comments on commit 38134c8

Please sign in to comment.