From 2acc81cd7521912049005a18f04f3bc9452a1670 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Fri, 12 Feb 2021 14:57:23 +0000 Subject: [PATCH] remodeled percentage calculation in strategy --- rustybot/src/strategy.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/rustybot/src/strategy.rs b/rustybot/src/strategy.rs index df9a34a..90aabef 100644 --- a/rustybot/src/strategy.rs +++ b/rustybot/src/strategy.rs @@ -4,8 +4,10 @@ use std::fmt::{Debug, Formatter}; use dyn_clone::DynClone; use log::info; +use crate::connectors::Connector; use crate::events::{Event, EventKind, EventMetadata, Message}; use crate::managers::OptionUpdate; +use crate::models::OrderBookEntry::Trading; use crate::models::{ ActiveOrder, OrderBook, OrderBookEntry, OrderForm, OrderKind, Position, PositionProfitState, PositionState, TradingPlatform, @@ -74,10 +76,22 @@ pub struct TrailingStop { } impl TrailingStop { - const BREAK_EVEN_PERC: f64 = 0.1; - const MIN_PROFIT_PERC: f64 = 0.5; - const GOOD_PROFIT_PERC: f64 = TrailingStop::MIN_PROFIT_PERC * 1.75; - const MAX_LOSS_PERC: f64 = -4.0; + // in percentage + const CAPITAL_MAX_LOSS: f64 = 17.5; + const CAPITAL_MIN_PROFIT: f64 = 10.0; + const CAPITAL_GOOD_PROFIT: f64 = 20.0; + + // in percentage + const MIN_PROFIT_TRAILING_DELTA: f64 = 0.2; + const GOOD_PROFIT_TRAILING_DELTA: f64 = 0.1; + + const LEVERAGE: f64 = 15.0; + + const MIN_PROFIT_PERC: f64 = (TrailingStop::CAPITAL_MIN_PROFIT / TrailingStop::LEVERAGE) + + TrailingStop::MIN_PROFIT_TRAILING_DELTA; + const GOOD_PROFIT_PERC: f64 = (TrailingStop::CAPITAL_GOOD_PROFIT / TrailingStop::LEVERAGE) + + TrailingStop::GOOD_PROFIT_TRAILING_DELTA; + const MAX_LOSS_PERC: f64 = -(TrailingStop::CAPITAL_MAX_LOSS / TrailingStop::LEVERAGE); pub fn new() -> Self { TrailingStop { @@ -88,8 +102,8 @@ impl TrailingStop { fn update_stop_percentage(&mut self, position: &Position) { if let Some(profit_state) = position.profit_state() { let profit_state_delta = match profit_state { - PositionProfitState::MinimumProfit => Some(0.2), - PositionProfitState::Profit => Some(0.1), + PositionProfitState::MinimumProfit => Some(TrailingStop::MIN_PROFIT_TRAILING_DELTA), + PositionProfitState::Profit => Some(TrailingStop::GOOD_PROFIT_TRAILING_DELTA), _ => None, }; @@ -252,7 +266,7 @@ pub struct FastOrderStrategy { impl Default for FastOrderStrategy { fn default() -> Self { - Self { threshold: 0.2 } + Self { threshold: 0.15 } } }