Skip to content

Commit

Permalink
Final README updates for new version
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGoldfarb authored and Daniel Goldfarb committed Feb 12, 2020
1 parent ff4de2e commit f7e7d85
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 4,054 deletions.
97 changes: 62 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ The conventional way to import the new API is as follows:
```python
import mplfinance as mpf
```
The most common usage is then to call

The most common usage is then to call

```python
mpf.plot(data)
Expand All @@ -53,6 +53,7 @@ I am very interested to hear from you regarding what you think of the new `mplfi
# <a name="usage"></a>Basic Usage
Start with a Pandas DataFrame containing OHLC data. For example,


```python
import pandas as pd
daily = pd.read_csv('examples/data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True)
Expand All @@ -61,6 +62,7 @@ daily.shape
daily.head(3)
daily.tail(3)
```

(20, 5)

<table border="1" class="dataframe">
Expand Down Expand Up @@ -159,20 +161,21 @@ daily.tail(3)
</tbody>
</table>

<br>

---

<br>

After importing mplfinance, plotting OHLC data is as simple as calling `mpf.plot()` on the dataframe


```python
import mplfinance as mpf
mpf.plot(daily)
```

![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_4_0.png)

![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_4_1.png)


---
<br>
Expand All @@ -184,14 +187,18 @@ The default plot type, as you can see above, is `'ohlc'`. Other plot types can
mpf.plot(daily,type='candle')
```

![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_6_0.png)

![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_6_1.png)



```python
mpf.plot(daily,type='line')
```

![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_7_0.png)

![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_7_1.png)


---
<br>
Expand All @@ -205,14 +212,18 @@ We can also plot moving averages with the `mav` keyword
mpf.plot(daily,type='ohlc',mav=4)
```

![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_9_0.png)

![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_9_1.png)



```python
mpf.plot(daily,type='candle',mav=(3,6,9))
```

![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_10_0.png)

![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_10_1.png)


---
We can also display `Volume`
Expand All @@ -223,20 +234,23 @@ mpf.plot(daily,type='candle',mav=(3,6,9),volume=True)
```


![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_12_0.png)
![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_12_1.png)


Notice, in the above chart, there are gaps along the x-coordinate corresponding to days on which there was no trading.
- Many people like to see these gaps so that they can tell, with a quick glance, where the weekends and holidays fall.
- For example, in the above chart you can see a gap at Thursday, November 28th for the U.S. Thanksgiving holiday.
- Gaps along the x-axis can be eliminated with the `no_xgaps` keyword
Notice, in the above chart, there are no gaps along the x-coordinate, even though there are days on which there was no trading. ***Non-trading days are simply not shown*** (since there are no prices for those days).

- However, sometimes people like to see these gaps, so that they can tell, with a quick glance, where the weekends and holidays fall.

- Non-trading days can be displayed with the `show_nontrading` keyword.
- For example, in the chart below, you can easily see weekends, as well as a gap at Thursday, November 28th for the U.S. Thanksgiving holiday.


```python
mpf.plot(daily,type='candle',mav=(3,6,9),volume=True,no_xgaps=True)
mpf.plot(daily,type='candle',mav=(3,6,9),volume=True,show_nontrading=True)
```


![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_14_0.png)
![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_14_1.png)


---
Expand All @@ -255,6 +269,7 @@ intraday.tail(3)

(1563, 4)


<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
Expand Down Expand Up @@ -341,6 +356,8 @@ intraday.tail(3)
</tbody>
</table>



The above dataframe contains Open,High,Low,Close data at 1 minute intervervals for the S&P 500 stock index for November 5, 6, 7 and 8, 2019. Let's look at the last hour of trading on November 6th, with a 7 minute and 12 minute moving average.


Expand All @@ -349,12 +366,11 @@ iday = intraday.loc['2019-11-06 15:00':'2019-11-06 16:00',:]
mpf.plot(iday,type='candle',mav=(7,12))
```

![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_18_0.png)

![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_18_1.png)

The "time-interpretation" of the `mav` integers depends on the frequency of the data, because the mav integers are number of data points used in the Moving Average. Notice above that for intraday data the x-axis automatically displays TIME *instead of* date. Below we see that if the intraday data spans two (or more) trading days then two things happen:
- The x-axis displays *BOTH* TIME and DATE
- `no-xgaps` defaults to `True` FOR INTRADAY DATA INVOLVING TWO OR MORE TRADING DAYS

The "time-interpretation" of the `mav` integers depends on the frequency of the data, because the mav integers are the *number of data points* used in the Moving Average (not the number of days or minutes, etc). Notice above that for intraday data the x-axis automatically displays TIME *instead of* date. Below we see that if the intraday data spans into two (or more) trading days the x-axis automatically displays *BOTH* TIME and DATE


```python
Expand All @@ -363,47 +379,47 @@ mpf.plot(iday,type='candle')
```


![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_20_0.png)
![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_20_1.png)


---
In the plot below, we see **what would happen if ` no_xgaps ` did NOT** default to `True` for intraday data involving two or more days.
In the plot below, we see what an intraday plot looks like when we **display non-trading time periods** with **`show_nontrading=True`** for intraday data spanning into two or more days.


