-
Notifications
You must be signed in to change notification settings - Fork 75
Added a test for Yahoo finance data in 'Head and shoulder' conformation #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Lucioric2000
wants to merge
3
commits into
white07S:main
Choose a base branch
from
Lucioric2000:feature/plots-and-new-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
| yfinance | ||
| pytest |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| numpy | ||
| pandas | ||
| matplotlib |
This file contains hidden or 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,45 @@ | ||
| from tradingpatterns.hard_data import generate_sample_df_with_pattern | ||
| from tradingpatterns.tradingpatterns import detect_patterns, plot_patterns | ||
|
|
||
| def test_detect_patterns(): | ||
| # Generate data with different patterns | ||
| df_head_shoulder = generate_sample_df_with_pattern("Head and Shoulder") | ||
| df_inv_shoulder = generate_sample_df_with_pattern("Inverse Head and Shoulder") | ||
| df_double_top = generate_sample_df_with_pattern("Double Top") | ||
| df_double_bottom = generate_sample_df_with_pattern("Double Bottom") | ||
| df_triple_top = generate_sample_df_with_pattern("Triple Top") | ||
| df_triple_bottom = generate_sample_df_with_pattern("Triple Bottom") | ||
| df_at = generate_sample_df_with_pattern("Ascending Triangle") | ||
| df_dt = generate_sample_df_with_pattern("Descending Triangle") | ||
|
|
||
| plot_patterns(df_head_shoulder) | ||
| plot_patterns(df_inv_shoulder) | ||
| plot_patterns(df_double_top) | ||
| plot_patterns(df_double_bottom) | ||
| plot_patterns(df_triple_top) | ||
| plot_patterns(df_triple_bottom) | ||
| plot_patterns(df_at) | ||
| plot_patterns(df_dt) | ||
|
|
||
|
|
||
| # Detect patterns | ||
| df_with_head_shoulder_detection = detect_patterns(df_head_shoulder) | ||
| df_with_inv_shoulder_detection = detect_patterns(df_inv_shoulder) | ||
| df_with_double_top_detection = detect_patterns(df_double_top) | ||
| df_with_double_bottom_detection = detect_patterns(df_double_bottom) | ||
| df_with_triple_top_detection = detect_patterns(df_triple_top) | ||
| df_with_triple_bottom_detection = detect_patterns(df_triple_bottom) | ||
| df_with_at_detection = detect_patterns(df_at) | ||
| df_with_dt_detection = detect_patterns(df_dt) | ||
|
|
||
| # Assert that the detected patterns are present in the respective DataFrames | ||
| assert "Head and Shoulder" in df_with_head_shoulder_detection['head_shoulder_pattern'].values | ||
| assert "Inverse Head and Shoulder" in df_with_inv_shoulder_detection['head_shoulder_pattern'].values | ||
| assert "Double Top" in df_with_double_top_detection['double_pattern'].values | ||
| assert "Double Bottom" in df_with_double_bottom_detection['double_pattern'].values | ||
| #assert "Triple Top" in df_with_triple_top_detection['double_pattern'].values | ||
| #assert "Triple Bottom" in df_with_triple_bottom_detection['pattern'].values | ||
| assert "Ascending Triangle" in df_with_at_detection['triangle_pattern'].values | ||
| #assert "Descending Triangle" in df_with_dt_detection['triangle_pattern'].values | ||
|
|
||
| #Now you should modify the detect_patterns function in the tradingpatterns.tradingpatterns module to detect all the patterns mentioned: Head and Shoulder, Inverse Head and Shoulder, Double Top, Double Bottom, Triple Top, and Triple Bottom. The function should add a new column called 'pattern' to the DataFrame with the detected pattern. | ||
This file contains hidden or 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,31 @@ | ||
| date,Price | ||
| 1,100.00 | ||
| 2,101.00 | ||
| 3,102.00 | ||
| 4,103.00 | ||
| 5,104.00 | ||
| 6,103.50 | ||
| 7,104.00 | ||
| 8,104.50 | ||
| 9,105.00 | ||
| 10,105.50 | ||
| 11,105.75 | ||
| 12,106.00 | ||
| 13,106.25 | ||
| 14,106.50 | ||
| 15,106.75 | ||
| 16,107.00 | ||
| 17,107.25 | ||
| 18,107.50 | ||
| 19,107.75 | ||
| 20,108.00 | ||
| 21,108.25 | ||
| 22,108.50 | ||
| 23,108.75 | ||
| 24,109.00 | ||
| 25,109.50 | ||
| 26,110.00 | ||
| 27,110.50 | ||
| 28,111.00 | ||
| 29,111.50 | ||
| 30,112.00 |
This file contains hidden or 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,30 @@ | ||
| 1 | 100.00 | ||
| 2 | 101.00 | ||
| 3 | 102.00 | ||
| 4 | 103.00 | ||
| 5 | 104.00 (Upper trendline) | ||
| 6 | 103.50 | ||
| 7 | 104.00 (Upper trendline) | ||
| 8 | 104.50 | ||
| 9 | 105.00 | ||
| 10 | 105.50 (Upper trendline) | ||
| 11 | 105.75 | ||
| 12 | 106.00 | ||
| 13 | 106.25 | ||
| 14 | 106.50 (Upper trendline) | ||
| 15 | 106.75 | ||
| 16 | 107.00 | ||
| 17 | 107.25 | ||
| 18 | 107.50 | ||
| 19 | 107.75 (Upper trendline) | ||
| 20 | 108.00 | ||
| 21 | 108.25 | ||
| 22 | 108.50 | ||
| 23 | 108.75 | ||
| 24 | 109.00 (Breakout) | ||
| 25 | 109.50 | ||
| 26 | 110.00 | ||
| 27 | 110.50 | ||
| 28 | 111.00 | ||
| 29 | 111.50 | ||
| 30 | 112.00 |
This file contains hidden or 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,31 @@ | ||
| date,Price | ||
| 1,100.00 | ||
| 2,99.00 | ||
| 3,98.00 | ||
| 4,97.00 | ||
| 5,96.00 | ||
| 6,97.00 | ||
| 7,96.00 | ||
| 8,95.00 | ||
| 9,94.00 | ||
| 10,93.00 | ||
| 11,94.00 | ||
| 12,93.00 | ||
| 13,92.00 | ||
| 14,91.00 | ||
| 15,92.00 | ||
| 16,91.00 | ||
| 17,90.00 | ||
| 18,89.00 | ||
| 19,88.00 | ||
| 20,89.00 | ||
| 21,88.00 | ||
| 22,87.00 | ||
| 23,86.00 | ||
| 24,85.00 | ||
| 25,84.00 | ||
| 26,83.00 | ||
| 27,82.00 | ||
| 28,81.00 | ||
| 29,80.00 | ||
| 30,79.00 |
This file contains hidden or 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,30 @@ | ||
| 1 | 100.00 | ||
| 2 | 99.00 | ||
| 3 | 98.00 | ||
| 4 | 97.00 | ||
| 5 | 96.00 (Lower trendline) | ||
| 6 | 97.00 | ||
| 7 | 96.00 (Lower trendline) | ||
| 8 | 95.00 | ||
| 9 | 94.00 | ||
| 10 | 93.00 (Lower trendline) | ||
| 11 | 94.00 | ||
| 12 | 93.00 | ||
| 13 | 92.00 | ||
| 14 | 91.00 (Lower trendline) | ||
| 15 | 92.00 | ||
| 16 | 91.00 | ||
| 17 | 90.00 | ||
| 18 | 89.00 | ||
| 19 | 88.00 (Lower trendline) | ||
| 20 | 89.00 | ||
| 21 | 88.00 | ||
| 22 | 87.00 | ||
| 23 | 86.00 | ||
| 24 | 85.00 (Breakdown) | ||
| 25 | 84.00 | ||
| 26 | 83.00 | ||
| 27 | 82.00 | ||
| 28 | 81.00 | ||
| 29 | 80.00 | ||
| 30 | 79.00 |
This file contains hidden or 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,31 @@ | ||
| date,Price | ||
| 1,100.00 | ||
| 2,102.50 | ||
| 3,105.00 | ||
| 4,107.50 | ||
| 5,110.00 | ||
| 6,107.50 | ||
| 7,105.00 | ||
| 8,107.50 | ||
| 9,110.00 | ||
| 10,107.50 | ||
| 11,105.00 | ||
| 12,102.50 | ||
| 13,100.00 | ||
| 14,97.50 | ||
| 15,95.00 | ||
| 16,92.50 | ||
| 17,90.00 | ||
| 18,92.50 | ||
| 19,95.00 | ||
| 20,92.50 | ||
| 21,90.00 | ||
| 22,87.50 | ||
| 23,85.00 | ||
| 24,82.50 | ||
| 25,80.00 | ||
| 26,77.50 | ||
| 27,75.00 | ||
| 28,72.50 | ||
| 29,70.00 | ||
| 30,67.50 |
This file contains hidden or 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,30 @@ | ||
| 1 | 100.00 | ||
| 2 | 102.50 | ||
| 3 | 105.00 | ||
| 4 | 107.50 | ||
| 5 | 110.00 (1st Top) | ||
| 6 | 107.50 | ||
| 7 | 105.00 | ||
| 8 | 107.50 | ||
| 9 | 110.00 (2nd Top) | ||
| 10 | 107.50 | ||
| 11 | 105.00 | ||
| 12 | 102.50 | ||
| 13 | 100.00 | ||
| 14 | 97.50 | ||
| 15 | 95.00 | ||
| 16 | 92.50 | ||
| 17 | 90.00 (Neckline) | ||
| 18 | 92.50 | ||
| 19 | 95.00 | ||
| 20 | 92.50 | ||
| 21 | 90.00 (Break below neckline) | ||
| 22 | 87.50 | ||
| 23 | 85.00 | ||
| 24 | 82.50 | ||
| 25 | 80.00 | ||
| 26 | 77.50 | ||
| 27 | 75.00 | ||
| 28 | 72.50 | ||
| 29 | 70.00 | ||
| 30 | 67.50 |
This file contains hidden or 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,31 @@ | ||
| date,Price | ||
| 2023-01-01,100 | ||
| 2023-01-02,102 | ||
| 2023-01-03,105 | ||
| 2023-01-04,110 | ||
| 2023-01-05,120 | ||
| 2023-01-06,130 | ||
| 2023-01-07,135 | ||
| 2023-01-08,130 | ||
| 2023-01-09,125 | ||
| 2023-01-10,120 | ||
| 2023-01-11,115 | ||
| 2023-01-12,110 | ||
| 2023-01-13,105 | ||
| 2023-01-14,102 | ||
| 2023-01-15,100 | ||
| 2023-01-16,102 | ||
| 2023-01-17,105 | ||
| 2023-01-18,110 | ||
| 2023-01-19,120 | ||
| 2023-01-20,130 | ||
| 2023-01-21,135 | ||
| 2023-01-22,130 | ||
| 2023-01-23,125 | ||
| 2023-01-24,120 | ||
| 2023-01-25,115 | ||
| 2023-01-26,110 | ||
| 2023-01-27,105 | ||
| 2023-01-28,100 | ||
| 2023-01-29,95 | ||
| 2023-01-30,90 |
This file contains hidden or 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,20 @@ | ||
| import yfinance as yf | ||
| from tradingpatterns.tradingpatterns import detect_head_shoulder | ||
| import datetime as dt | ||
|
|
||
|
|
||
| def test_gold_yfinance_long_term(): | ||
| ticker = yf.Ticker("GOLD") | ||
| history = ticker.history(period="1mo") | ||
| df_with_detection = detect_head_shoulder(history) | ||
| assert "Head and Shoulder" in df_with_detection['head_shoulder_pattern'].values | ||
|
|
||
|
|
||
| def test_tesla_2_hours(): | ||
|
|
||
| start_date = dt.datetime.fromisoformat('2023-05-04T02:51:56.734028') | ||
| end_date = dt.datetime.fromisoformat('2023-05-04T04:51:56.734028') | ||
|
|
||
| gold_data = yf.download("TSLA", start=start_date, end=end_date, interval="15m") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure the name of variable is correct and also cross verify if the start and end params are working |
||
| df_with_detection = detect_head_shoulder(gold_data) | ||
| assert "Head and Shoulder" in df_with_detection['head_shoulder_pattern'].values | ||
This file contains hidden or 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,41 @@ | ||
| date,Price | ||
| 1,100.00 | ||
| 2,102.50 | ||
| 3,105.00 | ||
| 4,107.50 | ||
| 5,110.00 | ||
| 6,107.50 | ||
| 7,105.00 | ||
| 8,107.50 | ||
| 9,110.00 | ||
| 10,107.50 | ||
| 11,105.00 | ||
| 12,107.50 | ||
| 13,110.00 | ||
| 14,107.50 | ||
| 15,105.00 | ||
| 16,102.50 | ||
| 17,100.00 | ||
| 18,97.50 | ||
| 19,95.00 | ||
| 20,92.50 | ||
| 21,90.00 | ||
| 22,92.50 | ||
| 23,95.00 | ||
| 24,92.50 | ||
| 25,90.00 | ||
| 26,87.50 | ||
| 27,85.00 | ||
| 28,82.50 | ||
| 29,80.00 | ||
| 30,77.50 | ||
| 31,75.00 | ||
| 32,72.50 | ||
| 33,70.00 | ||
| 34,67.50 | ||
| 35,65.00 | ||
| 36,62.50 | ||
| 37,60.00 | ||
| 38,57.50 | ||
| 39,55.00 | ||
| 40,52.50 |
This file contains hidden or 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,40 @@ | ||
| 1 | 100.00 | ||
| 2 | 102.50 | ||
| 3 | 105.00 | ||
| 4 | 107.50 | ||
| 5 | 110.00 (1st Top) | ||
| 6 | 107.50 | ||
| 7 | 105.00 | ||
| 8 | 107.50 | ||
| 9 | 110.00 (2nd Top) | ||
| 10 | 107.50 | ||
| 11 | 105.00 | ||
| 12 | 107.50 | ||
| 13 | 110.00 (3rd Top) | ||
| 14 | 107.50 | ||
| 15 | 105.00 | ||
| 16 | 102.50 | ||
| 17 | 100.00 | ||
| 18 | 97.50 | ||
| 19 | 95.00 | ||
| 20 | 92.50 | ||
| 21 | 90.00 (Neckline) | ||
| 22 | 92.50 | ||
| 23 | 95.00 | ||
| 24 | 92.50 | ||
| 25 | 90.00 (Break below neckline) | ||
| 26 | 87.50 | ||
| 27 | 85.00 | ||
| 28 | 82.50 | ||
| 29 | 80.00 | ||
| 30 | 77.50 | ||
| 31 | 75.00 | ||
| 32 | 72.50 | ||
| 33 | 70.00 | ||
| 34 | 67.50 | ||
| 35 | 65.00 | ||
| 36 | 62.50 | ||
| 37 | 60.00 | ||
| 38 | 57.50 | ||
| 39 | 55.00 | ||
| 40 | 52.50 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do let me know if you are working on improving the plotting function based on detection rather than just plotting the candlesticks