# Data Frequency
Data frequencies play a pivotal role in determining the time intervals at which data is collected, reported, or updated. This documentation provides a comprehensive guide to understand different data frequencies and their meanings. The primary focus is on how to represent data frequencies using the 'frequency representation' format, and it also describes various data frequency types.
</br>

## Frequency Representation
The 'frequency representation' is a comprehensive format that combines all the elements necessary for representing the frequency. The format for frequency representation is as follows: **XBF-S**

**X - Resampling Interval(Optional, defaults to 1 if not provided)**
The 'X' element represents the number that determines the regularity of data. It defines how often data points should be represented. If not provided, it defaults to 1, indicating that data is presented for every available data interval frequency.

**B - Business Frequency (Optional, assumed to be non-business if not provided)**
The 'B' element signifies whether the data representation should align with business days. If 'B' is included, it indicates a business-aligned representation; otherwise, it's considered non-business.

**F - Frequency Type (D, W, M, Q, SA, A)**
The 'F' element specifies the type of frequency, which defines the time unit for data representation. It can take on one of the following values: D (Daily), W (Weekly), M (Monthly), Q (Quarterly), SA (Semi-Annual), A (Annual). Aperiodic, Aperiodic Day

* **Aperiodic:**  Aperiodic data indicates that data points are represented on no specific interval, business alignment, or specific timing associated with this type of data. Aperiodic frequency may involve data updates that are irregularly collected.

* **Aperiodic Day:** Aperiodic day data indicates that data points are represented on a daily basis, but without a consistent pattern. The updates may occur irregularly or on specific days as determined by the data source.

* **Daily:** Daily data refers to information that is collected, reported, or updated every day.

* **Weekly:** Weekly data indicates that data points are collected, reported, or updated on a weekly basis.

* **Monthly:** Monthly data involves data represented in monthly basis.

* **Quarterly:** Quarterly data refers to information that is represented in quarterly basis. Quarterly data can only be occuring on months of March, June, September, and December.

* **Semi-Annual:** Semi-Annual data refers to information that is represented in Semi-Annual basis. Semi-Annual data can only be occuring on months of June and December.

* **Annual:** Annual data refers to information that is represented in Yearly basis.

 **S - Specific Part of Frequency (Optional, depends on 'F')**
The 'S' element is an optional part of the 'frequency' parameter, and its presence depends on the chosen frequency type ('F'). It allows you to specify a particular aspect of the resampling frequency.
</br>

## Frequency Representation Example

**Aperiodic Frequency**
* **`Aperiodic`** **|** Format: F (Only possible example)

**Aperiodic Day Frequency**
* **`Aperiodic Day`** **|** Format: F (Only possible example)

**D (Daily) Frequency**
* **`D`** (Every day) **|** Format: F (If a specific part is given, it will raise an error)
* **`2D`** (Every 2 days) **|** Format: XF
* **`BD`** (Every day except weekends) **|** Format: BF
* **`3BD`** (Every 3 days except weekends) **|** Format: XBF

**W (Weekly) Frequency**
* **`2W-Fri`** (Every 2 weeks on Fridays) **|** Format: XF-Day of the Week (Case Insensitive)
* **`3W-5`** (Every 3 weeks on Fridays) **|** Format: XF-Day of the Week (Case Insensitive)

**M (Monthly) Frequency**
* **`3M-25`** (Every 3 months on the 25th day of the month) **|** Format: XF-dd (Day of the Month)

**Q (Quarterly) Frequency**
* **`3M-25`** (Every 3 months on the 25th day of the month) **|** Format: XF-dd (Day of the Month)

**SA (Semi-Annual) Frequency**
* **`SA-25`** (Resample every 3 months on the 25th day of the month) **|** Format: XF-dd (Day of the Month)

**A (Annual) Frequency**
* **`A-12/15`** (Resample every year on December 15th) **|** Format: F-MM/dd (Months and Day)
</br>

## Frequency during Data Tranformation
Data frequency inheritance ensures consistency and coherence in the resulting data components when performing operations between different data components with varying frequencies.

Before explaining how data frequencies are inherited during data operations of different data frequencies, let's define what we mean by "lower frequency" and "higher frequency" in the context of PrismStudio. The lower frequency refers to a data component with a lower temporal resolution, so when comparing yearly and daily frequency, the lower frequency in this case would be the yearly frequency.

When a data component with a higher frequency data is operated with a lower frequency data, the resulting component inherits the frequency of the lower-frequency data. For example, if a daily data component is operated with a monthly frequency data, the resulting component's data frequency will be monthly frequency.

This makes intuitive sense because it aligns with the lower frequency data. Since the monthly frequency is a subset of the daily frequency, the operation considers the available data points at the monthly intervals, resulting in a coherent and meaningful monthly representation.

To demonstrate the data frequency inheritance during operations, let's consider a practical case involving market capitalization data. Suppose we have a daily frequency market capitalization dataset represented by the variable **`mc`**. We want to resample this dataset to a monthly frequency using a lookback window of 31 days, and then perform an addition operation with the original market capitalization dataset.

```python
# Obtain the daily frequency market capitalization dataset
>>> mc = ps.market.market_cap()

# Resample the market capitalization dataset to monthly frequency
>>> mc_monthly = mc.resample('M', lookback=31)

# Perform an addition operation between the daily and monthly market capitalization datasets
>>> mc_operation_result = mc + mc_monthly

# Multiply the monthly market capitalization dataset by 2
>>> mc_monthly_double = mc_monthly * 2
```

In this example, we first resample the daily frequency market capitalization dataset (**`mc`**) to a monthly frequency using a lookback window of 31 days, resulting in the **`mc_monthly`** dataset. Then, we perform an addition operation (**`+`**) between the daily (**`mc`**) and monthly (**`mc_monthly`**) market capitalization datasets, resulting in the **`mc_operation_result`** dataset. Additionally, we multiply the monthly market capitalization dataset (**`mc_monthly`**) by 2, obtaining the **`mc_monthly_double`** dataset.

Since the operation involves adding two datasets of different frequencies, the resulting dataset (**`mc_operation_result`**) will inherit the lower frequency, which is the monthly frequency in this case. Therefore, **`mc_operation_result`** will have a monthly frequency, aligning with the lower frequency dataset (**`mc_monthly`**).

In this specific case, **`mc_monthly_double`** will be the same as **`mc_operation_result`** because both involve the multiplication operation with the same dataset (**`mc_monthly`**).
</br>

## Default Frequencies
Each component has its own default frequency based on their natural collection frequencies. For more inforamtion

### Aperiodic Daily Default Frequency for Financial Data
Fundamental data is set to an **Aperiodic Daily** default frequency. One may question why this data isn't categorized under a quarterly or annual default frequency, considering the common intervals for data collection. This categorization is due to the irregular timing of data reporting; various companies disclose their financial outcomes on differing dates, which do not follow a predictable pattern, hence the designation of Aperiodic Daily frequency.
</br>

## Data Resampling
Data resampling is a process that alters the frequency of a target data component. The desired frequency can be achieved through the [resample](<#prismstudio._PrismComponent.resample>) function.
