-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "Add DATA605 directory (#876)" (#884) This reverts commit 00e90d2. * SorrTask786 Unit test for split_positive_and_negative_parts() (#883) * Added Unit test for split_positive_and_negative_parts() * Resolved comments * Added remaining comments * deleted unnecessary files * "Fixes" * Comment resolution * Comments resolved. --------- Co-authored-by: Samarth KaPatel <samarth.kapatel5@gmail.com> * SorrTask-782 Unit tests for calculate_vwap_twap() (#801) * Issue #782 draft PR with code skeleton * Issue #782 unit tests for function calculate_vwap_twap with 2 different resampling rules * Fix for ambiguous truth value of multiindex column names * Linter corrections on file * Changes for PR comment * Modifications to address PR comments * Adding full-stop to comments --------- Co-authored-by: Aishwarya Nidhi <aishwaryanidhi@Aishwaryas-Air.cgocable.net> Co-authored-by: Samarth KaPatel <samarth.kapatel5@gmail.com> * SorrTask-891 Unit tests for compute epoch function (#901) * Issue 891 - Unit test code skeleton * Issue-891 3 unit tests with each available unit value for Series input. * Issue-891 Unit test of compute epoch function for dataframe input with default unit * Adding missed full stop for comment * PR comment fixes * Removing todo from function * PR comment fixes --------- Co-authored-by: Aishwarya Nidhi <aishwaryanidhi@Aishwaryas-Air.cgocable.net> Co-authored-by: Samarth KaPatel <samarth.kapatel5@gmail.com> * SorTask903 Unit test convert_seconds_to_pandas_minutes() (#907) * Added unit test for function convert_seconds_to_minutes * Nits --------- Co-authored-by: Shaunak Dhande <77265046+Shaunak01@users.noreply.github.com> Co-authored-by: neha2801-create <77967216+neha2801-create@users.noreply.github.com> Co-authored-by: Samarth KaPatel <samarth.kapatel5@gmail.com> Co-authored-by: Aishwarya Nidhi <nidhiaishwarya8@gmail.com> Co-authored-by: Aishwarya Nidhi <aishwaryanidhi@Aishwaryas-Air.cgocable.net>
- Loading branch information
1 parent
b5191b3
commit fd6004c
Showing
7 changed files
with
310 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule DATA605
deleted from
453447
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import pandas as pd | ||
|
||
import helpers.hunit_test as hunitest | ||
import research_amp.transform as ramptran | ||
|
||
|
||
class TestCalculateVwapTwap(hunitest.TestCase): | ||
""" | ||
Test the calculation of VWAP and TWAP with different resampling rules. | ||
""" | ||
|
||
def helper(self) -> pd.DataFrame: | ||
""" | ||
Create data for testing. | ||
""" | ||
timestamp_index = pd.date_range("2024-01-01", periods=10, freq="T") | ||
close = list(range(200, 210)) | ||
volume = list(range(40, 50)) | ||
asset_id = [11, 12] * 5 | ||
data = { | ||
"timestamp": timestamp_index, | ||
"close": close, | ||
"volume": volume, | ||
"full_symbol": asset_id, | ||
} | ||
df = pd.DataFrame(data=data).set_index("timestamp") | ||
return df | ||
|
||
def test1(self) -> None: | ||
resample_rule = "5T" | ||
df = self.helper() | ||
result_df = ramptran.calculate_vwap_twap(df, resample_rule) | ||
# Define expected values. | ||
expected_length = 3 | ||
expected_column_value = None | ||
expected_signature = r""" | ||
# df= | ||
index=[2024-01-01 00:00:00, 2024-01-01 00:10:00] | ||
columns=('close', 11),('close', 12),('twap', 11),('twap', 12),('volume', 11),('volume', 12),('vwap', 11),('vwap', 12) | ||
shape=(3, 8) | ||
close twap volume vwap | ||
11 12 11 12 11 12 11 12 | ||
timestamp | ||
2024-01-01 00:00:00 200.0 NaN 200.0 NaN 40.0 NaN 200.000000 NaN | ||
2024-01-01 00:05:00 204.0 205.0 203.0 203.0 86.0 129.0 203.023256 203.062016 | ||
2024-01-01 00:10:00 208.0 209.0 207.0 208.0 94.0 96.0 207.021277 208.020833 | ||
""" | ||
# Check signature. | ||
self.check_df_output( | ||
result_df, | ||
expected_length, | ||
expected_column_value, | ||
expected_column_value, | ||
expected_signature, | ||
) | ||
|
||
def test2(self) -> None: | ||
resample_rule = "1T" | ||
df = self.helper() | ||
result_df = ramptran.calculate_vwap_twap(df, resample_rule) | ||
# Define expected values. | ||
expected_length = 10 | ||
expected_column_value = None | ||
expected_signature = r""" | ||
# df= | ||
index=[2024-01-01 00:00:00, 2024-01-01 00:09:00] | ||
columns=('close', 11),('close', 12),('twap', 11),('twap', 12),('volume', 11),('volume', 12),('vwap', 11),('vwap', 12) | ||
shape=(10, 8) | ||
close twap volume vwap | ||
11 12 11 12 11 12 11 12 | ||
timestamp | ||
2024-01-01 00:00:00 200.0 NaN 200.0 NaN 40.0 NaN 200.0 NaN | ||
2024-01-01 00:01:00 NaN 201.0 NaN 201.0 NaN 41.0 NaN 201.0 | ||
2024-01-01 00:02:00 202.0 NaN 202.0 NaN 42.0 NaN 202.0 NaN | ||
... | ||
timestamp | ||
2024-01-01 00:07:00 NaN 207.0 NaN 207.0 NaN 47.0 NaN 207.0 | ||
2024-01-01 00:08:00 208.0 NaN 208.0 NaN 48.0 NaN 208.0 NaN | ||
2024-01-01 00:09:00 NaN 209.0 NaN 209.0 NaN 49.0 NaN 209.0 | ||
""" | ||
# Check signature. | ||
self.check_df_output( | ||
result_df, | ||
expected_length, | ||
expected_column_value, | ||
expected_column_value, | ||
expected_signature, | ||
) |