From cb6d682dd8db18c083f44dfd1050f7f93cdcbf19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=A1k?= Date: Sun, 10 Jan 2021 23:39:38 +0100 Subject: [PATCH] experimental ema reduction (-negative reduce) --- src/main/strategy_leveraged_base.tcc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/strategy_leveraged_base.tcc b/src/main/strategy_leveraged_base.tcc index d2d41918..6983aa2a 100644 --- a/src/main/strategy_leveraged_base.tcc +++ b/src/main/strategy_leveraged_base.tcc @@ -92,7 +92,7 @@ double Strategy_Leveraged::calcPosition(double price) const { } } - double reduction = 2*cfg->reduction; + double reduction = cfg->reduction>=0?2*cfg->reduction:0; double dynred = 0; if (cfg->dynred) { double val = st.redbal+cfg->external_balance; @@ -120,6 +120,9 @@ double Strategy_Leveraged::calcPosition(double price) const { new_neutral = st.neutral_price; } } + + + double pos = calc->calcPosition(st.power, calcAsym(), new_neutral, price); if (cfg->longonly && pos < 0) pos = 0; double pp = pos * st.position ; @@ -224,7 +227,17 @@ std::pair::OnTradeResult, PStrategy> Strategy_ nwst.last_price = tradePrice; nwst.last_dir = sgn(tradeSize); - recalcNeutral(calc, cfg, nwst); + if (cfg->reduction >= 0) { + recalcNeutral(calc, cfg, nwst); + } else { + if (cpos == 0) { + nwst.neutral_price = tradePrice; + } + else { + double ema = -cfg->reduction*200; + nwst.neutral_price = std::exp((std::log(nwst.neutral_price) * (ema-1) + std::log(tradePrice))/ema); + } + } double val = calc->calcPosValue(mult, calcAsym(), nwst.neutral_price, tradePrice); //calculate extra profit - we get change of value and add profit. This shows how effective is strategy. If extra is positive, it generates