Skip to content

Commit 00e3ed5

Browse files
Add more detailed description to README.md file. Delist variables in config.py, which should be strings.
1 parent a35e472 commit 00e3ed5

File tree

2 files changed

+62
-23
lines changed

2 files changed

+62
-23
lines changed

README.md

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
# BacktestBay: Evaluation of Trading Strategies
22

33
BacktestBay is a Python-based framework for backtesting trading strategies. It leverages
4-
`yfinance` for importing financial data.
4+
[yfinance](https://pypi.org/project/yfinance/) for importing financial data.
55

66
## Configuration
77

88
BacktestBay enables the configuration of input parameters through
99
[config.py](https://github.com/iame-uni-bonn/final-project-niklasniedermeier-1/blob/main/src/backtest_bay/config.py).
1010

11-
This configuration file allows for the customization of data source settings
11+
First, the data source is specified in more detail in the configuration file:
1212

1313
```python
14-
STOCKS = ["AAPL", "MSFT"] # List of stock symbols from yfinance
15-
START_DATES = ["2019-01-01"] # Start date for historical data ("YYYY-MM_DD")
16-
END_DATES = ["2025-01-01"] # End date for historical data ("YYYY-MM_DD")
17-
INTERVALS = ["1d"] # Data frequency (e.g., daily)
14+
STOCKS = ["AAPL", "MSFT"]
15+
START_DATES = "2019-01-01"
16+
END_DATES = "2025-01-01"
17+
INTERVALS = "1d"
1818
```
1919

20-
and the choice of trading strategies
20+
Multiple valid symbols from [yfinance](https://pypi.org/project/yfinance/) can be added
21+
to the `STOCKS` list. `START_DATES` and `END_DATES` define the time range for the price
22+
history of the selected `STOCKS` at a specified `INTERVAL`. The available options for
23+
`INTERVAL` are listed at the end of the README file.
2124

22-
```python
23-
STRATEGIES = ["bollinger", "macd", "roc", "rsi"]
24-
```
25-
26-
as well as the adjustment of trading parameters
25+
In the next step, multiple trading strategies can be added to the `STRATEGIES` list:
2726

2827
```python
29-
INITIAL_CASH = 1000000 # Initial capital for trading
30-
TAC = 0.005 # Transaction cost
31-
TRADE_PCT = 0.05 # Percentage of current portfolio used per trade
28+
STRATEGIES = ["bollinger", "macd", "roc", "rsi"]
3229
```
3330

34-
providing users with enhanced control and flexibility in their backtesting process.
35-
36-
The following trading strategies are currently implemented
31+
Each trading strategy is backtested on the stocks specified in the `STOCKS` list. The
32+
following trading strategies are currently implemented:
3733

3834
- 'bollinger':
3935
[Bollinger Bands](https://www.investopedia.com/terms/b/bollingerbands.asp)
@@ -42,12 +38,25 @@ The following trading strategies are currently implemented
4238
- 'roc': [Rate of Change](https://www.investopedia.com/terms/p/pricerateofchange.asp)
4339
- 'rsi': [Relative Strength Index](https://www.investopedia.com/terms/r/rsi.asp)
4440

41+
Finally, additional backtesting parameters can be specified
42+
43+
```python
44+
INITIAL_CASH = 1000000
45+
TAC = 0.005
46+
TRADE_PCT = 0.05
47+
```
48+
49+
providing users with greater control and flexibility in their backtesting process.
50+
`INITIAL_CASH` specifies the amount of cash available at the start. `TAC` specifies the
51+
transaction costs as a percentage of the traded volume.. `TRADE_PCT` indicates the
52+
percentage of the current portfolio allocated for trading.
53+
4554
## Getting Started
4655

4756
To get started, first clone the repository using the following command:
4857

4958
```bash
50-
git clone <repository-url>
59+
git clone repository-url
5160
```
5261

5362
Next, create and activate the environment by navigating to the directory containing
@@ -64,3 +73,31 @@ project directory:
6473
```bash
6574
pytask
6675
```
76+
77+
## yfinance Download Intervals and Maximum History
78+
79+
| INTERVAL | Description | Maximum History Available |
80+
| -------- | ----------- | ----------------------------------- |
81+
| `1m` | 1 minute | **7 days** |
82+
| `2m` | 2 minutes | **60 days** |
83+
| `5m` | 5 minutes | **60 days** |
84+
| `15m` | 15 minutes | **60 days** |
85+
| `30m` | 30 minutes | **60 days** |
86+
| `60m` | 60 minutes | **730 days (2 years)** |
87+
| `90m` | 90 minutes | **730 days (2 years)** |
88+
| `1h` | 1 hour | **730 days (2 years)** |
89+
| `1d` | 1 day | **Max available (up to 50+ years)** |
90+
| `5d` | 5 days | **Max available (up to 50+ years)** |
91+
| `1wk` | 1 week | **Max available (up to 50+ years)** |
92+
| `1mo` | 1 month | **Max available (up to 50+ years)** |
93+
| `3mo` | 3 months | **Max available (up to 50+ years)** |
94+
95+
### Notes:
96+
97+
- Intraday data (`< 1d`) is typically only available for the last **60 days**, except
98+
for `1m`, which is limited to the last **7 days**.
99+
- Daily, weekly, and monthly data can be downloaded for the maximum history available,
100+
which may go back **50+ years** depending on the stock.
101+
- For intervals `60m`, `90m`, and `1h`, data is available for up to **2 years**.
102+
- These limitations are set by Yahoo Finance, and attempting to request more data than
103+
allowed will result in an error or incomplete data.

src/backtest_bay/config.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
# Data source
1414
STOCKS = ["AAPL", "MSFT"]
15-
START_DATES = ["2019-01-01"]
16-
END_DATES = ["2025-01-01"]
17-
INTERVALS = ["1d"]
15+
START_DATES = "2019-01-01"
16+
END_DATES = "2025-01-01"
17+
INTERVALS = "1d"
1818

1919
# Trading strategies
2020
STRATEGIES = ["bollinger", "macd", "roc", "rsi"]
@@ -26,6 +26,8 @@
2626

2727
# Define PARAMS using input data
2828
PARAMS = pd.DataFrame(
29-
list(itertools.product(STOCKS, START_DATES, END_DATES, INTERVALS, STRATEGIES)),
29+
list(
30+
itertools.product(STOCKS, [START_DATES], [END_DATES], [INTERVALS], STRATEGIES)
31+
),
3032
columns=["stock", "start_date", "end_date", "interval", "strategy"],
3133
)

0 commit comments

Comments
 (0)