```python
mpf.plot(iday,type='candle',no_xgaps=False)
mpf.plot(iday,type='candle',show_nontrading=True)
```


![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_22_0.png)
![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_22_1.png)


---
Below: 4 days of intraday data with `no_xgaps=False`
Below: 4 days of intraday data with `show_nontrading=True`


```python
mpf.plot(intraday,type='ohlc',no_xgaps=False) # 4 day of intraday with no_xgaps=False
mpf.plot(intraday,type='ohlc',show_nontrading=True)
```


![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_24_0.png)
![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_24_1.png)


---
Below: 4 days of intraday data with `no_xgaps` defaulted to `True` for intraday data spanning more than one day.
Below: the same 4 days of intraday data with `show_nontrading` defaulted to `False`.


```python
mpf.plot(intraday,type='line') # intraday spanning more than one day defaults to no_xgaps=True
mpf.plot(intraday,type='line')
```


![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_26_0.png)
![png](https://raw.githubusercontent.com/DanielGoldfarb/mplfinance/master/readme_files/readme_26_1.png)


---
Below: Daily data spanning more than a year automatically adds the *YEAR* to the DATE format
Below: Daily data spanning across a year boundary automatically adds the *YEAR* to the DATE format


```python
Expand All @@ -415,6 +431,7 @@ df.tail(3)

(2519, 6)


<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
Expand Down Expand Up @@ -521,11 +538,13 @@ df.tail(3)
</tbody>
</table>


```python
mpf.plot(df[700:850],type='bars',volume=True,no_xgaps=True,mav=(20,40))
mpf.plot(df[700:850],type='bars',volume=True,mav=(20,40))
```

![png](https://raw.githubusercontent.com/matplotlib/mplfinance/master/readme_files/readme_29_0.png)

![png](readme_files/readme_29_1.png)


For more examples of using mplfinance, please see the jupyter notebooks in the **[`examples`](https://github.com/matplotlib/mplfinance/blob/master/examples/)** directory.
Expand All @@ -535,8 +554,8 @@ For more examples of using mplfinance, please see the jupyter notebooks in the *
# <a name="release"></a>Release Notes

| Version | Description | Release Date |
|----------|--------------|----------------|
| 0.12.3a0 | - kwarg `block=False` for non-blocking call to `mpf.plot()`<br> - customize aspect ratio, title, y-labels<br> - customize colors and other `style` aspects of plot<br> - `no_xgaps` now default to True: use `show_nontrading=True` to set no_xgaps to false<br> - secondary y-axis available to `make_addplot()`<br> - bug fix for volume widths | 2020-02-11 |
|:---------|:-------------|:---------------|
| 0.12.3a0 | - kwarg `block=False` for non-blocking call to `mpf.plot()`<br> - customize aspect ratio, figure title, y-labels<br> - customize colors and other `style` aspects of plot<br> - `no_xgaps` now defaults to True: use `show_nontrading=True` to set no_xgaps to false<br> - secondary y-axis available to `make_addplot()`<br> - bug fix for volume widths | 2020-02-12 |
| 0.12.0a3 | Increase mav limit from 3 to 7 different mavs | 2020-01-16 |
| 0.12.0a2 | Ability to save plot to a file (pdf, svg, png, jpg, ...) | 2020-01-14 |
| 0.12.0a1 | Ability to plot arbitrary user data (in addition to basic OHLCV data).<br> - both line and scatter plots available.<br> - optionally plot on either the "main" or "lower" (aka "volume") axis. | 2020-01-09 |
Expand Down Expand Up @@ -566,10 +585,18 @@ With this new ` mplfinance ` package installed, in addition to the new API, user
from mplfinance.original_flavor import <method>
```


where `<method>` indicates the method you want to import, for example:



```python
from mplfinance.original_flavor import candlestick_ohlc
```

---


```python

```
66 changes: 36 additions & 30 deletions examples/addplot.ipynb

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions examples/customization_and_styles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>2019-11-01</td>\n",
" <th>2019-11-01</th>\n",
" <td>3050.72</td>\n",
" <td>3066.95</td>\n",
" <td>3050.72</td>\n",
" <td>3066.91</td>\n",
" <td>510301237</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2019-11-04</td>\n",
" <th>2019-11-04</th>\n",
" <td>3078.96</td>\n",
" <td>3085.20</td>\n",
" <td>3074.87</td>\n",
Expand Down Expand Up @@ -160,15 +160,15 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>2019-11-27</td>\n",
" <th>2019-11-27</th>\n",
" <td>3145.49</td>\n",
" <td>3154.26</td>\n",
" <td>3143.41</td>\n",
" <td>3153.63</td>\n",
" <td>421853938</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2019-11-29</td>\n",
" <th>2019-11-29</th>\n",
" <td>3147.18</td>\n",
" <td>3150.30</td>\n",
" <td>3139.34</td>\n",
Expand Down Expand Up @@ -362,6 +362,7 @@
" 'default',\n",
" 'mike',\n",
" 'nightclouds',\n",
" 'sas',\n",
" 'starsandstripes',\n",
" 'yahoo']"
]
Expand All @@ -387,7 +388,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -397,7 +398,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {
"scrolled": false
},
Expand Down Expand Up @@ -1027,7 +1028,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit f7e7d85

Please sign in to comment.