remodeled percentage calculation in strategy
This commit is contained in:
parent
6c409ac9fd
commit
2acc81cd75
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user