## download_open_source.download_data_stambaugh_yuan()


Download and process Stambaugh-Yuan mispricing factors.


Usage

``` python
download_open_source.download_data_stambaugh_yuan(
    dataset="monthly",
    start_date=None,
    end_date=None,
    url="https://faculty.wharton.upenn.edu/wp-content/uploads/2016/11/"
)
```


Downloads and processes the mispricing factor data of Stambaugh and Yuan (2017) from `Stambaugh's data library <https://fnce.wharton.upenn.edu/profile/stambaug/#misc>`\_. The four-factor model (M4) combines the market and size factors with two mispricing factors, 'mgmt' (management) and 'perf' (performance). The function downloads the requested frequency, aligns the date, renames the columns to the package conventions, and optionally filters the data based on a provided date range.

Returns are already expressed as plain numeric (decimal) values in the source data, so no rescaling is applied. The source files currently end in December 2016; a requested date range that lies entirely outside the available data emits a warning and returns an empty data frame.


## Parameters


`dataset: str = ``"monthly"`  
The data frequency to download, either 'monthly' or 'daily'.

`start_date: str = None`  
A character string or date in 'YYYY-MM-DD' format specifying the start date for the data. If not provided, the full dataset is returned.

`end_date: str = None`  
A character string or date in 'YYYY-MM-DD' format specifying the end date for the data. If not provided, the full dataset is returned.

`url: str = ``"https://faculty.wharton.upenn.edu/wp-content/uploads/2016/11/"`  
The base URL from which to download the dataset files. The file name ('M4.csv' or 'M4d.csv') is appended based on 'dataset'.


## Returns


`pl.DataFrame`  
A data frame with the columns 'date' (aligned to the beginning of the month for monthly data), 'mkt_excess' (the market excess return), 'smb' (size), 'mgmt' (the management mispricing factor), 'perf' (the performance mispricing factor), and 'risk_free' (the risk-free rate). All returns are plain numeric (decimal) values, filtered by the specified date range if 'start_date' and 'end_date' are provided.


## References

Stambaugh, R. F., and Yuan, Y. (2017). Mispricing factors. Review of Financial Studies, 30(4), 1270-1315. https://doi.org/10.1093/rfs/hhw107


## Examples

``` python
from tidyfinance import download_data_stambaugh_yuan
download_data_stambaugh_yuan(
    start_date='2015-01-01', end_date='2016-12-31'
)
download_data_stambaugh_yuan(
    dataset='daily', start_date='2016-01-01', end_date='2016-12-31'
)
```
