overfitting 0.3.1__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of overfitting might be problematic. Click here for more details.

Files changed (30) hide show
  1. {overfitting-0.3.1 → overfitting-0.3.2}/PKG-INFO +13 -16
  2. {overfitting-0.3.1 → overfitting-0.3.2}/README.md +12 -15
  3. overfitting-0.3.2/overfitting/__init__.py +3 -0
  4. {overfitting-0.3.1/overfitting/visualization → overfitting-0.3.2/overfitting/analysis}/report.py +1 -1
  5. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting/broker.py +3 -3
  6. {overfitting-0.3.1/overfitting/data → overfitting-0.3.2/overfitting}/data.py +35 -2
  7. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting/order.py +1 -2
  8. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting/strategy.py +2 -2
  9. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting.egg-info/PKG-INFO +13 -16
  10. overfitting-0.3.2/overfitting.egg-info/SOURCES.txt +22 -0
  11. {overfitting-0.3.1 → overfitting-0.3.2}/pyproject.toml +1 -1
  12. overfitting-0.3.1/overfitting/__init__.py +0 -3
  13. overfitting-0.3.1/overfitting/data/__init__.py +0 -4
  14. overfitting-0.3.1/overfitting/data/multi_currency.py +0 -38
  15. overfitting-0.3.1/overfitting/execution/__init__.py +0 -0
  16. overfitting-0.3.1/overfitting/visualization/__init__.py +0 -0
  17. overfitting-0.3.1/overfitting.egg-info/SOURCES.txt +0 -26
  18. {overfitting-0.3.1 → overfitting-0.3.2}/LICENSE +0 -0
  19. {overfitting-0.3.1/overfitting/entities → overfitting-0.3.2/overfitting/analysis}/__init__.py +0 -0
  20. {overfitting-0.3.1/overfitting/visualization → overfitting-0.3.2/overfitting/analysis}/graph.py +0 -0
  21. {overfitting-0.3.1/overfitting/visualization → overfitting-0.3.2/overfitting/analysis}/viewer.py +0 -0
  22. /overfitting-0.3.1/overfitting/error.py → /overfitting-0.3.2/overfitting/errors.py +0 -0
  23. /overfitting-0.3.1/overfitting/indicator.py → /overfitting-0.3.2/overfitting/indicators.py +0 -0
  24. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting/position.py +0 -0
  25. {overfitting-0.3.1/overfitting/execution → overfitting-0.3.2/overfitting}/slippage.py +0 -0
  26. /overfitting-0.3.1/overfitting/entities/order.py → /overfitting-0.3.2/overfitting/types.py +0 -0
  27. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting.egg-info/dependency_links.txt +0 -0
  28. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting.egg-info/requires.txt +0 -0
  29. {overfitting-0.3.1 → overfitting-0.3.2}/overfitting.egg-info/top_level.txt +0 -0
  30. {overfitting-0.3.1 → overfitting-0.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: overfitting
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: A Robust Futures CryptoCurrency Backtesting Library.
5
5
  Author-email: Dohyun Kim <dohyun.k.july@gmail.com>
6
6
  License: MIT
@@ -59,41 +59,38 @@ def load_data():
59
59
 
60
60
  start_time = pd.to_datetime('2023-01-01 00:00:00')
61
61
  df = df.loc[start_time:]
62
- # Compute short and long SMAs
63
- df['sma_short'] = df['close'].rolling(window=20).mean().shift(1)
64
- df['sma_long'] = df['close'].rolling(window=50).mean().shift(1)
65
62
 
66
63
  return df, benchamrk_df
67
-
64
+
68
65
  class MyStrategy(Strategy):
69
66
  def init(self):
70
67
  self.asset = 'BTC'
71
68
  self.set_leverage(self.asset, 1)
72
69
 
70
+ self.sma_short = SMA(self, self.asset, source="close", window=20)
71
+ self.sma_long = SMA(self, self.asset, source="close", window=50)
72
+
73
73
  def next(self, i):
74
74
  if i == 0:
75
75
  return
76
76
 
77
- sma_short = self.val(self.asset, i, "sma_short")
78
- sma_long = self.val(self.asset, i, "sma_long")
79
- previous_sma_short = self.val(self.asset, i - 1, "sma_short")
80
- previous_sma_long = self.val(self.asset, i - 1, "sma_long")
77
+ sma_short = self.sma_short[i]
78
+ sma_long = self.sma_long[i]
79
+ previous_sma_short = self.sma_short[i - 1]
80
+ previous_sma_long = self.sma_long[i - 1]
81
81
 
82
- # Also skip if values are not available
83
- if (pd.isna(sma_short) or pd.isna(sma_long) or
84
- pd.isna(previous_sma_short) or pd.isna(previous_sma_long)):
82
+ if (
83
+ pd.isna(sma_short) or pd.isna(sma_long) or
84
+ pd.isna(previous_sma_short) or pd.isna(previous_sma_long)
85
+ ):
85
86
  return
86
87
 
87
- # Fetch the current position
88
88
  position = self.get_position(self.asset)
89
89
 
90
90
  # Golden cross (entry)
91
91
  if previous_sma_short <= previous_sma_long and sma_short > sma_long and position.qty == 0:
92
- # First fetch current open price which is the target Price
93
92
  open_price = self.open(self.asset, i)
94
- # Determine Lot Size
95
93
  lot_size = self.get_balance() // open_price
96
- # Create LIMIT ORDER
97
94
  self.limit_order(self.asset, lot_size, open_price)
98
95
 
99
96
  # Death cross (exit)
@@ -24,41 +24,38 @@ def load_data():
24
24
 
25
25
  start_time = pd.to_datetime('2023-01-01 00:00:00')
26
26
  df = df.loc[start_time:]
27
- # Compute short and long SMAs
28
- df['sma_short'] = df['close'].rolling(window=20).mean().shift(1)
29
- df['sma_long'] = df['close'].rolling(window=50).mean().shift(1)
30
27
 
31
28
  return df, benchamrk_df
32
-
29
+
33
30
  class MyStrategy(Strategy):
34
31
  def init(self):
35
32
  self.asset = 'BTC'
36
33
  self.set_leverage(self.asset, 1)
37
34
 
35
+ self.sma_short = SMA(self, self.asset, source="close", window=20)
36
+ self.sma_long = SMA(self, self.asset, source="close", window=50)
37
+
38
38
  def next(self, i):
39
39
  if i == 0:
40
40
  return
41
41
 
42
- sma_short = self.val(self.asset, i, "sma_short")
43
- sma_long = self.val(self.asset, i, "sma_long")
44
- previous_sma_short = self.val(self.asset, i - 1, "sma_short")
45
- previous_sma_long = self.val(self.asset, i - 1, "sma_long")
42
+ sma_short = self.sma_short[i]
43
+ sma_long = self.sma_long[i]
44
+ previous_sma_short = self.sma_short[i - 1]
45
+ previous_sma_long = self.sma_long[i - 1]
46
46
 
47
- # Also skip if values are not available
48
- if (pd.isna(sma_short) or pd.isna(sma_long) or
49
- pd.isna(previous_sma_short) or pd.isna(previous_sma_long)):
47
+ if (
48
+ pd.isna(sma_short) or pd.isna(sma_long) or
49
+ pd.isna(previous_sma_short) or pd.isna(previous_sma_long)
50
+ ):
50
51
  return
51
52
 
52
- # Fetch the current position
53
53
  position = self.get_position(self.asset)
54
54
 
55
55
  # Golden cross (entry)
56
56
  if previous_sma_short <= previous_sma_long and sma_short > sma_long and position.qty == 0:
57
- # First fetch current open price which is the target Price
58
57
  open_price = self.open(self.asset, i)
59
- # Determine Lot Size
60
58
  lot_size = self.get_balance() // open_price
61
- # Create LIMIT ORDER
62
59
  self.limit_order(self.asset, lot_size, open_price)
63
60
 
64
61
  # Death cross (exit)
@@ -0,0 +1,3 @@
1
+ from .strategy import Strategy
2
+ from .slippage import Slippage
3
+ from .analysis.viewer import BacktestViewer
@@ -2,7 +2,7 @@ import pandas as pd
2
2
  import numpy as np
3
3
  import matplotlib.pyplot as plt
4
4
  import seaborn as sns
5
- import overfitting.visualization.graph as graph
5
+ import overfitting.analysis.graph as graph
6
6
  from overfitting.order import Order
7
7
  from typing import Optional, Sequence
8
8
  from matplotlib.colors import LinearSegmentedColormap
@@ -3,9 +3,9 @@ from typing import List, Dict, Optional, Union, Tuple
3
3
  from overfitting.data import Data, MultiCurrency
4
4
  from overfitting.order import Order
5
5
  from overfitting.position import Position
6
- from overfitting.execution.slippage import SlippageModel
7
- from overfitting.entities.order import OrderType
8
- from overfitting.error import EmptyOrderParameters, InvalidOrderParameters, LiquidationError
6
+ from overfitting.slippage import SlippageModel
7
+ from overfitting.types import OrderType
8
+ from overfitting.errors import EmptyOrderParameters, InvalidOrderParameters, LiquidationError
9
9
 
10
10
  class Broker:
11
11
  def __init__(self,
@@ -1,7 +1,7 @@
1
1
  import pandas as pd
2
2
  import numpy as np
3
3
  from pandas.api.types import is_datetime64_any_dtype, is_integer_dtype, is_float_dtype
4
- from overfitting.error import InitializationError
4
+ from overfitting.errors import InitializationError
5
5
 
6
6
  REQUIRED_OHLC = ("open", "high", "low", "close")
7
7
 
@@ -84,4 +84,37 @@ class Data(dict):
84
84
  if key in {"index", "columns", "n"}:
85
85
  object.__setattr__(self, key, value)
86
86
  else:
87
- raise AttributeError("Data is read-only; modify the source DataFrame before wrapping.")
87
+ raise AttributeError("Data is read-only; modify the source DataFrame before wrapping.")
88
+
89
+ class MultiCurrency(dict):
90
+
91
+ symbols: tuple[str, ...] # List of symbols in this container
92
+ index: np.ndarray # datetime64[ns] index
93
+ n: int # Number of rows per symbol
94
+
95
+ def __init__(self, frames: dict[str, pd.DataFrame]):
96
+ if not isinstance(frames, dict) or not frames:
97
+ raise InitializationError("Data must be non-empty dict Type - dict[str, pd.DataFrame]")
98
+
99
+ payload = {}
100
+ first_ts = None
101
+ for symbol, df in frames.items():
102
+ d = Data(df)
103
+ if first_ts is None:
104
+ first_ts = d.index
105
+ else:
106
+ # Requires identical timestamps for NOW
107
+ # TODO IMNPLEMENT AUTO FILL for uniform timestamps
108
+ if len(d.index) != len(first_ts) or not np.array_equal(d.index, first_ts):
109
+ raise InitializationError(
110
+ f"Len Timestamps for {symbol} are not equal with the other symbols.")
111
+
112
+ payload[symbol] = d
113
+
114
+ super().__init__(payload)
115
+ object.__setattr__(self, "symbols", tuple(payload.keys()))
116
+ object.__setattr__(self, "index", first_ts)
117
+ object.__setattr__(self, "n", len(first_ts))
118
+
119
+ def __len__(self) -> int:
120
+ return self.n
@@ -1,7 +1,6 @@
1
1
  import uuid
2
2
  import pandas as pd
3
- from overfitting.entities.order import OrderType, Status
4
- from enum import Enum
3
+ from overfitting.types import OrderType, Status
5
4
 
6
5
  class Order:
7
6
  def __init__(self,
@@ -7,8 +7,8 @@ from overfitting.data import Data, MultiCurrency
7
7
  from overfitting.broker import Broker
8
8
  from overfitting.order import Order
9
9
  from overfitting.position import Position
10
- from overfitting.visualization.report import Report
11
- from overfitting.execution.slippage import SlippageModel
10
+ from overfitting.analysis.report import Report
11
+ from overfitting.slippage import SlippageModel
12
12
 
13
13
  class Strategy:
14
14
  def __init__(self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: overfitting
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: A Robust Futures CryptoCurrency Backtesting Library.
5
5
  Author-email: Dohyun Kim <dohyun.k.july@gmail.com>
6
6
  License: MIT
@@ -59,41 +59,38 @@ def load_data():
59
59
 
60
60
  start_time = pd.to_datetime('2023-01-01 00:00:00')
61
61
  df = df.loc[start_time:]
62
- # Compute short and long SMAs
63
- df['sma_short'] = df['close'].rolling(window=20).mean().shift(1)
64
- df['sma_long'] = df['close'].rolling(window=50).mean().shift(1)
65
62
 
66
63
  return df, benchamrk_df
67
-
64
+
68
65
  class MyStrategy(Strategy):
69
66
  def init(self):
70
67
  self.asset = 'BTC'
71
68
  self.set_leverage(self.asset, 1)
72
69
 
70
+ self.sma_short = SMA(self, self.asset, source="close", window=20)
71
+ self.sma_long = SMA(self, self.asset, source="close", window=50)
72
+
73
73
  def next(self, i):
74
74
  if i == 0:
75
75
  return
76
76
 
77
- sma_short = self.val(self.asset, i, "sma_short")
78
- sma_long = self.val(self.asset, i, "sma_long")
79
- previous_sma_short = self.val(self.asset, i - 1, "sma_short")
80
- previous_sma_long = self.val(self.asset, i - 1, "sma_long")
77
+ sma_short = self.sma_short[i]
78
+ sma_long = self.sma_long[i]
79
+ previous_sma_short = self.sma_short[i - 1]
80
+ previous_sma_long = self.sma_long[i - 1]
81
81
 
82
- # Also skip if values are not available
83
- if (pd.isna(sma_short) or pd.isna(sma_long) or
84
- pd.isna(previous_sma_short) or pd.isna(previous_sma_long)):
82
+ if (
83
+ pd.isna(sma_short) or pd.isna(sma_long) or
84
+ pd.isna(previous_sma_short) or pd.isna(previous_sma_long)
85
+ ):
85
86
  return
86
87
 
87
- # Fetch the current position
88
88
  position = self.get_position(self.asset)
89
89
 
90
90
  # Golden cross (entry)
91
91
  if previous_sma_short <= previous_sma_long and sma_short > sma_long and position.qty == 0:
92
- # First fetch current open price which is the target Price
93
92
  open_price = self.open(self.asset, i)
94
- # Determine Lot Size
95
93
  lot_size = self.get_balance() // open_price
96
- # Create LIMIT ORDER
97
94
  self.limit_order(self.asset, lot_size, open_price)
98
95
 
99
96
  # Death cross (exit)
@@ -0,0 +1,22 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ overfitting/__init__.py
5
+ overfitting/broker.py
6
+ overfitting/data.py
7
+ overfitting/errors.py
8
+ overfitting/indicators.py
9
+ overfitting/order.py
10
+ overfitting/position.py
11
+ overfitting/slippage.py
12
+ overfitting/strategy.py
13
+ overfitting/types.py
14
+ overfitting.egg-info/PKG-INFO
15
+ overfitting.egg-info/SOURCES.txt
16
+ overfitting.egg-info/dependency_links.txt
17
+ overfitting.egg-info/requires.txt
18
+ overfitting.egg-info/top_level.txt
19
+ overfitting/analysis/__init__.py
20
+ overfitting/analysis/graph.py
21
+ overfitting/analysis/report.py
22
+ overfitting/analysis/viewer.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "overfitting"
7
- version = "0.3.1"
7
+ version = "0.3.2"
8
8
  description = "A Robust Futures CryptoCurrency Backtesting Library."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -1,3 +0,0 @@
1
- from .strategy import Strategy
2
- from .execution.slippage import Slippage
3
- from .visualization.viewer import BacktestViewer
@@ -1,4 +0,0 @@
1
- from .data import Data
2
- from .multi_currency import MultiCurrency
3
-
4
- __all__ = ["Data", "MultiCurrency"]
@@ -1,38 +0,0 @@
1
- import pandas as pd
2
- import numpy as np
3
- from pandas.api.types import is_datetime64_any_dtype, is_integer_dtype, is_float_dtype
4
- from overfitting.error import InitializationError
5
- from overfitting.data import Data
6
-
7
- class MultiCurrency(dict):
8
-
9
- symbols: tuple[str, ...] # List of symbols in this container
10
- index: np.ndarray # datetime64[ns] index
11
- n: int # Number of rows per symbol
12
-
13
- def __init__(self, frames: dict[str, pd.DataFrame]):
14
- if not isinstance(frames, dict) or not frames:
15
- raise InitializationError("Data must be non-empty dict Type - dict[str, pd.DataFrame]")
16
-
17
- payload = {}
18
- first_ts = None
19
- for symbol, df in frames.items():
20
- d = Data(df)
21
- if first_ts is None:
22
- first_ts = d.index
23
- else:
24
- # Requires identical timestamps for NOW
25
- # TODO IMNPLEMENT AUTO FILL for uniform timestamps
26
- if len(d.index) != len(first_ts) or not np.array_equal(d.index, first_ts):
27
- raise InitializationError(
28
- f"Len Timestamps for {symbol} are not equal with the other symbols.")
29
-
30
- payload[symbol] = d
31
-
32
- super().__init__(payload)
33
- object.__setattr__(self, "symbols", tuple(payload.keys()))
34
- object.__setattr__(self, "index", first_ts)
35
- object.__setattr__(self, "n", len(first_ts))
36
-
37
- def __len__(self) -> int:
38
- return self.n
File without changes
File without changes
@@ -1,26 +0,0 @@
1
- LICENSE
2
- README.md
3
- pyproject.toml
4
- overfitting/__init__.py
5
- overfitting/broker.py
6
- overfitting/error.py
7
- overfitting/indicator.py
8
- overfitting/order.py
9
- overfitting/position.py
10
- overfitting/strategy.py
11
- overfitting.egg-info/PKG-INFO
12
- overfitting.egg-info/SOURCES.txt
13
- overfitting.egg-info/dependency_links.txt
14
- overfitting.egg-info/requires.txt
15
- overfitting.egg-info/top_level.txt
16
- overfitting/data/__init__.py
17
- overfitting/data/data.py
18
- overfitting/data/multi_currency.py
19
- overfitting/entities/__init__.py
20
- overfitting/entities/order.py
21
- overfitting/execution/__init__.py
22
- overfitting/execution/slippage.py
23
- overfitting/visualization/__init__.py
24
- overfitting/visualization/graph.py
25
- overfitting/visualization/report.py
26
- overfitting/visualization/viewer.py
File without changes
File without changes