You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-7Lines changed: 60 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,12 @@ This is the result of a simple strategy using RSI with a period 14 on the BTCUSD
101
101
102
102
We then loop through each strategy in each file and in each period, and we get in return additional details for each strategy such as the **portofolio final amount**, the **total number of wins and losses**, the **net profit and loss** and finally the **SQN value** which is an indicator designed to assist traders in determining the global quality of a trading system.
103
103
104
+
For that we call the ```runbacktest``` function imported from **backtest.py**.
For example for this strategy ([SMA-BTCUSDT-20170101-20201231-1h.csv](result/SMA-BTCUSDT-20170101-20201231-1h.csv)) using SMA on the 1 hour dataframe BTCUSDT pair from 2017 to 2020, we can notice that the lower the SMA period is the lower our sqn and profit will be (in that case even negative), and conversely when the SMA period is higher our profit is better.
123
+
For example for this strategy ([SMA-BTCUSDT-20170101-20201231-1h.csv](result/SMA-BTCUSDT-20170101-20201231-1h.csv)) using SMA on the 1 hour timeframe BTCUSDT pair from 2017 to 2020, we can notice that the lower the SMA period is the lower our sqn and profit will be (in that case even negative), and conversely when the SMA period is higher our profit is better.
118
124
119
125
120
126
## Backtest <aname="backtest"></a>
121
127
122
-
The [backtest.py](backtest.py) code was mostly based on the [Backtrader Quickstart Guide](https://www.backtrader.com/docu/quickstart/quickstart/). However, some modifications were applied and functions added to respond our needs so until this section is filled with more details know that :
128
+
The [backtest.py](backtest.py) code was mostly based on the [Backtrader Quickstart Guide](https://www.backtrader.com/docu/quickstart/quickstart/). However, some modifications were applied and functionalities added to respond our needs.
129
+
130
+
**Two strategies were implemented :**
123
131
124
-
**Two strategies are implemented :**
132
+
* Using SMA :
125
133
126
134
```python
127
135
classSMAStrategy(bt.Strategy):
136
+
params = (
137
+
('maperiod', None),
138
+
('quantity', None)
139
+
)
128
140
```
129
141
130
-
* SMA strategy based on the SMA indicator. If we are not already in a position and the closure price of the last candlestick is higher than the indicator (that mean we cross the sma from bellow to top), then we buy a size equivalent to 10% of the current portofolio amount.
142
+
This strategy is based on the SMA indicator. If we are not already in a position and the closure price of the last candlestick is higher than the indicator (i.e. we cross the sma from bellow to top), then we buy a size equivalent to 10% of the current portofolio amount. We sell when the opposite happen.
# Keep track of the created order to avoid a 2nd order
158
+
self.order =self.sell(size=self.amount)
159
+
```
160
+
161
+
* Using RSI :
162
+
163
+
```python
164
+
classRSIStrategy(bt.Strategy):
165
+
params = (
166
+
('maperiod', None),
167
+
('quantity', None)
168
+
)
169
+
```
144
170
171
+
Based on the RSI indicator, if we are not already in a position and the rsi go below 30 then we buy a size equivalent to 10% of the current portofolio amount that we will sell when rsi > 70.
172
+
173
+
```python
174
+
# Check if we are in the market
175
+
ifnotself.position:
176
+
# Not yet ... we MIGHT BUY if ...
177
+
ifself.rsi <30:
178
+
# Keep track of the created order to avoid a 2nd order
Depending on the parameter given in the ```runbacktest``` function we will add one of the two strategy we have written and give it the period we want to use and quantity in % of our portofolio that we want to use.
0 commit comments