-
Notifications
You must be signed in to change notification settings - Fork 4
/
SPXicMonitor.py
57 lines (50 loc) · 2.36 KB
/
SPXicMonitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#region imports
from AlgorithmImports import *
#endregion
from .Base import Base
from CustomIndicators import ATRLevels
from Tools import Underlying
from Strategy import WorkingOrder
class SPXicMonitor(Base):
DEFAULT_PARAMETERS = {
# The frequency (in minutes) with which each position is managed
"managePositionFrequency": 1,
# Profit Target Factor (Multiplier of the premium received/paid when the position was opened)
"profitTarget": 1.5,
# Stop Loss Multiplier, expressed as a function of the profit target (rather than the credit received)
# The position is closed (Market Order) if:
# Position P&L < -abs(openPremium) * stopLossMultiplier
# where:
# - openPremium is the premium received (positive) in case of credit strategies
# - openPremium is the premium paid (negative) in case of debit strategies
#
# Credit Strategies (i.e. $2 credit):
# - profitTarget < 1 (i.e. 0.5 -> 50% profit target -> $1 profit)
# - stopLossMultiplier = 2 * profitTarget (i.e. -abs(openPremium) * stopLossMultiplier = -abs(2) * 2 * 0.5 = -2 --> stop if P&L < -2$)
# Debit Strategies (i.e. $4 debit):
# - profitTarget < 1 (i.e. 0.5 -> 50% profit target -> $2 profit)
# - stopLossMultiplier < 1 (You can't lose more than the debit paid. i.e. stopLossMultiplier = 0.6 --> stop if P&L < -2.4$)
# self.stopLossMultiplier = 3 * self.profitTarget
# self.stopLossMultiplier = 0.6
"stopLossMultiplier": 1.2,
# Ensures that the Stop Loss does not exceed the theoretical loss. (Set to False for Credit Calendars)
"capStopLoss": True,
}
def __init__(self, context):
# Call the Base class __init__ method
super().__init__(context, 'SPXic')
self.fiveMinuteITM = {}
self.HODLOD = {}
self.triggerHODLOD = {}
# The dictionary of consolidators
self.consolidators = dict()
# self.ATRLevels = ATRLevels("ATRLevels", length = 14)
# EMAs for the 8, 21 and 34 periods
self.EMAs = {8: {}, 21: {}, 34: {}}
# self.stdDevs = {}
# Add a dictionary to keep track of whether the position reached 50% profit
self.reachedHalfProfit = {}
def monitorPosition(self, position):
pass
def shouldClose(self, position):
return False, None