-
Notifications
You must be signed in to change notification settings - Fork 52
/
init_operations.py
64 lines (51 loc) · 2.74 KB
/
init_operations.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
58
59
60
61
62
63
64
#!/usr/local/bin/env python3.7
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
#
# The MIT License (MIT)
# Copyright (c) 2020 Philippe Ostiguy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
###############################################################################
"""Module to easily reinitiliaze values when needed """
from initialize import Initialize
from manip_data import ManipData as md
import pandas as pd
import matplotlib.pyplot as plt
class InitOp(Initialize):
def __init__(self):
super().__init__()
super().__call__()
def __call__(self):
self.reset_value()
def reset_value(self):
"""Function to reset the dictionary that contains the trading journal (entry, exit, return) in
`self.trades_track`
We need to do that when we optimize, ie when `self.is_walkfoward` is `True`
"""
self.trades_track = pd.DataFrame(columns=[self.entry_row, self.entry_level, self.exit_row, self.exit_level, \
self.trade_return])
def init_series(self):
"""Function that extract the data from csv to a pandas Dataframe `self.series`
It actually is the data that we are using for the strategy """
self.series = md.csv_to_pandas(self.date_name, self.start_date, self.end_date, self.name, self.directory,
self.asset, ordinal_name=self.date_ordinal_name, is_fx=self.is_fx, dup_col = self.dup_col)
if self.is_detrend:
self.series_diff = md.de_trend(self.series,self.date_name, self.date_ordinal_name,self.default_data,
period=self.period,p_value= self.p_value)