From 491917f9c22a95c142bc96aa546d3338e83be92e Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 5 Apr 2026 16:02:14 +0900 Subject: [PATCH 01/15] chore: update dependencies and add .cargo/config.toml to .gitignore --- .gitignore | 2 ++ Cargo.toml | 11 +++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index e1aad9b..8183d72 100644 --- a/.gitignore +++ b/.gitignore @@ -210,3 +210,5 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +.cargo/config.toml \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 5d86adf..a42eaa5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ bytes = "1.10.1" bytestring = "1.5.0" anyhow = "1.0.100" thiserror = "2.0.17" -simple_moving_average = "1.0.2" csv = "1.4.0" serde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0.145" @@ -19,24 +18,20 @@ chrono-tz = "0.10.4" itertools = "0.14.0" charts-rs = "0.3.25" num-traits = "0.2.19" -strum = { version = "0.27.2", features = ["derive"] } +strum = { version = "0.28.0", features = ["derive"] } yahoo_finance_api = "4.1.0" tokio = { version = "1.48.0", features = ["full"] } async-trait = "0.1.89" tryhard = "0.5.2" -reqwest = { version = "0.12.24", features = ["json"] } +reqwest = { version = "0.13.2", features = ["json"] } query-string-builder = "0.6.0" rayon = "1.11.0" deref-derive = "0.1.0" dirs = "6.0.0" +ta = "=0.5.0" [dev-dependencies] indoc = "2.0.7" rstest = "0.26.1" tokio-test = "0.4.4" pretty_assertions = "1.4.1" - -[build] -rustflags = ["-C", "codegen-units=16"] -incremental = true -rustc-wrappers = ["sccache"] From ede2a50735fff1e7d73a17ec481781eb226fe6f0 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 5 Apr 2026 16:02:37 +0900 Subject: [PATCH 02/15] chore: add rust-toolchain.toml for toolchain configuration --- rust-toolchain.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..425fc30 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.90.0" +components = ["rustc", "cargo"] +targets = [] From b0961a2442581922ffb6d5fa38488dd63060cbc5 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 5 Apr 2026 16:04:58 +0900 Subject: [PATCH 03/15] feat: add initial Copilot instructions and coding standards guidelines --- .github/copilot-instructions.md | 46 ++++++++++++++++++++ .github/skills/coding-standards/SKILL.md | 51 ++++++++++++++++++++++ .github/skills/testing-practices/SKILL.md | 53 +++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 .github/copilot-instructions.md create mode 100644 .github/skills/coding-standards/SKILL.md create mode 100644 .github/skills/testing-practices/SKILL.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..5e5ceb1 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,46 @@ +# quantitative-data-analysis-rs Copilot インストラクション(初版) + +## 目的と前提 + +- 本プロジェクトはRustによる株価・財務指標分析ツール(README参照)。ヘキサゴナルアーキテクチャを崩さず、`domain`/`use_case` + でロジック、`infrastructure`/`presenter`で外部適合を行う。 + +## 開発ガイドライン + +このプロジェクトはMicrosoftのPragmatic Rust Guidelinesに従います。 + +### Quick Reference + +- Complete guidelines: `~/.rust/rust-guidelines.txt` +- `~/rust-toolchain` for Rust toolchain management +- Focus areas: Error handling, API design, performance, interoperability +- Tools: rustfmt, clippy, cargo-audit + +### Code Review Checklist + +- [ ] Follows error handling patterns from guidelines +- [ ] API design is scalable and idiomatic +- [ ] Performance considerations addressed +- [ ] Proper documentation and examples included + +### AI Assistant Integration + +When using AI coding assistants, reference the guidelines file: +"Please follow the Microsoft Rust guidelines in `~/.rust/rust-guidelines.txt`" + +## コミュニケーション + +- 非自明なアルゴリズムやデータ変換を触る際は簡潔なコメントで意図を共有。冗長な説明は避ける。 +- 実行結果や差分を示す際はファイルパスをバッククオートで明示し、必要に応じて再現コマンドも提示。 +- 不確実な点や既存の変更がある場合は、即座にユーザへ確認を取りながらペアプロする姿勢を保つ。 + +## 参照スキルガイド (Skills) + +特定のタスクを実行する際は、必ず以下の対応するドキュメントを参照し、その指針に従ってください。 + +- **coding-standards** + - Rust コード変更時の設計指針・レビュー前手順 + - 📄 `.github/skills/coding-standards/SKILL.md` +- **testing-practices** + - テスト実行順序・品質ゲート・ログ共有手順 + - 📄 `.github/skills/testing-practices/SKILL.md` diff --git a/.github/skills/coding-standards/SKILL.md b/.github/skills/coding-standards/SKILL.md new file mode 100644 index 0000000..e9a9cf9 --- /dev/null +++ b/.github/skills/coding-standards/SKILL.md @@ -0,0 +1,51 @@ +--- +name: coding-standards +description: Rust の設計原則と品質ゲートを一貫適用し、ヘキサゴナル境界を守った堅牢な変更を支援する。 +--- + +# coding-standards スキルガイド + +## 目的 + +- Rust コードを追加・変更するときに、Microsoft Pragmatic Rust Guidelines と本リポジトリの方針を一貫して適用する。 +- レビュー負担を減らし、ヘキサゴナルアーキテクチャを崩さない堅牢な変更を下支えする。 + +## 適用タイミング + +- `src/` や `tests/` 配下の Rust コードを作成・編集・削除するとき。 +- CLI/Presenter 層も含め、ビルドに影響する設定を触るとき。 + +## 主要ルール + +1. **設計指針**: ロジックは `domain`/`use_case`、外部適合は `infrastructure`/`presenter` に限定する。 +2. **エラー処理**: `Result` とカスタムエラー型を優先。`unwrap`/`expect` はテストや初期化コードのみで使用可。 +3. **API 設計**: Public API には意味のある型名、`&[T]`/`&str` のような参照を使う。破壊的変更はインタフェース層で吸収。 +4. **性能と相互運用性**: 不要なアロケーションを避け、`Iterator`/`Cow` など標準トレイトを活用。FFI 境界では `unsafe` を局所化。 +5. **ドキュメント**: 意図が読み取りづらい変換やアルゴリズムには短いコメントを残す。README/マニュアルとの齟齬を作らない。 + +## 作業手順 + +1. 変更前に `~/.rust/rust-guidelines.txt` を参照し、該当セクション(エラー処理・API 設計・性能)を確認。 +2. 実装ではレイヤリングと依存方向を常に意識し、必要ならユースケース→インフラの順で改修する。 +3. フォーマットと静的解析をローカルで実行: + ```bash + cargo fmt + cargo clippy --all-targets --all-features + cargo test + ``` + 追加でセキュリティ確認が必要な場合 `cargo audit` を走らせる。 +4. テストや CLI 出力の差異は ` +``path`` +` 表記と再現コマンドをセットで共有する。 + +## チェックリスト + +- [ ] エラー経路は Result/thiserror などで明示されているか。 +- [ ] 新規 API の命名・可視性はドメインモデルと整合しているか。 +- [ ] 不要な `clone`・`String` 化を避け、参照を渡しているか。 +- [ ] `cargo fmt`, `clippy`, `cargo test` を成功させたか (ログを確認したか)。 + +## 参考資料 + +- Microsoft Pragmatic Rust Guidelines: `~/.rust/rust-guidelines.txt` +- リポジトリ共通方針: `.github/copilot-instructions.md` diff --git a/.github/skills/testing-practices/SKILL.md b/.github/skills/testing-practices/SKILL.md new file mode 100644 index 0000000..44b78be --- /dev/null +++ b/.github/skills/testing-practices/SKILL.md @@ -0,0 +1,53 @@ +--- +name: testing-practices +description: Rust 変更を安全に統合するための標準テストフローと品質ゲートを定義する。 +--- + +# testing-practices スキルガイド + +## 目的 + +- Rust コードやビルド設定を触る際に、必要な検証手順を明示して品質を一定に保つ。 +- テスト結果の共有方法を統一し、レビューの手戻りを減らす。 + +## 適用タイミング + +- `src/` や `tests/` 配下のコードを変更・追加・削除するとき。 +- Cargo 設定や CI スクリプトを更新してビルド/テスト結果に影響が出るとき。 + +## 推奨コマンド + +```bash +cargo fmt +cargo clippy --all-targets --all-features +cargo test +cargo nextest run --all --all-features # 長時間テストやCI検証が必要な場合 +cargo audit # 依存パッケージの脆弱性チェック +``` + +## 実行手順 + +1. 変更内容に応じて必要なテストデータや API 資格情報を準備する。 +2. `cargo fmt` でフォーマッタ差分を解消し、`cargo clippy --all-targets --all-features` で警告が出ないことを確認。 +3. `cargo test` でユニット/統合テストを実行し、失敗した場合は該当ターゲットを `-- --nocapture` などで再実行して切り分ける。 +4. 長時間処理やCI互換が求められる変更は `cargo nextest run --all --all-features` を追加実行する。 +5. 依存を更新した場合やセキュリティリスクを懸念する場合は `cargo audit` を実施し、出力を記録する。 +6. レビュー提出時は成功したコマンドとログ要約を共有し、差分が生じたファイルパスはバッククオートで提示する。 + +## チェックリスト + +- [ ] フォーマッタと Clippy を警告ゼロで通過したか。 +- [ ] 追加・変更したロジックに対してユニットテスト/統合テストを更新したか。 +- [ ] `cargo test`/`cargo nextest run` の結果を確認し、失敗ケースを再現できるログを添付したか。 +- [ ] 依存更新時に `cargo audit` を実行し、CVE が残っていないか。 + +## 失敗時の切り分けメモ + +- Clippy が `allow` 無しで回避できない場合は `coding-standards` に立ち返り設計を再検討する。 +- 外部 API を叩くテストは `-- --ignored` 等で分離し、副作用がある場合はモックや固定データを使う。 +- 長時間テストが CI 限定の場合、ローカルでは対象モジュールに絞り `cargo test path::to::module` を使って最小範囲で再現する。 + +## 参考資料 + +- 共通方針: `.github/copilot-instructions.md` +- 設計ルール: `.github/skills/coding-standards/SKILL.md` From 33813be1dd174410fa6e6bdf135b8c887ba07eaa Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 12 Apr 2026 16:27:37 +0900 Subject: [PATCH 04/15] chore: update .gitignore to track Cargo.lock for CI reproducibility --- .gitignore | 14 +- Cargo.lock | 2848 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2852 insertions(+), 10 deletions(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index 8183d72..61ebaae 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,8 @@ examples/**/*.svg examples/**/*.tsv /target -/Cargo.lock +# Cargo.lock is tracked in this repository to keep CI reproducible. +!/Cargo.lock ### Generated by gibo (https://github.com/simonwhitaker/gibo) ### https://raw.github.com/github/gitignore/4488915eec0b3a45b5c63ead28f286819c0917de/Global/macOS.gitignore @@ -203,12 +204,5 @@ target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb - -.cargo/config.toml \ No newline at end of file +# Cargo.lock is intentionally tracked in this repository. +# Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a31d2ea --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2848 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.2", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "aws-lc-rs" +version = "1.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a054912289d18629dc78375ba2c3726a3afe3ff71b4edba9dedfca0e3446d1fc" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a25cf98105baa966497416dbd42565ce3a8cf8dbfd59803ec9ad46f3126399" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "bytes" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" + +[[package]] +name = "bytestring" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "113b4343b5f6617e7ad401ced8de3cc8b012e73a594347c307b90db3e9271289" +dependencies = [ + "bytes", +] + +[[package]] +name = "cc" +version = "1.2.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "charts-rs" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46613e62ca4b6ff0b9e262adaf27dc3113aaf264accb90db048b833c6f95ad45" +dependencies = [ + "ahash", + "arc-swap", + "charts-rs-derive", + "fontdue", + "once_cell", + "regex", + "serde", + "serde_json", + "snafu", + "substring", +] + +[[package]] +name = "charts-rs-derive" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d38f1088dcf6ce3487a09c49fc2d2f8759045603f24d5814357e9283260426" +dependencies = [ + "quote", + "syn 2.0.111", +] + +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link 0.2.1", +] + +[[package]] +name = "chrono-tz" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3" +dependencies = [ + "chrono", + "phf", +] + +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "cookie" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cookie_store" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fc4bff745c9b4c7fb1e97b25d13153da2bc7796260141df62378998d070207f" +dependencies = [ + "cookie", + "document-features", + "idna 1.1.0", + "log", + "publicsuffix", + "serde", + "serde_derive", + "serde_json", + "time", + "url", +] + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "csv" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52cd9d68cf7efc6ddfaaee42e7288d3a99d613d4b50f76ce9827ae0c6e14f938" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde_core", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + +[[package]] +name = "deranged" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "deref-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4255bb7dd538590188bd0aea52e48bd699b19bd90b0d069ec2ced8461fe23273" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] +name = "dirs" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.61.2", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "encoding_rs" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "fontdue" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e57e16b3fe8ff4364c0661fdaac543fb38b29ea9bc9c2f45612d90adf931d2b" +dependencies = [ + "hashbrown", + "ttf-parser", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", + "wasm-bindgen", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "h2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51ee2dd2e4f378392eeff5d51618cd9a63166a2513846bbc55f21cfacd9199d4" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots 0.26.10", +] + +[[package]] +name = "hyper-util" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc2fdfdbff08affe55bb779f33b053aa1fe5dd5b54c257343c17edfa55711bdb" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2 0.5.9", + "system-configuration", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" + +[[package]] +name = "icu_properties" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "potential_utf", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" + +[[package]] +name = "icu_provider" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" +dependencies = [ + "displaydoc", + "icu_locale_core", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "indoc" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" +dependencies = [ + "rustversion", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + +[[package]] +name = "iri-string" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc5ebe9c3a1a7a5127f920a418f7585e9e758e911d0466ed004f393b0e380b2" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys 0.3.1", + "log", + "thiserror 1.0.48", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258" +dependencies = [ + "jni-sys 0.4.1", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.111", +] + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.2", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "libredox" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df15f6eac291ed1cf25865b1ee60399f57e7c227e7f51bdbd4c5270396a9ed50" +dependencies = [ + "bitflags 2.11.0", + "libc", +] + +[[package]] +name = "litemap" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" + +[[package]] +name = "litrs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.52.0", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + +[[package]] +name = "phf" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_shared" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "potential_utf" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psl-types" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac" + +[[package]] +name = "publicsuffix" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42ea446cab60335f76979ec15e12619a2165b5ae2c12166bef27d283a9fadf" +dependencies = [ + "idna 1.1.0", + "psl-types", +] + +[[package]] +name = "quantitative-data-analysis-rs" +version = "0.33.0" +dependencies = [ + "anyhow", + "async-trait", + "bytes", + "bytestring", + "charts-rs", + "chrono", + "chrono-tz", + "csv", + "deref-derive", + "dirs", + "indoc", + "itertools", + "num-traits", + "pretty_assertions", + "query-string-builder", + "rayon", + "reqwest 0.13.2", + "rstest", + "serde", + "serde_json", + "strum", + "ta", + "thiserror 2.0.17", + "tokio", + "tokio-test", + "tryhard", + "yahoo_finance_api", +] + +[[package]] +name = "query-string-builder" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b71ad2010fcd6b911a2efb67fead507f6dd847301c1f77c870499e46b3768c" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "quinn" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3bd15a6f2967aef83887dcb9fec0014580467e33720d073560cf015a5683012" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2 0.5.9", + "thiserror 2.0.17", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcbafbbdbb0f638fe3f35f3c56739f77a8a1d070cb25603226c83339b391472b" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.3.2", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.17", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4e529991f949c5e25755532370b8af5d114acae52326361d68d47af64aa842" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2 0.5.9", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "quote" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + +[[package]] +name = "rand" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.2", +] + +[[package]] +name = "rayon" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" +dependencies = [ + "getrandom 0.2.11", + "libredox", + "thiserror 2.0.17", +] + +[[package]] +name = "regex" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "relative-path" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" + +[[package]] +name = "reqwest" +version = "0.12.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b4c14b2d9afca6a60277086b0cc6a6ae0b568f6f7916c943a8cdc79f8be240f" +dependencies = [ + "base64", + "bytes", + "cookie", + "cookie_store", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 1.0.1", +] + +[[package]] +name = "reqwest" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "serde", + "serde_json", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "ring" +version = "0.17.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" +dependencies = [ + "cc", + "getrandom 0.2.11", + "libc", + "spin", + "untrusted", + "windows-sys 0.48.0", +] + +[[package]] +name = "rstest" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5a3193c063baaa2a95a33f03035c8a72b83d97a54916055ba22d35ed3839d49" +dependencies = [ + "futures-timer", + "futures-util", + "rstest_macros", +] + +[[package]] +name = "rstest_macros" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c845311f0ff7951c5506121a9ad75aec44d083c31583b2ea5a30bcb0b0abba0" +dependencies = [ + "cfg-if", + "glob", + "proc-macro-crate", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version", + "syn 2.0.111", + "unicode-ident", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustls" +version = "0.23.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7160e3e10bf4535308537f3c4e1641468cd0e485175d6163087c0393c7d46643" +dependencies = [ + "aws-lc-rs", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +dependencies = [ + "web-time", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + +[[package]] +name = "rustls-webpki" +version = "0.103.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags 2.11.0", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "serde_json" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "snafu" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e84b3f4eacbf3a1ce05eac6763b4d629d60cbc94d632e4092c54ade71f1e1a2" +dependencies = [ + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1c97747dbf44bb1ca44a561ece23508e99cb592e862f22222dcf42f51d1e451" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "socket2" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "socket2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "substring" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ee6433ecef213b2e72f587ef64a2f5943e7cd16fbd82dbe8bc07486c534c86" +dependencies = [ + "autocfg", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.11.0", + "core-foundation 0.9.3", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "ta" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "609409d472a0a7d8d4dd9e19891bbdef546b9dce670c3057d0e02192dc541226" + +[[package]] +name = "thiserror" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +dependencies = [ + "thiserror-impl 1.0.48", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl 2.0.17", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "time" +version = "0.3.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.6.0", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-test" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2468baabc3311435b55dd935f702f42cd1b8abb7e754fb7dfb16bd36aa88f9f7" +dependencies = [ + "async-stream", + "bytes", + "futures-core", + "tokio", + "tokio-stream", +] + +[[package]] +name = "tokio-util" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags 2.11.0", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + +[[package]] +name = "tryhard" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fe58ebd5edd976e0fe0f8a14d2a04b7c81ef153ea9a54eebc42e67c2c23b4e5" +dependencies = [ + "pin-project-lite", + "tokio", +] + +[[package]] +name = "ttf-parser" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" + +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +dependencies = [ + "form_urlencoded", + "idna 0.4.0", + "percent-encoding", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn 2.0.111", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "webpki-roots" +version = "0.26.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37493cadf42a2a939ed404698ded7fb378bf301b5011f973361779a3a74f8c93" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "webpki-roots" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8782dd5a41a24eed3a4f40b606249b3e236ca61adf1f25ea4d45c73de122b502" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-registry" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bab093bdd303a1240bb99b8aba8ea8a69ee19d34c9e2ef9594e708a4878820" +dependencies = [ + "windows-link 0.1.1", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link 0.1.1", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link 0.1.1", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link 0.2.1", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags 2.11.0", +] + +[[package]] +name = "writeable" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" + +[[package]] +name = "yahoo_finance_api" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc75c0aef2fb5095c7fb103dc2aaec2d0bdeed8c4a34b2cd504f083e29f6f128" +dependencies = [ + "reqwest 0.12.26", + "serde", + "serde_json", + "thiserror 1.0.48", + "time", +] + +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + +[[package]] +name = "yoke" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerotrie" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] From 2be9449584ed92ee441bcb8f1d8181bc5eab26c9 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 12 Apr 2026 17:01:28 +0900 Subject: [PATCH 05/15] refactor: rename files and update module paths for crossover strategy --- .cargo/config.toml | 8 + .github/workflows/rust.yml | 48 ++- README.md | 2 + RUST_GUIDELINES.md | 21 -- .../8473.T.financial_indicator_summary.json | 14 +- ...T.high_low_direction_signal_analysis.json} | 0 ...ysis.json => 8473.T.sma_cos_analysis.json} | 2 +- assets/8473.T.trend_reversal_analysis.json | 8 +- ...T.high_low_direction_signal_analysis.json} | 0 ...ysis.json => 9223.T.sma_cos_analysis.json} | 2 +- assets/9223.T.trend_reversal_analysis.json | 8 +- assets/trend_summary.svg | 34 -- examples/trend_analysis.rs | 54 ++-- rust-toolchain | 1 - src/domain/models.rs | 15 +- .../models/{ecp1.rs => body_engulfing.rs} | 0 .../models/{ecp2 => body_engulfing}/model.rs | 43 ++- .../models/{macos_analysis => }/close.rs | 0 src/domain/models/close/model.rs | 2 + src/domain/models/crossover_strategy.rs | 7 + .../crossover_strategy/analysis_pattern.rs | 1 + .../analysis_pattern/model.rs | 67 ++++ .../crossover_strategy/crossover_pattern.rs | 3 + .../crossover_pattern/close.rs} | 0 .../crossover_pattern/close/model.rs | 4 + .../crossover_pattern/model.rs | 41 +++ .../crossover_pattern}/volume.rs | 0 .../crossover_pattern/volume/model.rs | 4 + .../latest_chance.rs} | 0 .../crossover_strategy/latest_chance/model.rs | 53 ++++ .../macd_cos.rs} | 0 .../crossover_strategy/macd_cos/model.rs | 47 +++ .../rate_of_chance.rs} | 0 .../rate_of_chance/model.rs | 6 + .../models/crossover_strategy/sma_cos.rs | 2 + .../sma_cos/analysis_result.rs} | 0 .../sma_cos/analysis_result/close.rs | 1 + .../sma_cos/analysis_result/close/model.rs | 201 ++++++++++++ .../sma_cos/analysis_result/volume.rs | 1 + .../sma_cos/analysis_result/volume/model.rs | 86 +++++ .../crossover_strategy/sma_cos/model.rs | 197 ++++++++++++ .../sma_cps.rs} | 0 .../sma_cps}/model.rs | 27 +- .../models/high_low_direction_signal.rs | 1 + .../model.rs | 47 ++- src/domain/models/macd.rs | 1 + src/domain/models/macd/model.rs | 62 ++++ src/domain/models/macos/model.rs | 294 ------------------ .../models/macos_analysis/close/model.rs | 259 --------------- .../models/macos_analysis/volume/model.rs | 87 ------ src/domain/models/ms_es.rs | 1 + src/domain/models/{msesp => ms_es}/model.rs | 52 ++-- src/domain/models/sma/model.rs | 60 ++-- src/domain/models/statement/model.rs | 2 +- .../models/stocks_macoses_pair/model.rs | 7 - src/domain/models/stocks_sma_coses_pair.rs | 1 + .../models/stocks_sma_coses_pair/model.rs | 7 + .../models/trend_reversal_analysis/model.rs | 121 +++---- src/domain/models/volume.rs | 1 + src/domain/models/volume/model.rs | 2 + .../repositories/statement/jquants_api.rs | 16 +- .../presenters/trend_analysis/output.rs | 19 +- .../presenters/trend_analysis/response.rs | 10 +- .../trend_analysis/response/chart.rs | 100 +++--- .../trend_analysis/response/json.rs | 2 +- .../trend_analysis_summary/response/chart.rs | 2 +- src/presenter/views.rs | 6 +- ... => high_low_direction_signal_analysis.rs} | 0 .../view.rs | 19 +- src/presenter/views/latest_chance/view.rs | 2 +- src/presenter/views/macos_analysis/view.rs | 82 ----- src/presenter/views/rate_of_chance/view.rs | 25 +- .../views/shared/crossover_pattern_filter.rs | 39 +-- src/presenter/views/sma/view.rs | 15 +- ...{macos_analysis.rs => sma_cos_analysis.rs} | 0 .../close.rs | 0 .../close/view.rs | 27 +- src/presenter/views/sma_cos_analysis/view.rs | 84 +++++ .../volume.rs | 0 .../volume/view.rs | 13 +- ...{macps_analysis.rs => sma_cps_analysis.rs} | 0 .../view.rs | 2 +- src/presenter/views/stock/view.rs | 4 +- .../trend_analysis_summary/chart/view.rs | 6 +- .../views/trend_analysis_summary/json/view.rs | 64 ++-- .../views/trend_reversal_analysis/view.rs | 35 ++- .../interactors/trend_analysis/interactor.rs | 62 ++-- tests/csv.rs | 10 +- tests/simple_moving_average.rs | 15 - 89 files changed, 1403 insertions(+), 1271 deletions(-) create mode 100644 .cargo/config.toml delete mode 100644 RUST_GUIDELINES.md rename assets/{8473.T.ecp1_analysis.json => 8473.T.high_low_direction_signal_analysis.json} (100%) rename assets/{8473.T.macos_analysis.json => 8473.T.sma_cos_analysis.json} (68%) rename assets/{9223.T.ecp1_analysis.json => 9223.T.high_low_direction_signal_analysis.json} (100%) rename assets/{9223.T.macos_analysis.json => 9223.T.sma_cos_analysis.json} (66%) delete mode 100644 assets/trend_summary.svg delete mode 100644 rust-toolchain rename src/domain/models/{ecp1.rs => body_engulfing.rs} (100%) rename src/domain/models/{ecp2 => body_engulfing}/model.rs (89%) rename src/domain/models/{macos_analysis => }/close.rs (100%) create mode 100644 src/domain/models/close/model.rs create mode 100644 src/domain/models/crossover_strategy.rs create mode 100644 src/domain/models/crossover_strategy/analysis_pattern.rs create mode 100644 src/domain/models/crossover_strategy/analysis_pattern/model.rs create mode 100644 src/domain/models/crossover_strategy/crossover_pattern.rs rename src/domain/models/{ecp2.rs => crossover_strategy/crossover_pattern/close.rs} (100%) create mode 100644 src/domain/models/crossover_strategy/crossover_pattern/close/model.rs create mode 100644 src/domain/models/crossover_strategy/crossover_pattern/model.rs rename src/domain/models/{macos_analysis => crossover_strategy/crossover_pattern}/volume.rs (100%) create mode 100644 src/domain/models/crossover_strategy/crossover_pattern/volume/model.rs rename src/domain/models/{macos.rs => crossover_strategy/latest_chance.rs} (100%) create mode 100644 src/domain/models/crossover_strategy/latest_chance/model.rs rename src/domain/models/{macps.rs => crossover_strategy/macd_cos.rs} (100%) create mode 100644 src/domain/models/crossover_strategy/macd_cos/model.rs rename src/domain/models/{msesp.rs => crossover_strategy/rate_of_chance.rs} (100%) create mode 100644 src/domain/models/crossover_strategy/rate_of_chance/model.rs create mode 100644 src/domain/models/crossover_strategy/sma_cos.rs rename src/domain/models/{macos_analysis.rs => crossover_strategy/sma_cos/analysis_result.rs} (100%) create mode 100644 src/domain/models/crossover_strategy/sma_cos/analysis_result/close.rs create mode 100644 src/domain/models/crossover_strategy/sma_cos/analysis_result/close/model.rs create mode 100644 src/domain/models/crossover_strategy/sma_cos/analysis_result/volume.rs create mode 100644 src/domain/models/crossover_strategy/sma_cos/analysis_result/volume/model.rs create mode 100644 src/domain/models/crossover_strategy/sma_cos/model.rs rename src/domain/models/{stocks_macoses_pair.rs => crossover_strategy/sma_cps.rs} (100%) rename src/domain/models/{macps => crossover_strategy/sma_cps}/model.rs (80%) create mode 100644 src/domain/models/high_low_direction_signal.rs rename src/domain/models/{ecp1 => high_low_direction_signal}/model.rs (84%) create mode 100644 src/domain/models/macd.rs create mode 100644 src/domain/models/macd/model.rs delete mode 100644 src/domain/models/macos/model.rs delete mode 100644 src/domain/models/macos_analysis/close/model.rs delete mode 100644 src/domain/models/macos_analysis/volume/model.rs create mode 100644 src/domain/models/ms_es.rs rename src/domain/models/{msesp => ms_es}/model.rs (89%) delete mode 100644 src/domain/models/stocks_macoses_pair/model.rs create mode 100644 src/domain/models/stocks_sma_coses_pair.rs create mode 100644 src/domain/models/stocks_sma_coses_pair/model.rs create mode 100644 src/domain/models/volume.rs create mode 100644 src/domain/models/volume/model.rs rename src/presenter/views/{buy_sell_signal_analysis.rs => high_low_direction_signal_analysis.rs} (100%) rename src/presenter/views/{buy_sell_signal_analysis => high_low_direction_signal_analysis}/view.rs (70%) delete mode 100644 src/presenter/views/macos_analysis/view.rs rename src/presenter/views/{macos_analysis.rs => sma_cos_analysis.rs} (100%) rename src/presenter/views/{macos_analysis => sma_cos_analysis}/close.rs (100%) rename src/presenter/views/{macos_analysis => sma_cos_analysis}/close/view.rs (64%) create mode 100644 src/presenter/views/sma_cos_analysis/view.rs rename src/presenter/views/{macos_analysis => sma_cos_analysis}/volume.rs (100%) rename src/presenter/views/{macos_analysis => sma_cos_analysis}/volume/view.rs (78%) rename src/presenter/views/{macps_analysis.rs => sma_cps_analysis.rs} (100%) rename src/presenter/views/{macps_analysis => sma_cps_analysis}/view.rs (92%) delete mode 100644 tests/simple_moving_average.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..6c36a91 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,8 @@ +# https://medium.com/@anshusinghal703/rust-dev-speedup-secret-cutting-compile-time-from-22-minutes-to-under-a-minute-with-a-single-be8a0da4fc83 +[build] +rustflags = ["-C", "codegen-units=16"] +rustc-wrapper = "sccache" +incremental = true + +[profile.dev.build-override] +opt-level = 3 diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d5d1453..ab43e46 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,20 +6,52 @@ on: pull_request: branches: [ "main" ] +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + env: CARGO_TERM_COLOR: always - JQUANTS_MAIL_ADDRESS: ${{ secrets.JQUANTS_MAIL_ADDRESS }} - JQUANTS_PASSWORD: ${{ secrets.JQUANTS_PASSWORD }} jobs: build: - + name: Test and Build runs-on: ubuntu-latest - + timeout-minutes: 30 steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@v2 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: 1.90.0 + components: clippy, rustfmt + + - name: Cache Rust artifacts + uses: Swatinem/rust-cache@v2 + + - name: Validate J-Quants secrets + env: + JQUANTS_MAIL_ADDRESS: ${{ secrets.JQUANTS_MAIL_ADDRESS }} + JQUANTS_PASSWORD: ${{ secrets.JQUANTS_PASSWORD }} + run: | + test -n "$JQUANTS_MAIL_ADDRESS" + test -n "$JQUANTS_PASSWORD" + + - name: Check formatting + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-targets --all-features -- -D warnings + - name: Run tests - run: cargo test --verbose - - name: Build - run: cargo build --verbose + env: + JQUANTS_MAIL_ADDRESS: ${{ secrets.JQUANTS_MAIL_ADDRESS }} + JQUANTS_PASSWORD: ${{ secrets.JQUANTS_PASSWORD }} + run: cargo test --all --locked + + - name: Build library + run: cargo build --lib --all-features --locked --verbose diff --git a/README.md b/README.md index 2d4995c..ffa39b1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ and Yahoo Finance to produce chart-ready signals, summaries, and SVG/JSON artifa cargo fetch ``` +> This repository intentionally tracks `Cargo.lock` to keep CI and J-Quants connectivity checks reproducible. + ## Usage - **Financial indicators:** diff --git a/RUST_GUIDELINES.md b/RUST_GUIDELINES.md deleted file mode 100644 index 99d282a..0000000 --- a/RUST_GUIDELINES.md +++ /dev/null @@ -1,21 +0,0 @@ -# Rust Development Guidelines - -This project follows Microsoft's Pragmatic Rust Guidelines. - -## Quick Reference - -- Complete guidelines: `~/.rust/rust-guidelines.txt` -- Focus areas: Error handling, API design, performance, interoperability -- Tools: rustfmt, clippy, cargo-audit - -## Code Review Checklist - -- [ ] Follows error handling patterns from guidelines -- [ ] API design is scalable and idiomatic -- [ ] Performance considerations addressed -- [ ] Proper documentation and examples included - -## AI Assistant Integration - -When using AI coding assistants, reference the guidelines file: -"Please follow the Microsoft Rust guidelines in ~/.rust/rust-guidelines.txt" \ No newline at end of file diff --git a/assets/8473.T.financial_indicator_summary.json b/assets/8473.T.financial_indicator_summary.json index a82e94f..6ad0db5 100644 --- a/assets/8473.T.financial_indicator_summary.json +++ b/assets/8473.T.financial_indicator_summary.json @@ -1,14 +1,14 @@ [ { "close_date": "2025-08-27", - "disclosed_date": "2025-05-09", - "pbr": 1.6220124773886369, - "per": 12.594900110056146, + "disclosed_date": "2026-03-13", + "pbr": null, + "per": null, "oppr": null, "orpr": null, - "pr": 11.229223131978005, - "mix": 20.429085129974585, - "roe": 9.191554791293537, - "roa": 0.5048355158573843 + "pr": null, + "mix": null, + "roe": null, + "roa": null } ] \ No newline at end of file diff --git a/assets/8473.T.ecp1_analysis.json b/assets/8473.T.high_low_direction_signal_analysis.json similarity index 100% rename from assets/8473.T.ecp1_analysis.json rename to assets/8473.T.high_low_direction_signal_analysis.json diff --git a/assets/8473.T.macos_analysis.json b/assets/8473.T.sma_cos_analysis.json similarity index 68% rename from assets/8473.T.macos_analysis.json rename to assets/8473.T.sma_cos_analysis.json index f916713..408814f 100644 --- a/assets/8473.T.macos_analysis.json +++ b/assets/8473.T.sma_cos_analysis.json @@ -1,6 +1,6 @@ [ { - "pattern": "GoldenCross", + "crossover_pattern": "GoldenCross", "latest_chance": "2023-08-30", "rate_of_chance": 27.27272727272727 } diff --git a/assets/8473.T.trend_reversal_analysis.json b/assets/8473.T.trend_reversal_analysis.json index 241d183..78dbadf 100644 --- a/assets/8473.T.trend_reversal_analysis.json +++ b/assets/8473.T.trend_reversal_analysis.json @@ -1,9 +1,9 @@ [ { "type": "Stay", - "macos_date": "2023-08-30", - "ecp2_date": "1970-01-01", - "msesp_date": "1970-01-01", - "macps_date": "2023-09-08" + "sma_cos_date": "2023-08-30", + "sma_cps_date": "2023-09-08", + "body_engulfing_date": "1970-01-01", + "ms_es_date": "1970-01-01" } ] \ No newline at end of file diff --git a/assets/9223.T.ecp1_analysis.json b/assets/9223.T.high_low_direction_signal_analysis.json similarity index 100% rename from assets/9223.T.ecp1_analysis.json rename to assets/9223.T.high_low_direction_signal_analysis.json diff --git a/assets/9223.T.macos_analysis.json b/assets/9223.T.sma_cos_analysis.json similarity index 66% rename from assets/9223.T.macos_analysis.json rename to assets/9223.T.sma_cos_analysis.json index 23ff704..1d42020 100644 --- a/assets/9223.T.macos_analysis.json +++ b/assets/9223.T.sma_cos_analysis.json @@ -1,6 +1,6 @@ [ { - "pattern": "Neither", + "crossover_pattern": "Neither", "latest_chance": "1970-01-01", "rate_of_chance": 0.0 } diff --git a/assets/9223.T.trend_reversal_analysis.json b/assets/9223.T.trend_reversal_analysis.json index d289adc..c406555 100644 --- a/assets/9223.T.trend_reversal_analysis.json +++ b/assets/9223.T.trend_reversal_analysis.json @@ -1,9 +1,9 @@ [ { "type": "Stay", - "macos_date": "2024-02-07", - "ecp2_date": "1970-01-01", - "msesp_date": "2024-02-13", - "macps_date": "1970-01-01" + "sma_cos_date": "2024-02-07", + "sma_cps_date": "1970-01-01", + "body_engulfing_date": "1970-01-01", + "ms_es_date": "2024-02-13" } ] \ No newline at end of file diff --git a/assets/trend_summary.svg b/assets/trend_summary.svg deleted file mode 100644 index 5904cdd..0000000 --- a/assets/trend_summary.svg +++ /dev/null @@ -1,34 +0,0 @@ - - - - -code - - -symbol - - -macos type - - -latest - - -chance rate(All) - - - - -84730 - - - -Golden - - -2023-08-30 - - -27% - - \ No newline at end of file diff --git a/examples/trend_analysis.rs b/examples/trend_analysis.rs index 11475cc..209dbfd 100644 --- a/examples/trend_analysis.rs +++ b/examples/trend_analysis.rs @@ -1,13 +1,13 @@ use anyhow::Result; use bytes::Bytes; use chrono::NaiveDate; -use itertools::{Itertools, multiunzip}; +use itertools::{multiunzip, Itertools}; use tokio::fs::write; use quantitative_data_analysis_rs::infrastructure::repositories::company::structures::internal::tsv; -use quantitative_data_analysis_rs::presenter::views::buy_sell_signal_analysis::view::BuySellSignalAnalysis; -use quantitative_data_analysis_rs::presenter::views::macos_analysis::view::MACOSAnalysis; +use quantitative_data_analysis_rs::presenter::views::high_low_direction_signal_analysis::view::HighLowDirectionSignalAnalysis; use quantitative_data_analysis_rs::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; +use quantitative_data_analysis_rs::presenter::views::sma_cos_analysis::view::SmaCosAnalysis; use quantitative_data_analysis_rs::presenter::views::trend_analysis_summary::json::view::JsonRow; use quantitative_data_analysis_rs::presenter::views::trend_reversal_analysis::view::TrendReversalAnalysis; use quantitative_data_analysis_rs::shared::jquants_api::setup::Setup; @@ -102,22 +102,26 @@ async fn main() -> Result<()> { .iter() .map(|row| { let JsonRow { - macos_analysis, + sma_cos_analysis, trend_reversal_analysis, - ecp1_analysis, + high_low_direction_signal_analysis, .. } = row; - (macos_analysis, trend_reversal_analysis, ecp1_analysis) + ( + sma_cos_analysis, + trend_reversal_analysis, + high_low_direction_signal_analysis, + ) }) .collect_vec(); - let (macos_analysis, trend_reversal_analysis, ecp1_analysis): ( - Vec<&MACOSAnalysis>, + let (sma_cos_analysis, trend_reversal_analysis, high_low_direction_signal_analysis): ( + Vec<&SmaCosAnalysis>, Vec<&TrendReversalAnalysis>, - Vec<&BuySellSignalAnalysis>, + Vec<&HighLowDirectionSignalAnalysis>, ) = multiunzip(tuples); - let json_str = serde_json::to_string_pretty(&macos_analysis)?; + let json_str = serde_json::to_string_pretty(&sma_cos_analysis)?; assert_eq!( - include_str!("../assets/8473.T.macos_analysis.json"), + include_str!("../assets/8473.T.sma_cos_analysis.json"), &json_str ); let json_str = serde_json::to_string_pretty(&trend_reversal_analysis)?; @@ -125,9 +129,9 @@ async fn main() -> Result<()> { include_str!("../assets/8473.T.trend_reversal_analysis.json"), &json_str ); - let json_str = serde_json::to_string_pretty(&ecp1_analysis)?; + let json_str = serde_json::to_string_pretty(&high_low_direction_signal_analysis)?; assert_eq!( - include_str!("../assets/8473.T.ecp1_analysis.json"), + include_str!("../assets/8473.T.high_low_direction_signal_analysis.json"), &json_str ); }; @@ -170,22 +174,26 @@ async fn main() -> Result<()> { .iter() .map(|row| { let JsonRow { - macos_analysis, + sma_cos_analysis, trend_reversal_analysis, - ecp1_analysis, + high_low_direction_signal_analysis, .. } = row; - (macos_analysis, trend_reversal_analysis, ecp1_analysis) + ( + sma_cos_analysis, + trend_reversal_analysis, + high_low_direction_signal_analysis, + ) }) .collect_vec(); - let (macos_analysis, trend_reversal_analysis, ecp1_analysis): ( - Vec<&MACOSAnalysis>, + let (sma_cos_analysis, trend_reversal_analysis, high_low_direction_signal_analysis): ( + Vec<&SmaCosAnalysis>, Vec<&TrendReversalAnalysis>, - Vec<&BuySellSignalAnalysis>, + Vec<&HighLowDirectionSignalAnalysis>, ) = multiunzip(tuples); - let json_str = serde_json::to_string_pretty(&macos_analysis)?; + let json_str = serde_json::to_string_pretty(&sma_cos_analysis)?; assert_eq!( - include_str!("../assets/9223.T.macos_analysis.json"), + include_str!("../assets/9223.T.sma_cos_analysis.json"), &json_str ); let json_str = serde_json::to_string_pretty(&trend_reversal_analysis)?; @@ -193,9 +201,9 @@ async fn main() -> Result<()> { include_str!("../assets/9223.T.trend_reversal_analysis.json"), &json_str ); - let json_str = serde_json::to_string_pretty(&ecp1_analysis)?; + let json_str = serde_json::to_string_pretty(&high_low_direction_signal_analysis)?; assert_eq!( - include_str!("../assets/9223.T.ecp1_analysis.json"), + include_str!("../assets/9223.T.high_low_direction_signal_analysis.json"), &json_str ); }; diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 82e24bf..0000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -1.90.0 diff --git a/src/domain/models.rs b/src/domain/models.rs index b79c20a..68ebea3 100644 --- a/src/domain/models.rs +++ b/src/domain/models.rs @@ -1,15 +1,16 @@ +pub mod body_engulfing; pub mod buy_sell_signal; pub mod candle_stick; +pub mod close; pub mod company; -pub mod ecp1; -pub mod ecp2; +pub mod crossover_strategy; pub mod financial_indicator; -pub mod macos; -pub mod macos_analysis; -pub mod macps; -pub mod msesp; +pub mod high_low_direction_signal; +pub mod macd; +pub mod ms_es; pub mod sma; pub mod statement; pub mod stock; -pub mod stocks_macoses_pair; +pub mod stocks_sma_coses_pair; pub mod trend_reversal_analysis; +pub mod volume; diff --git a/src/domain/models/ecp1.rs b/src/domain/models/body_engulfing.rs similarity index 100% rename from src/domain/models/ecp1.rs rename to src/domain/models/body_engulfing.rs diff --git a/src/domain/models/ecp2/model.rs b/src/domain/models/body_engulfing/model.rs similarity index 89% rename from src/domain/models/ecp2/model.rs rename to src/domain/models/body_engulfing/model.rs index 6374ca1..d5fd1b0 100644 --- a/src/domain/models/ecp2/model.rs +++ b/src/domain/models/body_engulfing/model.rs @@ -1,28 +1,27 @@ -use deref_derive::{Deref, DerefMut}; -use itertools::Itertools; -use std::cmp::Ordering; - use crate::domain::models::buy_sell_signal::model::{BuySellSignal, BuySellSignalType}; use crate::domain::models::candle_stick::model::{BullishBearishType, CandleStick}; +use deref_derive::{Deref, DerefMut}; +use rayon::prelude::*; +use std::cmp::Ordering; #[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct ECP2 { +pub struct BodyEngulfing { body_low_ordering: Option, body_high_ordering: Option, prev_bullish_bearish: BullishBearishType, today_bullish_bearish: BullishBearishType, } -/// Engulfing Candlestick Pattern2 +/// Body Engulfing /// /// ある日の始値と終値の間にその前日の始値と終値が飲み込まれているかをみる /// /// * **Buy**: ある日の始値と終値の間にその前日の始値と終値が飲み込まれており、前日がBearishCandleで当日がBullishCandleのとき /// * **Sell**: ある日の始値と終値の間にその前日の始値と終値が飲み込まれており、前日がBullishCandleで当日がBearishCandleのとき /// * **Stay**: 上記のどちらにもあてはまならない -impl From for BuySellSignalType { - fn from(value: ECP2) -> Self { - let ECP2 { +impl From for BuySellSignalType { + fn from(value: BodyEngulfing) -> Self { + let BodyEngulfing { body_low_ordering, body_high_ordering, prev_bullish_bearish, @@ -52,16 +51,16 @@ impl From for BuySellSignalType { } #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Deref, DerefMut)] -pub struct ECP2s(Vec); +pub struct BodyEngulfings(Vec); -impl From<&[CandleStick]> for ECP2s { +impl From<&[CandleStick]> for BodyEngulfings { /// /// # Examples /// ``` /// use bytes::Bytes; /// /// use quantitative_data_analysis_rs::domain::models::candle_stick::model::CandleSticks; - /// use quantitative_data_analysis_rs::domain::models::ecp2::model::ECP2s; + /// use quantitative_data_analysis_rs::domain::models::body_engulfing::model::BodyEngulfings; /// use quantitative_data_analysis_rs::domain::repositories::stock::queries; /// use quantitative_data_analysis_rs::infrastructure::dsv::Dsv; /// use quantitative_data_analysis_rs::infrastructure::repositories::stock::structures::internal::csv; @@ -79,31 +78,31 @@ impl From<&[CandleStick]> for ECP2s { /// }; /// let stocks = dsv.get_stocks(&query).await.unwrap(); /// let candle_sticks = CandleSticks::::try_from(stocks.as_slice()).unwrap(); - /// let ecp2s = ECP2s::from(candle_sticks.as_slice()); - /// assert_eq!(ecp2s.len(), 34); + /// let body_engulfings = BodyEngulfings::from(candle_sticks.as_slice()); + /// assert_eq!(body_engulfings.len(), 34); /// }); /// ``` fn from(value: &[CandleStick]) -> Self { let vec = value - .windows(2) + .par_windows(2) .map(|candle_sticks| { let prev = candle_sticks.first().unwrap(); let today = candle_sticks.get(1).unwrap(); let body_high_ordering = today.body_high.partial_cmp(&prev.body_high); let body_low_ordering = today.body_low.partial_cmp(&prev.body_low); - let ecp2 = ECP2 { + let body_engulfing = BodyEngulfing { body_low_ordering, body_high_ordering, prev_bullish_bearish: prev.bullish_bearish, today_bullish_bearish: today.bullish_bearish, }; - let r#type = BuySellSignalType::from(ecp2); + let r#type = BuySellSignalType::from(body_engulfing); let date = today.date; BuySellSignal { r#type, date } }) - .collect_vec(); - ECP2s(vec) + .collect(); + BodyEngulfings(vec) } } @@ -114,13 +113,13 @@ mod tests { use chrono::NaiveDate; use pretty_assertions::assert_eq; + use crate::domain::models::body_engulfing::model::BodyEngulfings; use crate::domain::models::buy_sell_signal::model::tests::TupleVecBuySellSignal; use crate::domain::models::buy_sell_signal::model::{ BuySellSignal, BuySellSignalType::{Buy, Sell}, }; use crate::domain::models::candle_stick::model::CandleSticks; - use crate::domain::models::ecp2::model::ECP2s; use crate::domain::repositories::stock::queries; use crate::domain::repositories::stock::repository::Stock; use crate::infrastructure::dsv::Dsv; @@ -143,9 +142,9 @@ mod tests { MARUBOZU_WICK_MAX_RATIO, DOJI_MAX_BODY_RATIO, >::try_from(stocks.as_slice())?; - let vec_ecp2 = ECP2s::from(candle_sticks.as_slice()); + let body_engulfings = BodyEngulfings::from(candle_sticks.as_slice()); let (actual_buy, actual_sell): (Vec<_>, Vec<_>) = - TupleVecBuySellSignal::from(vec_ecp2.0.as_slice()).0; + TupleVecBuySellSignal::from(body_engulfings.0.as_slice()).0; let (expected_buy, expected_sell): (Vec, Vec) = ( vec![ BuySellSignal { diff --git a/src/domain/models/macos_analysis/close.rs b/src/domain/models/close.rs similarity index 100% rename from src/domain/models/macos_analysis/close.rs rename to src/domain/models/close.rs diff --git a/src/domain/models/close/model.rs b/src/domain/models/close/model.rs new file mode 100644 index 0000000..8293be9 --- /dev/null +++ b/src/domain/models/close/model.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct F64(pub f64); diff --git a/src/domain/models/crossover_strategy.rs b/src/domain/models/crossover_strategy.rs new file mode 100644 index 0000000..39dab9e --- /dev/null +++ b/src/domain/models/crossover_strategy.rs @@ -0,0 +1,7 @@ +pub(crate) mod analysis_pattern; +pub mod crossover_pattern; +pub mod latest_chance; +pub mod macd_cos; +pub mod rate_of_chance; +pub mod sma_cos; +pub mod sma_cps; diff --git a/src/domain/models/crossover_strategy/analysis_pattern.rs b/src/domain/models/crossover_strategy/analysis_pattern.rs new file mode 100644 index 0000000..d9a5251 --- /dev/null +++ b/src/domain/models/crossover_strategy/analysis_pattern.rs @@ -0,0 +1 @@ +pub(crate) mod model; diff --git a/src/domain/models/crossover_strategy/analysis_pattern/model.rs b/src/domain/models/crossover_strategy/analysis_pattern/model.rs new file mode 100644 index 0000000..c1c4483 --- /dev/null +++ b/src/domain/models/crossover_strategy/analysis_pattern/model.rs @@ -0,0 +1,67 @@ +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; + +/// A pair of `CrossoverPattern` and `rate_of_change` values. +pub(crate) struct CrossoverPatternRateOfChangePair { + pub crossover_pattern: CrossoverPattern, + pub rate_of_change: f64, +} + +/// Analysis with combination of Crossover pattern and rate_of_change +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] +pub enum AnalysisPattern { + #[default] + None, + GoldenChance, + DeadChance, + GoldenLoss, + DeadLoss, +} + +/// Converts a `PatternRateOfChangePair` into an `AnalysisPattern`. +/// +/// # Parameters +/// - `value: PatternRateOfChangePair` +/// The input object containing a `CrossoverPattern` (either `GoldenCross` or `DeadCross`) and a `rate_of_change` value for evaluation. +/// +/// # Returns +/// - `AnalysisPattern`: +/// - Returns `AnalysisPattern::GoldenChance` if the `CrossoverPattern` is `GoldenCross` and the `rate_of_change` is greater than `0.0`. +/// - Returns `AnalysisPattern::DeadChance` if the `CrossoverPattern` is `DeadCross` and the `rate_of_change` is less than `0.0`. +/// - Returns `AnalysisPattern::GoldenLoss` if the `CrossoverPattern` is `GoldenCross` and the `rate_of_change` is less than or equal to `0.0`. +/// - Returns `AnalysisPattern::DeadLoss` if the `CrossoverPattern` is `DeadCross` and the `rate_of_change` is greater than or equal to `0.0`. +/// - Returns `AnalysisPattern::None` if none of the above conditions are met. +/// +/// # Behavior +/// - The conversion logic evaluates both the `CrossoverPattern` and the `rate_of_change` value +/// based on specific conditions to determine the appropriate `AnalysisPattern` variant. +/// +/// # Notes +/// - This implementation provides a structured way to classify input `PatternRateOfChangePair` values into `AnalysisPattern` variants, +/// reflecting specific conditions of the pattern and its associated rate of change. +impl From for AnalysisPattern { + fn from(value: CrossoverPatternRateOfChangePair) -> Self { + match value { + // GoldenChance: GoldenPattern/rate_of_change > 0.0 + CrossoverPatternRateOfChangePair { + crossover_pattern: CrossoverPattern::GoldenCross, + rate_of_change: change, + } if change > 0.0 => AnalysisPattern::GoldenChance, + // DeadChance: DeadPattern/rate_of_change < 0.0 + CrossoverPatternRateOfChangePair { + crossover_pattern: CrossoverPattern::DeadCross, + rate_of_change: change, + } if change < 0.0 => AnalysisPattern::DeadChance, + // GoldenLoss: GoldenPattern/rate_of_change <= 0.0 + CrossoverPatternRateOfChangePair { + crossover_pattern: CrossoverPattern::GoldenCross, + rate_of_change: change, + } if change <= 0.0 => AnalysisPattern::GoldenLoss, + // DeadLoss: DeadPattern/rate_of_change >= 0.0 + CrossoverPatternRateOfChangePair { + crossover_pattern: CrossoverPattern::DeadCross, + rate_of_change: change, + } if change >= 0.0 => AnalysisPattern::DeadLoss, + _ => AnalysisPattern::None, + } + } +} diff --git a/src/domain/models/crossover_strategy/crossover_pattern.rs b/src/domain/models/crossover_strategy/crossover_pattern.rs new file mode 100644 index 0000000..7bec4e8 --- /dev/null +++ b/src/domain/models/crossover_strategy/crossover_pattern.rs @@ -0,0 +1,3 @@ +pub mod close; +pub mod model; +pub mod volume; diff --git a/src/domain/models/ecp2.rs b/src/domain/models/crossover_strategy/crossover_pattern/close.rs similarity index 100% rename from src/domain/models/ecp2.rs rename to src/domain/models/crossover_strategy/crossover_pattern/close.rs diff --git a/src/domain/models/crossover_strategy/crossover_pattern/close/model.rs b/src/domain/models/crossover_strategy/crossover_pattern/close/model.rs new file mode 100644 index 0000000..bdd64e2 --- /dev/null +++ b/src/domain/models/crossover_strategy/crossover_pattern/close/model.rs @@ -0,0 +1,4 @@ +use crate::domain::models::crossover_strategy::crossover_pattern; + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] +pub struct CrossoverPattern(pub crossover_pattern::model::CrossoverPattern); diff --git a/src/domain/models/crossover_strategy/crossover_pattern/model.rs b/src/domain/models/crossover_strategy/crossover_pattern/model.rs new file mode 100644 index 0000000..9014f3f --- /dev/null +++ b/src/domain/models/crossover_strategy/crossover_pattern/model.rs @@ -0,0 +1,41 @@ +use serde::{Deserialize, Serialize}; +use std::cmp::Ordering; +use strum::Display; + +/// 各移動平均線が交わったときの向きのパターン +#[derive( + Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default, Display, +)] +pub enum CrossoverPattern { + #[default] + Neither, + GoldenCross, + DeadCross, +} + +/// Creates a `CrossoverPattern` from a tuple of two `Option` values. +/// +/// # Parameters +/// - `value: (Option, Option)` +/// A tuple containing two optional `Ordering` values, which represent comparisons. +/// +/// # Returns +/// - `Pattern`: +/// - Returns `CrossoverPattern::GoldenCross` if the first value is `Some(Ordering::Less)` and the second is `Some(Ordering::Greater)`. +/// - Returns `CrossoverPattern::DeadCross` if the first value is `Some(Ordering::Greater)` and the second is `Some(Ordering::Less)`. +/// - Returns `CrossoverPattern::Neither` for all other cases. +/// +/// # Behavior +/// - The function pattern matches on the provided tuple of `Option` values to determine which `CrossoverPattern` variant to return. +/// +/// # Notes +/// - Provides a convenient way to map comparison results (`Ordering`) into a `CrossoverPattern` variant. +impl From<(Option, Option)> for CrossoverPattern { + fn from(value: (Option, Option)) -> Self { + match value { + (Some(Ordering::Less), Some(Ordering::Greater)) => Self::GoldenCross, + (Some(Ordering::Greater), Some(Ordering::Less)) => Self::DeadCross, + _ => Self::Neither, + } + } +} diff --git a/src/domain/models/macos_analysis/volume.rs b/src/domain/models/crossover_strategy/crossover_pattern/volume.rs similarity index 100% rename from src/domain/models/macos_analysis/volume.rs rename to src/domain/models/crossover_strategy/crossover_pattern/volume.rs diff --git a/src/domain/models/crossover_strategy/crossover_pattern/volume/model.rs b/src/domain/models/crossover_strategy/crossover_pattern/volume/model.rs new file mode 100644 index 0000000..bdd64e2 --- /dev/null +++ b/src/domain/models/crossover_strategy/crossover_pattern/volume/model.rs @@ -0,0 +1,4 @@ +use crate::domain::models::crossover_strategy::crossover_pattern; + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] +pub struct CrossoverPattern(pub crossover_pattern::model::CrossoverPattern); diff --git a/src/domain/models/macos.rs b/src/domain/models/crossover_strategy/latest_chance.rs similarity index 100% rename from src/domain/models/macos.rs rename to src/domain/models/crossover_strategy/latest_chance.rs diff --git a/src/domain/models/crossover_strategy/latest_chance/model.rs b/src/domain/models/crossover_strategy/latest_chance/model.rs new file mode 100644 index 0000000..0bd0de4 --- /dev/null +++ b/src/domain/models/crossover_strategy/latest_chance/model.rs @@ -0,0 +1,53 @@ +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern::{ + DeadCross, GoldenCross, Neither, +}; +use chrono::NaiveDate; + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] +pub struct LatestChance { + pub golden_cross: Option, + pub dead_cross: Option, +} + +impl From for CrossoverPattern { + fn from(value: LatestChance) -> Self { + let LatestChance { + golden_cross: latest_golden_chance, + dead_cross: latest_dead_chance, + } = value; + match (latest_golden_chance, latest_dead_chance) { + (Some(golden), Some(dead)) => { + if golden >= dead { + GoldenCross + } else { + DeadCross + } + } + (Some(_), None) => GoldenCross, + (None, Some(_)) => DeadCross, + _ => Neither, + } + } +} + +impl From for NaiveDate { + fn from(value: LatestChance) -> Self { + let LatestChance { + golden_cross: latest_golden_chance, + dead_cross: latest_dead_chance, + } = value; + match (latest_golden_chance, latest_dead_chance) { + (Some(golden), Some(dead)) => { + if golden >= dead { + golden + } else { + dead + } + } + (Some(golden), None) => golden, + (None, Some(dead)) => dead, + _ => NaiveDate::default(), + } + } +} diff --git a/src/domain/models/macps.rs b/src/domain/models/crossover_strategy/macd_cos.rs similarity index 100% rename from src/domain/models/macps.rs rename to src/domain/models/crossover_strategy/macd_cos.rs diff --git a/src/domain/models/crossover_strategy/macd_cos/model.rs b/src/domain/models/crossover_strategy/macd_cos/model.rs new file mode 100644 index 0000000..a74fc51 --- /dev/null +++ b/src/domain/models/crossover_strategy/macd_cos/model.rs @@ -0,0 +1,47 @@ +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; +use crate::domain::models::macd::model::{MACDs, MACD}; +use chrono::NaiveDate; +use deref_derive::{Deref, DerefMut}; +use rayon::prelude::*; + +/// MACD Crossover Strategy +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct MacdCos { + pub date: NaiveDate, + pub macd: f64, + pub signal: f64, + pub histogram: f64, + pub crossover_pattern: CrossoverPattern, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Deref, DerefMut)] +pub struct MacdCoses(Vec); + +impl From> for MacdCoses { + fn from(value: MACDs) -> Self { + let vec_macd_cos = value + .as_slice() + .par_windows(2) + .map(|windows| { + // 昨日と今日のMACDとシグナルの比較からクロスオーバーパターンを判定 + let yesterday = windows[0].macd.partial_cmp(&windows[0].signal); + let target = windows[1].macd.partial_cmp(&windows[1].signal); + let crossover_pattern = CrossoverPattern::from((yesterday, target)); + let MACD { + date, + macd, + signal, + histogram, + } = windows[1]; + MacdCos { + date, + macd, + signal, + histogram, + crossover_pattern, + } + }) + .collect::>(); + Self(vec_macd_cos) + } +} diff --git a/src/domain/models/msesp.rs b/src/domain/models/crossover_strategy/rate_of_chance.rs similarity index 100% rename from src/domain/models/msesp.rs rename to src/domain/models/crossover_strategy/rate_of_chance.rs diff --git a/src/domain/models/crossover_strategy/rate_of_chance/model.rs b/src/domain/models/crossover_strategy/rate_of_chance/model.rs new file mode 100644 index 0000000..20746dc --- /dev/null +++ b/src/domain/models/crossover_strategy/rate_of_chance/model.rs @@ -0,0 +1,6 @@ +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct RateOfChance { + pub whole: f64, + pub golden: f64, + pub dead: f64, +} diff --git a/src/domain/models/crossover_strategy/sma_cos.rs b/src/domain/models/crossover_strategy/sma_cos.rs new file mode 100644 index 0000000..35c181d --- /dev/null +++ b/src/domain/models/crossover_strategy/sma_cos.rs @@ -0,0 +1,2 @@ +pub(crate) mod analysis_result; +pub mod model; diff --git a/src/domain/models/macos_analysis.rs b/src/domain/models/crossover_strategy/sma_cos/analysis_result.rs similarity index 100% rename from src/domain/models/macos_analysis.rs rename to src/domain/models/crossover_strategy/sma_cos/analysis_result.rs diff --git a/src/domain/models/crossover_strategy/sma_cos/analysis_result/close.rs b/src/domain/models/crossover_strategy/sma_cos/analysis_result/close.rs new file mode 100644 index 0000000..d9a5251 --- /dev/null +++ b/src/domain/models/crossover_strategy/sma_cos/analysis_result/close.rs @@ -0,0 +1 @@ +pub(crate) mod model; diff --git a/src/domain/models/crossover_strategy/sma_cos/analysis_result/close/model.rs b/src/domain/models/crossover_strategy/sma_cos/analysis_result/close/model.rs new file mode 100644 index 0000000..ed975f3 --- /dev/null +++ b/src/domain/models/crossover_strategy/sma_cos/analysis_result/close/model.rs @@ -0,0 +1,201 @@ +use crate::domain::models::crossover_strategy::analysis_pattern::model::{ + AnalysisPattern, CrossoverPatternRateOfChangePair, +}; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern::Neither; +use crate::domain::models::crossover_strategy::latest_chance::model::LatestChance; +use crate::domain::models::crossover_strategy::rate_of_chance::model::RateOfChance; +use crate::domain::models::stocks_sma_coses_pair::model::StocksSmaCosesPair; +use crate::shared::float::percentage; +use chrono::NaiveDate; +use deref_derive::{Deref, DerefMut}; +use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; +use std::ops::{Mul, Sub}; + +/// 終値ベースの解析結果 +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct AnalysisResult { + /// Crossover発生日 + pub date_of_event: NaiveDate, + /// Crossover発生日の終値 + pub close: f64, + /// N日後の終値 + pub close_after_n_days: f64, + /// CrossoverPattern + pub pattern: CrossoverPattern, + /// 増減率 + pub rate_of_change: f64, + /// 分析パターン + pub analysis_pattern: AnalysisPattern, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] +pub struct AnalysisResults(Vec); + +impl<'a, const N: usize> From<&StocksSmaCosesPair<'a>> for AnalysisResults { + fn from(value: &StocksSmaCosesPair<'a>) -> Self { + let StocksSmaCosesPair { stocks, sma_coses } = value; + let vec_analysis_result: Vec = sma_coses + .par_iter() + .filter_map(|sma_cos| { + if sma_cos.crossover_pattern_close.0.eq(&Neither) { + return None; + } + // Crossoverが発生した日を特定 + let (stock, sma_cos) = stocks.par_iter().find_map_first(|stock| { + if stock.date.eq(&sma_cos.date) { + Some((stock, sma_cos)) + } else { + None + } + })?; + // n日後のStockを取得。stocksは営業日で並んでいる。 + let (stock, sma_cos, stock_after_n_days) = stocks + .par_iter() + .enumerate() + .find_first(|(_, stock)| stock.date.eq(&sma_cos.date)) + .and_then(|(index, _)| { + let stock_after_n_days = stocks.get(index + N)?; + Some((stock, sma_cos, stock_after_n_days)) + })?; + // 増減率を取得 + let rate_of_change = stock_after_n_days.close.sub(stock.close) / stock.close; + let rate_of_change = rate_of_change.mul(100.0); + let pattern_rate_of_change_pair = CrossoverPatternRateOfChangePair { + crossover_pattern: sma_cos.crossover_pattern_close.0, + rate_of_change, + }; + let analysis_pattern = AnalysisPattern::from(pattern_rate_of_change_pair); + Some(AnalysisResult { + date_of_event: sma_cos.date, + close: stock.close, + close_after_n_days: stock_after_n_days.close, + pattern: sma_cos.crossover_pattern_close.0, + rate_of_change, + analysis_pattern, + }) + }) + .collect(); + AnalysisResults::(vec_analysis_result) + } +} + +impl AnalysisResults { + pub fn rate_of_chance(&self) -> RateOfChance { + let count_golden_chance = self + .par_iter() + .filter(|analysis_result| { + matches!( + analysis_result.analysis_pattern, + AnalysisPattern::GoldenChance + ) + }) + .count(); + let count_golden_loss = self + .par_iter() + .filter(|analysis_result| { + matches!( + analysis_result.analysis_pattern, + AnalysisPattern::GoldenLoss + ) + }) + .count(); + let golden = percentage(count_golden_chance, count_golden_chance + count_golden_loss); + + let count_dead_chance = self + .par_iter() + .filter(|analysis_result| { + matches!( + analysis_result.analysis_pattern, + AnalysisPattern::DeadChance + ) + }) + .count(); + let count_dead_loss = self + .par_iter() + .filter(|analysis_result| { + matches!(analysis_result.analysis_pattern, AnalysisPattern::DeadLoss) + }) + .count(); + let dead = percentage(count_dead_chance, count_dead_chance + count_dead_loss); + + let whole = percentage(count_golden_chance + count_dead_chance, self.len()); + RateOfChance { + whole, + golden, + dead, + } + } + + fn find_latest_event(&self, target_pattern: &AnalysisPattern) -> Option { + self.par_iter() + .find_last(|analysis_result| analysis_result.analysis_pattern.eq(target_pattern)) + .map(|analysis_result| analysis_result.date_of_event) + } + + pub fn latest_chance(&self) -> LatestChance { + let golden_cross = self.find_latest_event(&AnalysisPattern::GoldenChance); + let dead_cross = self.find_latest_event(&AnalysisPattern::DeadChance); + LatestChance { + golden_cross, + dead_cross, + } + } +} + +#[cfg(test)] +mod tests { + use crate::domain::models::crossover_strategy::sma_cos::analysis_result::close::model::AnalysisResults; + use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; + use crate::domain::models::sma::model::{SMAListPair, SMAs}; + use crate::domain::models::stocks_sma_coses_pair::model::StocksSmaCosesPair; + use crate::domain::repositories::stock::queries; + use crate::domain::repositories::stock::repository::Stock; + use crate::infrastructure::dsv::Dsv; + use crate::infrastructure::repositories::stock::structures::internal::csv; + use anyhow::Result; + use bytes::Bytes; + use chrono::NaiveDate; + use pretty_assertions::assert_eq; + + const CSV: &[u8] = include_bytes!("../../../../../../../assets/8473.T.csv"); + + #[tokio::test] + async fn sma_cos_analysis_close_test() -> Result<()> { + let dsv = Dsv::::new(true, Bytes::from(CSV)); + let query = queries::get_stocks::Query { + ..Default::default() + }; + let stocks = dsv.get_stocks(&query).await?; + let smas_5 = SMAs::<5>::from(stocks.as_slice()); + let smas_25 = SMAs::<25>::from(stocks.as_slice()); + let sma_list_pair = SMAListPair { + smas_n: smas_5.as_slice(), + smas_o: smas_25.as_slice(), + }; + let sma_coses = SmaCoses::from(sma_list_pair); + let stocks_sma_coses_pair = StocksSmaCosesPair { + stocks: stocks.as_slice(), + sma_coses: sma_coses.as_slice(), + }; + // 3日後トレンドを取得 + let analysis_results = AnalysisResults::<3>::from(&stocks_sma_coses_pair); + let actual = 11; + assert_eq!(actual, analysis_results.len()); + + let rate_of_chance = analysis_results.rate_of_chance(); + let actual = 45.45454545454545; + assert_eq!(actual, rate_of_chance.whole); + let actual = 66.66666666666666; + assert_eq!(actual, rate_of_chance.golden); + let actual = 20.0; + assert_eq!(actual, rate_of_chance.dead); + + let latest_chance = analysis_results.latest_chance(); + let actual = NaiveDate::from_ymd_opt(2023, 8, 30); + assert_eq!(actual, latest_chance.golden_cross); + let actual = NaiveDate::from_ymd_opt(2023, 3, 14); + assert_eq!(actual, latest_chance.dead_cross); + Ok(()) + } +} diff --git a/src/domain/models/crossover_strategy/sma_cos/analysis_result/volume.rs b/src/domain/models/crossover_strategy/sma_cos/analysis_result/volume.rs new file mode 100644 index 0000000..d9a5251 --- /dev/null +++ b/src/domain/models/crossover_strategy/sma_cos/analysis_result/volume.rs @@ -0,0 +1 @@ +pub(crate) mod model; diff --git a/src/domain/models/crossover_strategy/sma_cos/analysis_result/volume/model.rs b/src/domain/models/crossover_strategy/sma_cos/analysis_result/volume/model.rs new file mode 100644 index 0000000..863e318 --- /dev/null +++ b/src/domain/models/crossover_strategy/sma_cos/analysis_result/volume/model.rs @@ -0,0 +1,86 @@ +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern::Neither; +use crate::domain::models::stocks_sma_coses_pair::model::StocksSmaCosesPair; +use chrono::NaiveDate; +use deref_derive::{Deref, DerefMut}; +use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; + +/// 出来高ベースの解析結果 +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct AnalysisResult { + /// Crossover発生日 + pub date_of_event: NaiveDate, + /// Crossover発生日の出来高 + pub volume: u64, + /// CrossoverPattern + pub pattern: CrossoverPattern, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] +pub struct AnalysisResults(Vec); + +impl<'a> From<&StocksSmaCosesPair<'a>> for AnalysisResults { + fn from(value: &StocksSmaCosesPair<'a>) -> Self { + let StocksSmaCosesPair { stocks, sma_coses } = value; + let vec_sma_cos_analysis_volume = sma_coses + .par_iter() + .filter_map(|sma_cos| { + // Neitherは判断材料とならないため結果から除外する + if sma_cos.crossover_pattern_volume.0.eq(&Neither) { + return None; + } + // Crossover発生日と同じ日の株価情報を取得 + let stock = stocks + .par_iter() + .find_first(|stock| stock.date.eq(&sma_cos.date))?; + Some(AnalysisResult { + date_of_event: stock.date, + volume: stock.volume, + pattern: sma_cos.crossover_pattern_volume.0, + }) + }) + .collect::>(); + AnalysisResults(vec_sma_cos_analysis_volume) + } +} + +#[cfg(test)] +mod tests { + use crate::domain::models::crossover_strategy::sma_cos::analysis_result::volume::model::AnalysisResults; + use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; + use crate::domain::models::sma::model::{SMAListPair, SMAs}; + use crate::domain::models::stocks_sma_coses_pair::model::StocksSmaCosesPair; + use crate::domain::repositories::stock::queries; + use crate::domain::repositories::stock::repository::Stock; + use crate::infrastructure::dsv::Dsv; + use crate::infrastructure::repositories::stock::structures::internal::csv; + use anyhow::Result; + use bytes::Bytes; + use pretty_assertions::assert_eq; + + const CSV: &[u8] = include_bytes!("../../../../../../../assets/8473.T.csv"); + + #[tokio::test] + async fn sma_cos_analysis_volume_test() -> Result<()> { + let dsv = Dsv::::new(true, Bytes::from(CSV)); + let query = queries::get_stocks::Query { + ..Default::default() + }; + let stocks = dsv.get_stocks(&query).await?; + let smas_5 = SMAs::<5>::from(stocks.as_slice()); + let smas_25 = SMAs::<25>::from(stocks.as_slice()); + let sma_list_pair = SMAListPair { + smas_n: smas_5.as_slice(), + smas_o: smas_25.as_slice(), + }; + let sma_coses = SmaCoses::from(sma_list_pair); + let stocks_sma_coses_pair = StocksSmaCosesPair { + stocks: stocks.as_slice(), + sma_coses: sma_coses.as_slice(), + }; + let sma_cos_analysis_volumes = AnalysisResults::from(&stocks_sma_coses_pair); + let actual = 33; + assert_eq!(actual, sma_cos_analysis_volumes.len()); + Ok(()) + } +} diff --git a/src/domain/models/crossover_strategy/sma_cos/model.rs b/src/domain/models/crossover_strategy/sma_cos/model.rs new file mode 100644 index 0000000..84e611d --- /dev/null +++ b/src/domain/models/crossover_strategy/sma_cos/model.rs @@ -0,0 +1,197 @@ +use crate::domain::models::crossover_strategy::crossover_pattern; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; +use crate::domain::models::sma::model::{SMAListPair, SMAPair}; +use crate::domain::models::{close, volume}; +use chrono::NaiveDate; +use deref_derive::{Deref, DerefMut}; +use rayon::prelude::*; +use std::cmp::Ordering; + +/// SimpleMovingAverageCrossoverStrategy +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct SmaCos { + pub date: NaiveDate, + pub close_25: Option, + pub volume_25: Option, + pub crossover_pattern_close: crossover_pattern::close::model::CrossoverPattern, + pub crossover_pattern_volume: crossover_pattern::volume::model::CrossoverPattern, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] +pub struct SmaCoses(Vec); + +impl SmaCoses { + /// Retrieves the latest date based on the closing value that matches a specified pattern. + /// + /// # Parameters + /// - `crossover_pattern: &CrossoverPattern` + /// A reference to the `CrossoverPattern` object used to match against the `close` value + /// in the `pattern_close_volume` of each `SmaCos` item. + /// + /// # Returns + /// - `Option`: + /// - Returns `Some(date)` if one or more `SmaCos` objects match the given pattern, where `date` is the latest matching date. + /// - Returns `None` if no matches are found. + /// + /// # Process + /// - The method uses parallel iteration (`par_iter`) for efficiency when traversing the `MACOSES` collection. + /// - It filters `SmaCos` objects where the `close` field of `pattern_close_volume` equals the given `CrossoverPattern`. + /// - The filtered results are then sorted by the `date` field in ascending order. + /// - Finally, the latest date (if any) is extracted and returned. + /// + /// # Notes + /// - This method leverages the `rayon` library for parallel processing, ideal for handling large datasets. + /// - Sorting is done using `itertools`'s `sorted_by` for a clear and concise sorting step. + pub fn latest_based_on_close(&self, crossover_pattern: &CrossoverPattern) -> Option { + self.par_iter() + .filter_map(|sma_cos| { + if sma_cos.crossover_pattern_close.0.eq(crossover_pattern) { + Some(sma_cos) + } else { + None + } + }) + .max_by(|a, b| Ord::cmp(&a.date, &b.date)) + .map(|x| x.date) + } +} + +impl<'a> From> for SmaCoses { + /// + /// # Examples + /// ``` + /// use bytes::Bytes; + /// use rayon::prelude::*; + /// + /// use quantitative_data_analysis_rs::domain::models::sma::model::{SMAListPair, SMAs}; + /// use quantitative_data_analysis_rs::domain::models::stock::model; + /// use quantitative_data_analysis_rs::domain::models::crossover_strategy::sma_cos::model::SmaCoses; + /// use quantitative_data_analysis_rs::domain::repositories::stock::queries; + /// use quantitative_data_analysis_rs::domain::repositories::stock::repository::Stock; + /// use quantitative_data_analysis_rs::infrastructure::dsv::Dsv; + /// use quantitative_data_analysis_rs::infrastructure::repositories::stock::structures::internal::csv; + /// + /// const CSV: &[u8] = include_bytes!("../../../../../assets/8473.T.csv"); + /// + /// tokio_test::block_on(async { + /// let dsv = Dsv::::new(true, Bytes::from(CSV)); + /// let query = queries::get_stocks::Query { + /// ..Default::default() + /// }; + /// let stocks = dsv.get_stocks(&query).await.unwrap(); + /// let smas_5 = SMAs::<5>::from(stocks.as_slice()); + /// let smas_25 = SMAs::<25>::from(stocks.as_slice()); + /// let sma_list_pair = SMAListPair { + /// smas_n: smas_5.as_slice(), + /// smas_o: smas_25.as_slice(), + /// }; + /// let sma_coses = SmaCoses::from(sma_list_pair); + /// assert_eq!(sma_coses.len(), 241); + /// }); + /// ``` + fn from(value: SMAListPair<'a, 5, 25>) -> Self { + let SMAListPair { + smas_n: smas_5, + smas_o: smas_25, + } = value; + let vec_sma_cos = smas_5 + .par_iter() + .map(|sma_5| { + let sma_25 = smas_25 + .par_iter() + .find_first(|sma_25| sma_25.date.eq(&sma_5.date)); + let sma_pair = SMAPair { + sma_n: sma_5, + sma_o: sma_25, + }; + let ordering_close_volume = OrderingCloseVolume::from(sma_pair); + let (close, volume) = match sma_25 { + Some(sma_25) => (Some(sma_25.close), Some(sma_25.volume)), + None => (None, None), + }; + (sma_5.date, close, volume, ordering_close_volume) + }) + .collect::, + Option, + OrderingCloseVolume, + )>>() + .par_windows(2) + .map(|windows| { + let &(_, _, _, yesterday_ordering_close_volume) = &windows[0]; + let &(target, target_close, target_volume, target_ordering_close_volume) = + &windows[1]; + let ordering_close_volume_pair = OrderingCloseVolumePair { + past: yesterday_ordering_close_volume, + target: target_ordering_close_volume, + }; + let CrossoverPatternCloseVolume { + close: crossover_pattern_close, + volume: crossover_pattern_volume, + } = CrossoverPatternCloseVolume::from(ordering_close_volume_pair); + SmaCos { + date: target, + close_25: target_close, + volume_25: target_volume, + crossover_pattern_close: crossover_pattern::close::model::CrossoverPattern( + crossover_pattern_close, + ), + crossover_pattern_volume: crossover_pattern::volume::model::CrossoverPattern( + crossover_pattern_volume, + ), + } + }) + .collect::>(); + Self(vec_sma_cos) + } +} + +/// 終値ベース、出来高ベースそれぞれの大小関係 +/// 対象日が片方なかったなど比較出来なかった場合は、None +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] +struct OrderingCloseVolume { + /// 終値ベースの比較値 + pub close: Option, + /// 取引高ベースの比較値 + pub volume: Option, +} + +impl<'a, const N: usize, const O: usize> From> for OrderingCloseVolume { + fn from(value: SMAPair<'a, N, O>) -> Self { + let SMAPair { sma_n, sma_o } = value; + match (sma_n, sma_o) { + (sma_n, Some(sma_o)) => { + let close = sma_n.close.0.partial_cmp(&sma_o.close.0); + let volume = sma_n.volume.0.partial_cmp(&sma_o.volume.0); + OrderingCloseVolume { close, volume } + } + (_, _) => OrderingCloseVolume::default(), + } + } +} + +struct OrderingCloseVolumePair { + pub past: OrderingCloseVolume, + pub target: OrderingCloseVolume, +} + +/// 終値・取引高における各移動平均線が交わったときの向きのパターンのセット +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] +pub struct CrossoverPatternCloseVolume { + /// 終値ベースのMACOSのパターン + pub close: CrossoverPattern, + /// 出来高ベースのMACOSのパターン + pub volume: CrossoverPattern, +} + +impl From for CrossoverPatternCloseVolume { + fn from(value: OrderingCloseVolumePair) -> Self { + // 前日と対象日の大小関係を比較して、ゴールデンクロスかデッドクロスかどちらも発生していないかを判定していく。 + // https://myfrankblog.com/find_golden_cross_and_dead_cross_by_python/#i-4 + let OrderingCloseVolumePair { past, target } = value; + let close = CrossoverPattern::from((past.close, target.close)); + let volume = CrossoverPattern::from((past.volume, target.volume)); + CrossoverPatternCloseVolume { close, volume } + } +} diff --git a/src/domain/models/stocks_macoses_pair.rs b/src/domain/models/crossover_strategy/sma_cps.rs similarity index 100% rename from src/domain/models/stocks_macoses_pair.rs rename to src/domain/models/crossover_strategy/sma_cps.rs diff --git a/src/domain/models/macps/model.rs b/src/domain/models/crossover_strategy/sma_cps/model.rs similarity index 80% rename from src/domain/models/macps/model.rs rename to src/domain/models/crossover_strategy/sma_cps/model.rs index 76a6328..23375ac 100644 --- a/src/domain/models/macps/model.rs +++ b/src/domain/models/crossover_strategy/sma_cps/model.rs @@ -1,14 +1,13 @@ -use rayon::prelude::*; - use crate::domain::models::buy_sell_signal::model::{BuySellSignal, BuySellSignalType}; use crate::domain::models::sma::model::SMAListTrio; use crate::domain::models::stock::model::Stock; use chrono::NaiveDate; +use rayon::prelude::*; use std::cmp::Ordering; -/// MovingAverageComparisonStrategy +/// SimpleMovingAverageComparisonStrategy #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct MACPS { +pub struct SmaCps { pub buy: Option, pub sell: Option, } @@ -17,11 +16,11 @@ impl From<(Option, Option, Option)> for BuySellSig fn from(value: (Option, Option, Option)) -> Self { let (cmp1, cmp2, cmp3) = value; match (cmp1, cmp2, cmp3) { - // current close < 5day sma < 25day sma < 50day sma → Buy + // current close < 5day SMA < 25day SMA < 50day SMA → Buy (Some(Ordering::Less), Some(Ordering::Less), Some(Ordering::Less)) => { BuySellSignalType::Buy } - // current close > 5day sma > 25day sma > 50day sma → Sell + // current close > 5day SMA > 25day SMA > 50day SMA → Sell (Some(Ordering::Greater), Some(Ordering::Greater), Some(Ordering::Greater)) => { BuySellSignalType::Sell } @@ -30,7 +29,7 @@ impl From<(Option, Option, Option)> for BuySellSig } } -impl<'a> From<(&[Stock], SMAListTrio<'a, 5, 25, 50>)> for MACPS { +impl<'a> From<(&[Stock], SMAListTrio<'a, 5, 25, 50>)> for SmaCps { /// /// # Examples /// ``` @@ -38,7 +37,7 @@ impl<'a> From<(&[Stock], SMAListTrio<'a, 5, 25, 50>)> for MACPS { /// use chrono::NaiveDate; /// use rayon::prelude::*; /// - /// use quantitative_data_analysis_rs::domain::models::macps::model::MACPS; + /// use quantitative_data_analysis_rs::domain::models::crossover_strategy::sma_cps::model::SmaCps; /// use quantitative_data_analysis_rs::domain::models::sma::model::{SMAListTrio, SMAs}; /// use quantitative_data_analysis_rs::domain::models::stock::model; /// use quantitative_data_analysis_rs::domain::repositories::stock::queries; @@ -46,7 +45,7 @@ impl<'a> From<(&[Stock], SMAListTrio<'a, 5, 25, 50>)> for MACPS { /// use quantitative_data_analysis_rs::infrastructure::dsv::Dsv; /// use quantitative_data_analysis_rs::infrastructure::repositories::stock::structures::internal::csv; /// - /// const CSV: &[u8] = include_bytes!("../../../../assets/8473.T.csv"); + /// const CSV: &[u8] = include_bytes!("../../../../../assets/8473.T.csv"); /// /// tokio_test::block_on(async { /// let dsv = Dsv::::new(true, Bytes::from(CSV)); @@ -62,8 +61,8 @@ impl<'a> From<(&[Stock], SMAListTrio<'a, 5, 25, 50>)> for MACPS { /// smas_o: smas_25.as_slice(), /// smas_p: smas_50.as_slice(), /// }; - /// let macps = MACPS::from((stocks.as_slice(), sma_list_trio)); - /// assert_eq!(macps, MACPS { buy: NaiveDate::from_ymd_opt(2023, 4, 10), sell: NaiveDate::from_ymd_opt(2023, 9, 8) }); + /// let sma_cps = SmaCps::from((stocks.as_slice(), sma_list_trio)); + /// assert_eq!(sma_cps, SmaCps { buy: NaiveDate::from_ymd_opt(2023, 4, 10), sell: NaiveDate::from_ymd_opt(2023, 9, 8) }); /// }); /// ``` fn from(value: (&[Stock], SMAListTrio<'a, 5, 25, 50>)) -> Self { @@ -82,9 +81,9 @@ impl<'a> From<(&[Stock], SMAListTrio<'a, 5, 25, 50>)> for MACPS { let sma_n = smas_n.par_iter().find_first(|sma_n| sma_n.date.eq(&date))?; let sma_o = smas_o.par_iter().find_first(|sma_o| sma_o.date.eq(&date))?; let sma_p = smas_p.par_iter().find_first(|sma_p| sma_p.date.eq(&date))?; - let cmp1 = stock.close.partial_cmp(&sma_n.sma_n.close); - let cmp2 = sma_n.sma_n.close.partial_cmp(&sma_o.sma_n.close); - let cmp3 = sma_o.sma_n.close.partial_cmp(&sma_p.sma_n.close); + let cmp1 = stock.close.partial_cmp(&sma_n.close.0); + let cmp2 = sma_n.close.0.partial_cmp(&sma_o.close.0); + let cmp3 = sma_o.close.0.partial_cmp(&sma_p.close.0); let r#type = BuySellSignalType::from((cmp1, cmp2, cmp3)); let r#type = r#type.ne(&BuySellSignalType::Stay).then_some(r#type)?; Some(BuySellSignal { date, r#type }) diff --git a/src/domain/models/high_low_direction_signal.rs b/src/domain/models/high_low_direction_signal.rs new file mode 100644 index 0000000..65880be --- /dev/null +++ b/src/domain/models/high_low_direction_signal.rs @@ -0,0 +1 @@ +pub mod model; diff --git a/src/domain/models/ecp1/model.rs b/src/domain/models/high_low_direction_signal/model.rs similarity index 84% rename from src/domain/models/ecp1/model.rs rename to src/domain/models/high_low_direction_signal/model.rs index 838228f..d13bc61 100644 --- a/src/domain/models/ecp1/model.rs +++ b/src/domain/models/high_low_direction_signal/model.rs @@ -1,26 +1,25 @@ -use deref_derive::{Deref, DerefMut}; -use itertools::Itertools; -use std::cmp::Ordering; - use crate::domain::models::buy_sell_signal::model::{BuySellSignal, BuySellSignalType}; use crate::domain::models::stock::model::Stock; +use deref_derive::{Deref, DerefMut}; +use rayon::prelude::*; +use std::cmp::Ordering; #[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct ECP1 { +pub struct HighLowDirectionSignal { low_ordering: Option, high_ordering: Option, } -/// Engulfing Candlestick Pattern1 +/// High Low Direction Signal /// -/// ある日とその前日の安値・高値の切り上がり・切り下がりをみる +/// ある日とその前日の安値・高値の切り上がり・切り下がりをみて、価格レンジのトレンド方向のシグナルを出す /// /// * **Buy**: 安値切り上がりかつ高値切り上がり /// * **Sell**: 安値切り下がりかつ高値切り下がり /// * **Stay**: 上記のどちらにもあてはまならない -impl From for BuySellSignalType { - fn from(value: ECP1) -> Self { - let ECP1 { +impl From for BuySellSignalType { + fn from(value: HighLowDirectionSignal) -> Self { + let HighLowDirectionSignal { low_ordering, high_ordering, } = value; @@ -33,15 +32,15 @@ impl From for BuySellSignalType { } #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Deref, DerefMut)] -pub struct ECP1s(Vec); +pub struct HighLowDirectionSignals(Vec); -impl From<&[Stock]> for ECP1s { +impl From<&[Stock]> for HighLowDirectionSignals { /// /// # Examples /// ``` /// use bytes::Bytes; /// - /// use quantitative_data_analysis_rs::domain::models::ecp1::model::ECP1s; + /// use quantitative_data_analysis_rs::domain::models::high_low_direction_signal::model::HighLowDirectionSignals; /// use quantitative_data_analysis_rs::domain::models::stock::model; /// use quantitative_data_analysis_rs::domain::repositories::stock::queries; /// use quantitative_data_analysis_rs::domain::repositories::stock::repository::Stock; @@ -56,13 +55,13 @@ impl From<&[Stock]> for ECP1s { /// ..Default::default() /// }; /// let stocks = dsv.get_stocks(&query).await.unwrap(); - /// let ecp1s = ECP1s::from(stocks.as_slice()); - /// assert_eq!(ecp1s.len(), 34); + /// let high_low_direction_signals = HighLowDirectionSignals::from(stocks.as_slice()); + /// assert_eq!(high_low_direction_signals.len(), 34); /// }); /// ``` fn from(value: &[Stock]) -> Self { - let vec_buy_sell_signal = value - .windows(2) + let vec_high_low_direction_signal = value + .par_windows(2) .map(|stock| { let prev = stock.first().unwrap(); let today = stock.get(1).unwrap(); @@ -70,17 +69,17 @@ impl From<&[Stock]> for ECP1s { let low_ordering = today.low.partial_cmp(&prev.low); // 前日・当日それぞれの高値を比較する let high_ordering = today.high.partial_cmp(&prev.high); - let ecp1 = ECP1 { + let high_low_direction_signal = HighLowDirectionSignal { low_ordering, high_ordering, }; // 高値・安値の切り上げ・切り下げを基にした売買シグナル - let r#type = BuySellSignalType::from(ecp1); + let r#type = BuySellSignalType::from(high_low_direction_signal); let date = today.date; BuySellSignal { r#type, date } }) - .collect_vec(); - ECP1s(vec_buy_sell_signal) + .collect(); + HighLowDirectionSignals(vec_high_low_direction_signal) } } @@ -96,7 +95,7 @@ mod tests { BuySellSignal, BuySellSignalType::{Buy, Sell}, }; - use crate::domain::models::ecp1::model::ECP1s; + use crate::domain::models::high_low_direction_signal::model::HighLowDirectionSignals; use crate::domain::repositories::stock::queries; use crate::domain::repositories::stock::repository::Stock; use crate::infrastructure::dsv::Dsv; @@ -111,9 +110,9 @@ mod tests { ..Default::default() }; let stocks = dsv.get_stocks(&query).await?; - let ecp1s = ECP1s::from(stocks.as_slice()); + let high_low_direction_signals = HighLowDirectionSignals::from(stocks.as_slice()); let (actual_buy, actual_sell): (Vec<_>, Vec<_>) = - TupleVecBuySellSignal::from(ecp1s.as_slice()).0; + TupleVecBuySellSignal::from(high_low_direction_signals.as_slice()).0; let (expected_buy, expected_sell): (Vec, Vec) = ( vec![ BuySellSignal { diff --git a/src/domain/models/macd.rs b/src/domain/models/macd.rs new file mode 100644 index 0000000..65880be --- /dev/null +++ b/src/domain/models/macd.rs @@ -0,0 +1 @@ +pub mod model; diff --git a/src/domain/models/macd/model.rs b/src/domain/models/macd/model.rs new file mode 100644 index 0000000..8ac5886 --- /dev/null +++ b/src/domain/models/macd/model.rs @@ -0,0 +1,62 @@ +use crate::domain::models::stock::model::Stock; +use chrono::NaiveDate; +use deref_derive::{Deref, DerefMut}; +use ta::indicators::MovingAverageConvergenceDivergence; +use ta::Next; + +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct MACD { + pub date: NaiveDate, + pub macd: f64, + pub signal: f64, + pub histogram: f64, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] +pub struct MACDs(Vec); + +/// # Examples +/// ``` +/// use bytes::Bytes; +/// use quantitative_data_analysis_rs::domain::models::macd::model::MACDs; +/// use quantitative_data_analysis_rs::domain::models::stock::model; +/// use quantitative_data_analysis_rs::domain::repositories::stock::queries; +/// use quantitative_data_analysis_rs::domain::repositories::stock::repository::Stock; +/// use quantitative_data_analysis_rs::infrastructure::dsv::Dsv; +/// use quantitative_data_analysis_rs::infrastructure::repositories::stock::structures::internal::csv; +/// +/// const FAST_PERIOD: usize = 12; +/// const SLOW_PERIOD: usize = 26; +/// const SIGNAL_PERIOD: usize = 9; +/// const CSV: &[u8] = include_bytes!("../../../../assets/9223.T.csv"); +/// +/// tokio_test::block_on(async { +/// let dsv = Dsv::::new(true, Bytes::from(CSV)); +/// let query = queries::get_stocks::Query { +/// ..Default::default() +/// }; +/// let stocks = dsv.get_stocks(&query).await.unwrap(); +/// let macds = MACDs::::try_from(stocks.as_slice()).unwrap(); +/// assert_eq!(macds.len(), 35); +/// }); +/// ``` +impl TryFrom<&[Stock]> for MACDs { + type Error = anyhow::Error; + + fn try_from(value: &[Stock]) -> Result { + let mut macd = MovingAverageConvergenceDivergence::new(F, S, SG)?; + let macds = value + .iter() + .map(|stock| { + let (macd, signal, histogram) = macd.next(stock.close).into(); + MACD { + date: stock.date, + macd, + signal, + histogram, + } + }) + .collect::>(); + Ok(MACDs(macds)) + } +} diff --git a/src/domain/models/macos/model.rs b/src/domain/models/macos/model.rs deleted file mode 100644 index 7fe4a97..0000000 --- a/src/domain/models/macos/model.rs +++ /dev/null @@ -1,294 +0,0 @@ -use crate::domain::models::sma::model::{SMAListPair, SMAPair, SMASet}; -use chrono::NaiveDate; -use deref_derive::{Deref, DerefMut}; -use rayon::prelude::*; -use serde::{Deserialize, Serialize}; -use std::cmp::Ordering; -use strum::Display; - -/// MovingAverageCrossoverStrategy -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct MACOS { - pub date: NaiveDate, - pub sma_set_25: Option>, - pub pattern_close_volume: PatternCloseVolume, -} - -/// 終値・取引高における各移動平均線が交わったときの向きのパターンのセット -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] -pub struct PatternCloseVolume { - /// 終値ベースのMACOSのパターン - pub close: Pattern, - /// 出来高ベースのMACOSのパターン - pub volume: Pattern, -} - -/// 各移動平均線が交わったときの向きのパターン -#[derive( - Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default, Display, -)] -pub enum Pattern { - #[default] - Neither, - /// GoldenCross - GoldenCross, - /// DeadCross - DeadCross, -} - -/// Creates a `Pattern` from a tuple of two `Option` values. -/// -/// # Parameters -/// - `value: (Option, Option)` -/// A tuple containing two optional `Ordering` values, which represent comparisons. -/// -/// # Returns -/// - `Pattern`: -/// - Returns `Pattern::Golden` if the first value is `Some(Ordering::Less)` and the second is `Some(Ordering::Greater)`. -/// - Returns `Pattern::Dead` if the first value is `Some(Ordering::Greater)` and the second is `Some(Ordering::Less)`. -/// - Returns `Pattern::Neither` for all other cases. -/// -/// # Behavior -/// - The function pattern matches on the provided tuple of `Option` values to determine which `Pattern` variant to return. -/// -/// # Notes -/// - Provides a convenient way to map comparison results (`Ordering`) into a `Pattern` variant. -impl From<(Option, Option)> for Pattern { - fn from(value: (Option, Option)) -> Self { - match value { - (Some(Ordering::Less), Some(Ordering::Greater)) => Self::GoldenCross, - (Some(Ordering::Greater), Some(Ordering::Less)) => Self::DeadCross, - _ => Self::Neither, - } - } -} - -/// MACOS trend_analysis_summary pattern -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] -pub enum AnalysisPattern { - #[default] - None, - GoldenChance, - DeadChance, - GoldenLoss, - DeadLoss, -} - -/// A pair of `Pattern` and `rate_of_change` values. -pub(crate) struct PatternRateOfChangePair { - pub pattern: Pattern, - pub rate_of_change: f64, -} - -/// Converts a `PatternRateOfChangePair` into an `AnalysisPattern`. -/// -/// # Parameters -/// - `value: PatternRateOfChangePair` -/// The input object containing a `Pattern` (either `Golden` or `Dead`) and a `rate_of_change` value for evaluation. -/// -/// # Returns -/// - `AnalysisPattern`: -/// - Returns `AnalysisPattern::GoldenChance` if the `Pattern` is `Golden` and the `rate_of_change` is greater than `0.0`. -/// - Returns `AnalysisPattern::DeadChance` if the `Pattern` is `Dead` and the `rate_of_change` is less than `0.0`. -/// - Returns `AnalysisPattern::GoldenLoss` if the `Pattern` is `Golden` and the `rate_of_change` is less than or equal to `0.0`. -/// - Returns `AnalysisPattern::DeadLoss` if the `Pattern` is `Dead` and the `rate_of_change` is greater than or equal to `0.0`. -/// - Returns `AnalysisPattern::None` if none of the above conditions are met. -/// -/// # Behavior -/// - The conversion logic evaluates both the `Pattern` and the `rate_of_change` value -/// based on specific conditions to determine the appropriate `AnalysisPattern` variant. -/// -/// # Notes -/// - This implementation provides a structured way to classify input `PatternRateOfChangePair` values into `AnalysisPattern` variants, -/// reflecting specific conditions of the pattern and its associated rate of change. -impl From for AnalysisPattern { - fn from(value: PatternRateOfChangePair) -> Self { - match value { - // GoldenChance: GoldenPattern/rate_of_change > 0.0 - PatternRateOfChangePair { - pattern: Pattern::GoldenCross, - rate_of_change: change, - } if change > 0.0 => AnalysisPattern::GoldenChance, - // DeadChance: DeadPattern/rate_of_change < 0.0 - PatternRateOfChangePair { - pattern: Pattern::DeadCross, - rate_of_change: change, - } if change < 0.0 => AnalysisPattern::DeadChance, - // GoldenLoss: GoldenPattern/rate_of_change <= 0.0 - PatternRateOfChangePair { - pattern: Pattern::GoldenCross, - rate_of_change: change, - } if change <= 0.0 => AnalysisPattern::GoldenLoss, - // DeadLoss: DeadPattern/rate_of_change >= 0.0 - PatternRateOfChangePair { - pattern: Pattern::DeadCross, - rate_of_change: change, - } if change >= 0.0 => AnalysisPattern::DeadLoss, - _ => AnalysisPattern::None, - } - } -} - -#[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] -pub struct MACOSes(Vec); - -impl MACOSes { - /// Retrieves the latest date based on the closing value that matches a specified pattern. - /// - /// # Parameters - /// - `pattern: &Pattern` - /// A reference to the `Pattern` object used to match against the `close` value - /// in the `pattern_close_volume` of each `MACOS` item. - /// - /// # Returns - /// - `Option`: - /// - Returns `Some(date)` if one or more `MACOS` objects match the given pattern, where `date` is the latest matching date. - /// - Returns `None` if no matches are found. - /// - /// # Process - /// - The method uses parallel iteration (`par_iter`) for efficiency when traversing the `MACOSES` collection. - /// - It filters `MACOS` objects where the `close` field of `pattern_close_volume` equals the given `Pattern`. - /// - The filtered results are then sorted by the `date` field in ascending order. - /// - Finally, the latest date (if any) is extracted and returned. - /// - /// # Notes - /// - This method leverages the `rayon` library for parallel processing, ideal for handling large datasets. - /// - Sorting is done using `itertools`'s `sorted_by` for a clear and concise sorting step. - pub fn latest_based_on_close(&self, pattern: &Pattern) -> Option { - self.par_iter() - .filter_map(|macos| { - if macos.pattern_close_volume.close.eq(pattern) { - Some(*macos) - } else { - None - } - }) - .max_by(|a, b| Ord::cmp(&a.date, &b.date)) - .map(|x| x.date) - } -} - -struct Intermediate { - date: NaiveDate, - sma_set_25: Option>, - ordering_close_volume_5_25: OrderingCloseVolume<5, 25>, -} - -impl<'a> From> for MACOSes { - /// - /// # Examples - /// ``` - /// use bytes::Bytes; - /// use rayon::prelude::*; - /// - /// use quantitative_data_analysis_rs::domain::models::sma::model::{SMAListPair, SMAs}; - /// use quantitative_data_analysis_rs::domain::models::macos::model::MACOSes; - /// use quantitative_data_analysis_rs::domain::models::stock::model; - /// use quantitative_data_analysis_rs::domain::repositories::stock::queries; - /// use quantitative_data_analysis_rs::domain::repositories::stock::repository::Stock; - /// use quantitative_data_analysis_rs::infrastructure::dsv::Dsv; - /// use quantitative_data_analysis_rs::infrastructure::repositories::stock::structures::internal::csv; - /// - /// const CSV: &[u8] = include_bytes!("../../../../assets/8473.T.csv"); - /// - /// tokio_test::block_on(async { - /// let dsv = Dsv::::new(true, Bytes::from(CSV)); - /// let query = queries::get_stocks::Query { - /// ..Default::default() - /// }; - /// let stocks = dsv.get_stocks(&query).await.unwrap(); - /// let smas_5 = SMAs::<5>::from(stocks.as_slice()); - /// let smas_25 = SMAs::<25>::from(stocks.as_slice()); - /// let sma_list_pair = SMAListPair { - /// smas_n: smas_5.as_slice(), - /// smas_o: smas_25.as_slice(), - /// }; - /// let macoses = MACOSes::from(sma_list_pair); - /// assert_eq!(macoses.len(), 241); - /// }); - /// ``` - fn from(value: SMAListPair<'a, 5, 25>) -> Self { - let SMAListPair { - smas_n: smas_5, - smas_o: smas_25, - } = value; - let intermediates: Vec = smas_5 - .par_iter() - .map(|sma_5| { - let sma_25 = smas_25 - .par_iter() - .find_first(|sma_25| sma_5.date.eq(&sma_25.date)); - let sma_pair = SMAPair { - sma_n: sma_5, - sma_o: sma_25, - }; - let ordering_close_volume_5_25 = OrderingCloseVolume::from(sma_pair); - Intermediate { - date: sma_5.date, - sma_set_25: sma_25.map(|sma_25| sma_25.sma_n), - ordering_close_volume_5_25, - } - }) - .collect(); - let vec_macos = intermediates - .par_windows(2) - .map(|x| { - let yesterday = x[0].ordering_close_volume_5_25; - let today = x[1].ordering_close_volume_5_25; - let ordering_close_volume_pair = OrderingCloseVolumePastFuture { - past: yesterday, - future: today, - }; - let pattern_close_volume = PatternCloseVolume::from(ordering_close_volume_pair); - MACOS { - date: x[1].date, - sma_set_25: x[1].sma_set_25, - pattern_close_volume, - } - }) - .collect::>(); - Self(vec_macos) - } -} - -/// 終値ベース、出来高ベースそれぞれの大小関係 -/// 対象日が片方なかったなど比較出来なかった場合は、None -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] -pub struct OrderingCloseVolume { - /// 終値ベースの比較値 - pub close: Option, - /// 取引高ベースの比較値 - pub volume: Option, -} - -impl<'a, const N: usize, const O: usize> From> for OrderingCloseVolume { - fn from(value: SMAPair<'a, N, O>) -> Self { - let SMAPair { sma_n, sma_o } = value; - match (sma_n, sma_o) { - (sma_n, Some(sma_o)) => { - let close = sma_n.sma_n.close.partial_cmp(&sma_o.sma_n.close); - let volume = sma_n.sma_n.volume.partial_cmp(&sma_o.sma_n.volume); - OrderingCloseVolume:: { close, volume } - } - (_, _) => OrderingCloseVolume::::default(), - } - } -} - -struct OrderingCloseVolumePastFuture { - past: OrderingCloseVolume, - future: OrderingCloseVolume, -} - -impl From> - for PatternCloseVolume -{ - fn from(value: OrderingCloseVolumePastFuture) -> Self { - // 前日と対象日の大小関係を比較して、ゴールデンクロスかデッドクロスかどちらも発生していないかを判定していく。 - // https://myfrankblog.com/find_golden_cross_and_dead_cross_by_python/#i-4 - let OrderingCloseVolumePastFuture { past, future } = value; - let close = Pattern::from((past.close, future.close)); - let volume = Pattern::from((past.volume, future.volume)); - PatternCloseVolume { close, volume } - } -} diff --git a/src/domain/models/macos_analysis/close/model.rs b/src/domain/models/macos_analysis/close/model.rs deleted file mode 100644 index 0d3ecb8..0000000 --- a/src/domain/models/macos_analysis/close/model.rs +++ /dev/null @@ -1,259 +0,0 @@ -use crate::domain::models::macos::model::Pattern::{DeadCross, GoldenCross, Neither}; -use crate::domain::models::macos::model::{AnalysisPattern, Pattern, PatternRateOfChangePair}; -use crate::domain::models::stocks_macoses_pair::model::StocksMACOSESPair; -use crate::shared::float::percentage; - -use chrono::NaiveDate; -use deref_derive::{Deref, DerefMut}; -use rayon::prelude::*; -use std::ops::{Mul, Sub}; - -/// 終値ベースのMovingAverageCrossoverStrategyの解析 -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct MACOSAnalysisClose { - /// Crossover発生日 - pub date_of_event: NaiveDate, - /// Crossover発生日の終値 - pub close: f64, - /// N日後の終値 - pub close_after_n_days: f64, - /// MovingAverageCrossoverStrategyPattern - pub pattern: Pattern, - /// 増減率 - pub rate_of_change: f64, - /// 分析パターン - pub analysis_pattern: AnalysisPattern, -} - -#[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] -pub struct MACOSAnalysisCloses(Vec); - -impl<'a, const N: usize> From<&StocksMACOSESPair<'a>> for MACOSAnalysisCloses { - fn from(value: &StocksMACOSESPair<'a>) -> Self { - let StocksMACOSESPair { stocks, macoses } = value; - let vec_macos_analysis_close: Vec = macoses - .par_iter() - .filter_map(|macos| { - if macos.pattern_close_volume.close.eq(&Neither) { - return None; - } - // Crossoverが発生した日を特定 - let (stock, macos) = stocks.par_iter().find_map_first(|stock| { - if stock.date.eq(&macos.date) { - Some((stock, macos)) - } else { - None - } - })?; - // n日後のStockを取得。ただし営業日で並んでいる。 - let (stock, macos, stock_after_n_days) = stocks - .par_iter() - .enumerate() - .find_first(|(_, stock)| stock.date.eq(&macos.date)) - .and_then(|(index, _)| { - let stock_after_n_days = stocks.get(index + N)?; - Some((stock, macos, stock_after_n_days)) - })?; - // 増減率を取得 - let rate_of_change = stock_after_n_days.close.sub(stock.close) / stock.close; - let rate_of_change = rate_of_change.mul(100.0); - let pattern_rate_of_change_pair = PatternRateOfChangePair { - pattern: macos.pattern_close_volume.close, - rate_of_change, - }; - let analysis_pattern = AnalysisPattern::from(pattern_rate_of_change_pair); - Some(MACOSAnalysisClose { - date_of_event: macos.date, - close: stock.close, - close_after_n_days: stock_after_n_days.close, - pattern: macos.pattern_close_volume.close, - rate_of_change, - analysis_pattern, - }) - }) - .collect(); - MACOSAnalysisCloses::(vec_macos_analysis_close) - } -} - -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct RateOfChance { - pub whole: f64, - pub golden: f64, - pub dead: f64, -} - -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] -pub struct LatestChance { - pub golden_cross: Option, - pub dead_cross: Option, -} - -impl From for Pattern { - fn from(value: LatestChance) -> Self { - let LatestChance { - golden_cross: latest_golden_chance, - dead_cross: latest_dead_chance, - } = value; - match (latest_golden_chance, latest_dead_chance) { - (Some(golden), Some(dead)) => { - if golden >= dead { - GoldenCross - } else { - DeadCross - } - } - (Some(_), None) => GoldenCross, - (None, Some(_)) => DeadCross, - _ => Neither, - } - } -} - -impl From for NaiveDate { - fn from(value: LatestChance) -> Self { - let LatestChance { - golden_cross: latest_golden_chance, - dead_cross: latest_dead_chance, - } = value; - match (latest_golden_chance, latest_dead_chance) { - (Some(golden), Some(dead)) => { - if golden >= dead { - golden - } else { - dead - } - } - (Some(golden), None) => golden, - (None, Some(dead)) => dead, - _ => NaiveDate::default(), - } - } -} - -impl MACOSAnalysisCloses { - pub fn rate_of_chance(&self) -> RateOfChance { - let count_golden_chance = self - .par_iter() - .filter(|macos_analysis_close| { - matches!( - macos_analysis_close.analysis_pattern, - AnalysisPattern::GoldenChance - ) - }) - .count(); - let count_golden_loss = self - .par_iter() - .filter(|macos_analysis_close| { - matches!( - macos_analysis_close.analysis_pattern, - AnalysisPattern::GoldenLoss - ) - }) - .count(); - let golden = percentage(count_golden_chance, count_golden_chance + count_golden_loss); - - let count_dead_chance = self - .par_iter() - .filter(|macos_analysis_close| { - matches!( - macos_analysis_close.analysis_pattern, - AnalysisPattern::DeadChance - ) - }) - .count(); - let count_dead_loss = self - .par_iter() - .filter(|macos_analysis_close| { - matches!( - macos_analysis_close.analysis_pattern, - AnalysisPattern::DeadLoss - ) - }) - .count(); - let dead = percentage(count_dead_chance, count_dead_chance + count_dead_loss); - - let whole = percentage(count_golden_chance + count_dead_chance, self.len()); - RateOfChance { - whole, - golden, - dead, - } - } - - fn find_latest_event(&self, target_pattern: &AnalysisPattern) -> Option { - self.par_iter() - .rev() - .find_first(|macos_analysis_close| { - macos_analysis_close.analysis_pattern.eq(target_pattern) - }) - .map(|macos_analysis_close| macos_analysis_close.date_of_event) - } - - pub fn latest_chance(&self) -> LatestChance { - let golden_cross = self.find_latest_event(&AnalysisPattern::GoldenChance); - let dead_cross = self.find_latest_event(&AnalysisPattern::DeadChance); - LatestChance { - golden_cross, - dead_cross, - } - } -} - -#[cfg(test)] -mod tests { - use anyhow::Result; - use bytes::Bytes; - use chrono::NaiveDate; - use pretty_assertions::assert_eq; - - use crate::domain::models::macos::model::MACOSes; - use crate::domain::models::macos_analysis::close::model::MACOSAnalysisCloses; - use crate::domain::models::sma::model::{SMAListPair, SMAs}; - use crate::domain::models::stocks_macoses_pair::model::StocksMACOSESPair; - use crate::domain::repositories::stock::queries; - use crate::domain::repositories::stock::repository::Stock; - use crate::infrastructure::dsv::Dsv; - use crate::infrastructure::repositories::stock::structures::internal::csv; - - const CSV: &[u8] = include_bytes!("../../../../../assets/8473.T.csv"); - - #[tokio::test] - async fn macos_analysis_close_test() -> Result<()> { - let dsv = Dsv::::new(true, Bytes::from(CSV)); - let query = queries::get_stocks::Query { - ..Default::default() - }; - let stocks = dsv.get_stocks(&query).await?; - let smas_5 = SMAs::<5>::from(stocks.as_slice()); - let smas_25 = SMAs::<25>::from(stocks.as_slice()); - let sma_list_pair = SMAListPair { - smas_n: smas_5.as_slice(), - smas_o: smas_25.as_slice(), - }; - let macoses = MACOSes::from(sma_list_pair); - let stocks_macoses_pair = StocksMACOSESPair { - stocks: stocks.as_slice(), - macoses: macoses.as_slice(), - }; - // 3日後トレンドを取得 - let macos_analysis_closes = MACOSAnalysisCloses::<3>::from(&stocks_macoses_pair); - let actual = 11; - assert_eq!(actual, macos_analysis_closes.len()); - - let rate_of_chance = macos_analysis_closes.rate_of_chance(); - let actual = 45.45454545454545; - assert_eq!(actual, rate_of_chance.whole); - let actual = 66.66666666666666; - assert_eq!(actual, rate_of_chance.golden); - let actual = 20.0; - assert_eq!(actual, rate_of_chance.dead); - - let latest_chance = macos_analysis_closes.latest_chance(); - let actual = NaiveDate::from_ymd_opt(2023, 8, 30); - assert_eq!(actual, latest_chance.golden_cross); - let actual = NaiveDate::from_ymd_opt(2023, 3, 14); - assert_eq!(actual, latest_chance.dead_cross); - Ok(()) - } -} diff --git a/src/domain/models/macos_analysis/volume/model.rs b/src/domain/models/macos_analysis/volume/model.rs deleted file mode 100644 index 034e169..0000000 --- a/src/domain/models/macos_analysis/volume/model.rs +++ /dev/null @@ -1,87 +0,0 @@ -use crate::domain::models::macos::model::Pattern; -use crate::domain::models::macos::model::Pattern::Neither; -use crate::domain::models::stocks_macoses_pair::model::StocksMACOSESPair; -use chrono::NaiveDate; -use deref_derive::{Deref, DerefMut}; -use rayon::prelude::*; - -/// 出来高ベースのMovingAverageCrossoverStrategyのトレンド解析 -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct MACOSAnalysisVolume { - /// Crossover発生日 - pub date_of_event: NaiveDate, - /// Crossover発生日の出来高 - pub volume: u64, - /// MovingAverageCrossoverStrategyPattern - pub pattern: Pattern, -} - -#[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] -pub struct MACOSAnalysisVolumes(Vec); - -impl<'a> From<&StocksMACOSESPair<'a>> for MACOSAnalysisVolumes { - fn from(value: &StocksMACOSESPair<'a>) -> Self { - let StocksMACOSESPair { stocks, macoses } = value; - let vec_macos_analysis_volume = macoses - .par_iter() - .filter_map(|macos| { - // Neitherは判断材料とならないため結果から除外する - if macos.pattern_close_volume.volume.eq(&Neither) { - return None; - } - // Crossover発生日と同じ日の株価情報を取得 - let stock = stocks - .par_iter() - .find_first(|stock| stock.date.eq(&macos.date))?; - Some(MACOSAnalysisVolume { - date_of_event: stock.date, - volume: stock.volume, - pattern: macos.pattern_close_volume.volume, - }) - }) - .collect::>(); - MACOSAnalysisVolumes(vec_macos_analysis_volume) - } -} - -#[cfg(test)] -mod tests { - use anyhow::Result; - use bytes::Bytes; - use pretty_assertions::assert_eq; - - use crate::domain::models::macos::model::MACOSes; - use crate::domain::models::macos_analysis::volume::model::MACOSAnalysisVolumes; - use crate::domain::models::sma::model::{SMAListPair, SMAs}; - use crate::domain::models::stocks_macoses_pair::model::StocksMACOSESPair; - use crate::domain::repositories::stock::queries; - use crate::domain::repositories::stock::repository::Stock; - use crate::infrastructure::dsv::Dsv; - use crate::infrastructure::repositories::stock::structures::internal::csv; - - const CSV: &[u8] = include_bytes!("../../../../../assets/8473.T.csv"); - - #[tokio::test] - async fn macos_analysis_volume_test() -> Result<()> { - let dsv = Dsv::::new(true, Bytes::from(CSV)); - let query = queries::get_stocks::Query { - ..Default::default() - }; - let stocks = dsv.get_stocks(&query).await?; - let smas_5 = SMAs::<5>::from(stocks.as_slice()); - let smas_25 = SMAs::<25>::from(stocks.as_slice()); - let sma_list_pair = SMAListPair { - smas_n: smas_5.as_slice(), - smas_o: smas_25.as_slice(), - }; - let macoses = MACOSes::from(sma_list_pair); - let stocks_macoses_pair = StocksMACOSESPair { - stocks: stocks.as_slice(), - macoses: macoses.as_slice(), - }; - let macos_analysis_volumes = MACOSAnalysisVolumes::from(&stocks_macoses_pair); - let actual = 33; - assert_eq!(actual, macos_analysis_volumes.len()); - Ok(()) - } -} diff --git a/src/domain/models/ms_es.rs b/src/domain/models/ms_es.rs new file mode 100644 index 0000000..65880be --- /dev/null +++ b/src/domain/models/ms_es.rs @@ -0,0 +1 @@ +pub mod model; diff --git a/src/domain/models/msesp/model.rs b/src/domain/models/ms_es/model.rs similarity index 89% rename from src/domain/models/msesp/model.rs rename to src/domain/models/ms_es/model.rs index 0482f00..61ef51b 100644 --- a/src/domain/models/msesp/model.rs +++ b/src/domain/models/ms_es/model.rs @@ -1,25 +1,24 @@ -use deref_derive::{Deref, DerefMut}; -use rayon::prelude::*; - use crate::domain::models::buy_sell_signal::model::{BuySellSignal, BuySellSignalType}; use crate::domain::models::candle_stick::model::{BullishBearishType, CandleStick}; +use deref_derive::{Deref, DerefMut}; +use rayon::prelude::*; #[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct MSESP { +pub struct MsEs { two_days_before_bullish_bearish: BullishBearishType, a_day_before_is_doji: bool, target_day_bullish_bearish: BullishBearishType, } -impl From for BuySellSignalType { - /// Morning Star/Evening Star Pattern +impl From for BuySellSignalType { + /// Morning Star/Evening Star /// /// 3つのローソク足を考える。 /// * **Buy**: 対象日の2日前がBearish、対象日の1日前が同事、対象日がBullishのとき /// * **Sell**: 対象日の2日前がBullish、対象日の1日前が同事、対象日がBearishのとき /// * **Stay**: 上記のどちらにもあてはまならない - fn from(value: MSESP) -> Self { - let MSESP { + fn from(value: MsEs) -> Self { + let MsEs { two_days_before_bullish_bearish, a_day_before_is_doji, target_day_bullish_bearish, @@ -37,9 +36,9 @@ impl From for BuySellSignalType { } #[derive(Default, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Deref, DerefMut)] -pub struct MSESPes(Vec); +pub struct MsEses(Vec); -impl From<&[CandleStick]> for MSESPes { +impl From<&[CandleStick]> for MsEses { /// /// # Examples /// ``` @@ -47,7 +46,7 @@ impl From<&[CandleStick]> for MSESPes { /// /// use quantitative_data_analysis_rs::domain::models::candle_stick::model::CandleSticks; /// use quantitative_data_analysis_rs::domain::models::stock::model; - /// use quantitative_data_analysis_rs::domain::models::msesp::model::MSESPes; + /// use quantitative_data_analysis_rs::domain::models::ms_es::model::MsEses; /// use quantitative_data_analysis_rs::domain::repositories::stock::queries; /// use quantitative_data_analysis_rs::domain::repositories::stock::repository::Stock; /// use quantitative_data_analysis_rs::infrastructure::dsv::Dsv; @@ -65,53 +64,52 @@ impl From<&[CandleStick]> for MSESPes { /// }; /// let stocks = dsv.get_stocks(&query).await.unwrap(); /// let candle_sticks = CandleSticks::::try_from(stocks.as_slice()).unwrap(); - /// let msespes = MSESPes::from(candle_sticks.as_slice()); - /// assert_eq!(msespes.len(), 33); + /// let mseses = MsEses::from(candle_sticks.as_slice()); + /// assert_eq!(mseses.len(), 33); /// }); /// ``` fn from(value: &[CandleStick]) -> Self { - let vec_buy_sell_signal = value + let vec_ms_es = value .par_windows(3) .map(|candle_sticks| { let two_days_before_bullish_bearish = candle_sticks[0].bullish_bearish; let a_day_before_is_doji = candle_sticks[1].is_doji; let target_day_bullish_bearish = candle_sticks[2].bullish_bearish; - let msesp = MSESP { + let ms_es = MsEs { two_days_before_bullish_bearish, a_day_before_is_doji, target_day_bullish_bearish, }; - let r#type = BuySellSignalType::from(msesp); + let r#type = BuySellSignalType::from(ms_es); let today = candle_sticks[2].date; BuySellSignal { r#type, date: today, } }) - .collect::>(); - MSESPes(vec_buy_sell_signal) + .collect(); + MsEses(vec_ms_es) } } #[cfg(test)] mod tests { - use anyhow::Result; - use bytes::Bytes; - use chrono::NaiveDate; - use pretty_assertions::assert_eq; - use rayon::prelude::*; - use crate::domain::models::buy_sell_signal::model::BuySellSignalType::Sell; use crate::domain::models::buy_sell_signal::model::{ BuySellSignal, BuySellSignalType::{Buy, Stay}, }; use crate::domain::models::candle_stick::model::CandleSticks; - use crate::domain::models::msesp::model::MSESPes; + use crate::domain::models::ms_es::model::MsEses; use crate::domain::repositories::stock::queries; use crate::domain::repositories::stock::repository::Stock; use crate::infrastructure::dsv::Dsv; use crate::infrastructure::repositories::stock::structures::internal::csv; + use anyhow::Result; + use bytes::Bytes; + use chrono::NaiveDate; + use pretty_assertions::assert_eq; + use rayon::prelude::*; const MARUBOZU_BODY_MIN_RATIO: usize = 90; const MARUBOZU_WICK_MAX_RATIO: usize = 2; @@ -130,8 +128,8 @@ mod tests { MARUBOZU_WICK_MAX_RATIO, DOJI_MAX_BODY_RATIO, >::try_from(stocks.as_slice())?; - let MSESPes(vec_msesp) = MSESPes::from(candle_sticks.as_slice()); - let (actual_buy, actual_sell): (Vec<_>, Vec<_>) = vec_msesp + let MsEses(vec_ms_es) = MsEses::from(candle_sticks.as_slice()); + let (actual_buy, actual_sell): (Vec<_>, Vec<_>) = vec_ms_es .into_par_iter() .filter(|signal| signal.r#type.ne(&Stay)) .partition(|signal| signal.r#type.eq(&Buy)); diff --git a/src/domain/models/sma/model.rs b/src/domain/models/sma/model.rs index f5056aa..f3f678e 100644 --- a/src/domain/models/sma/model.rs +++ b/src/domain/models/sma/model.rs @@ -1,47 +1,21 @@ +use crate::domain::models::close; use crate::domain::models::stock::model::Stock; - +use crate::domain::models::volume; use chrono::NaiveDate; use deref_derive::{Deref, DerefMut}; use rayon::prelude::*; -use simple_moving_average::{SMA as OtherSMA, SumTreeSMA}; - -/// 終値、取引高の単純移動平均のセット -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct SMASet { - /// 終値 - pub close: f64, - /// 取引高 - pub volume: f64, -} - -impl From<&[Stock]> for SMASet { - fn from(value: &[Stock]) -> Self { - // 終値のN日と取引高のN日の単純移動平均 - let (closes, volumes) = value.iter().fold( - ( - SumTreeSMA::<_, f64, { N }>::new(), - SumTreeSMA::<_, f64, { N }>::new(), - ), - |acc, stock| { - let (mut acc_close, mut acc_volume) = acc; - acc_close.add_sample(stock.close); - acc_volume.add_sample(stock.volume as _); - (acc_close, acc_volume) - }, - ); - let close = closes.get_average(); - let volume = volumes.get_average(); - Self { close, volume } - } -} +use ta::indicators::SimpleMovingAverage; +use ta::Next; /// 終値、取引高の単純移動平均 #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] pub struct SMA { - /// 終値、取引高のN日単純移動平均 - pub sma_n: SMASet, /// N日目の日付 pub date: NaiveDate, + /// 終値のN日単純移動平均 + pub close: close::model::F64, + /// 取引高のN日単純移動平均 + pub volume: volume::model::F64, } #[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] @@ -86,9 +60,21 @@ impl From<&[Stock]> for SMAs { fn from(value: &[Stock]) -> Self { let vec_sma = value .par_windows(N) - .map(|stocks| SMA { - sma_n: SMASet::::from(stocks), - date: stocks.last().unwrap().date, + .map(|stocks| { + // 終値のN日と取引高のN日の単純移動平均 + let mut sma_close = SimpleMovingAverage::new(N).unwrap(); + let mut sma_volume = SimpleMovingAverage::new(N).unwrap(); + let mut close = 0.0; + let mut volume = 0.0; + for stock in stocks { + close = sma_close.next(stock.close); + volume = sma_volume.next(stock.volume as f64); + } + SMA { + date: stocks.last().unwrap().date, + close: close::model::F64(close), + volume: volume::model::F64(volume), + } }) .collect::>>(); Self(vec_sma) diff --git a/src/domain/models/statement/model.rs b/src/domain/models/statement/model.rs index 680a5e9..3c71bae 100644 --- a/src/domain/models/statement/model.rs +++ b/src/domain/models/statement/model.rs @@ -4,7 +4,7 @@ use chrono::NaiveDate; /// /// This struct is designed to encapsulate the key financial data points for /// a company or entity, including net sales, profits, and assets. It can be -/// used to store financial data for reporting or analysis purposes. +/// used to store financial data for reporting or analysis_result purposes. /// /// # Fields /// diff --git a/src/domain/models/stocks_macoses_pair/model.rs b/src/domain/models/stocks_macoses_pair/model.rs deleted file mode 100644 index b124355..0000000 --- a/src/domain/models/stocks_macoses_pair/model.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::domain::models::macos::model::MACOS; -use crate::domain::models::stock::model::Stock; - -pub struct StocksMACOSESPair<'a> { - pub stocks: &'a [Stock], - pub macoses: &'a [MACOS], -} diff --git a/src/domain/models/stocks_sma_coses_pair.rs b/src/domain/models/stocks_sma_coses_pair.rs new file mode 100644 index 0000000..65880be --- /dev/null +++ b/src/domain/models/stocks_sma_coses_pair.rs @@ -0,0 +1 @@ +pub mod model; diff --git a/src/domain/models/stocks_sma_coses_pair/model.rs b/src/domain/models/stocks_sma_coses_pair/model.rs new file mode 100644 index 0000000..24fd940 --- /dev/null +++ b/src/domain/models/stocks_sma_coses_pair/model.rs @@ -0,0 +1,7 @@ +use crate::domain::models::crossover_strategy::sma_cos::model::SmaCos; +use crate::domain::models::stock::model::Stock; + +pub struct StocksSmaCosesPair<'a> { + pub stocks: &'a [Stock], + pub sma_coses: &'a [SmaCos], +} diff --git a/src/domain/models/trend_reversal_analysis/model.rs b/src/domain/models/trend_reversal_analysis/model.rs index 6418dd3..90f0421 100644 --- a/src/domain/models/trend_reversal_analysis/model.rs +++ b/src/domain/models/trend_reversal_analysis/model.rs @@ -2,20 +2,22 @@ use rayon::prelude::*; use crate::domain::models::buy_sell_signal::model::BuySellSignalType::{Buy, Sell, Stay}; use crate::domain::models::buy_sell_signal::model::{BuySellSignal, BuySellSignalType}; -use crate::domain::models::macos::model::MACOSes; -use crate::domain::models::macos::model::Pattern::{DeadCross, GoldenCross}; -use crate::domain::models::macps::model::MACPS; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern::{ + DeadCross, GoldenCross, +}; +use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; +use crate::domain::models::crossover_strategy::sma_cps::model::SmaCps; use chrono::NaiveDate; use serde::{Deserialize, Serialize}; -/// MACOS/MACPS/ECP2/MSESPの売買シグナルから相場転換を分析する +/// SmaCos/SmaCps/BodyEngulfing/MsEsの売買シグナルから相場転換を分析する #[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] pub struct TrendReversalAnalysis { pub r#type: BuySellSignalType, - pub macos: Option<(NaiveDate, BuySellSignalType)>, - pub ecp2: Option<(NaiveDate, BuySellSignalType)>, - pub msesp: Option<(NaiveDate, BuySellSignalType)>, - pub macps: Option<(NaiveDate, BuySellSignalType)>, + pub sma_cos: Option<(NaiveDate, BuySellSignalType)>, + pub sma_cps: Option<(NaiveDate, BuySellSignalType)>, + pub body_engulfing: Option<(NaiveDate, BuySellSignalType)>, + pub ms_es: Option<(NaiveDate, BuySellSignalType)>, } impl TrendReversalAnalysis { @@ -50,45 +52,48 @@ impl TrendReversalAnalysis { } pub struct TrendReversalAnalysisSet<'a> { - pub ecp2s: &'a [BuySellSignal], - pub msesps: &'a [BuySellSignal], - pub macps: &'a MACPS, - pub macoses: &'a MACOSes, + pub body_engulfings: &'a [BuySellSignal], + pub ms_eses: &'a [BuySellSignal], + pub sma_cps: &'a SmaCps, + pub sma_coses: &'a SmaCoses, } impl<'a> From> for TrendReversalAnalysis { fn from(value: TrendReversalAnalysisSet<'a>) -> Self { let TrendReversalAnalysisSet { - macps, - macoses, - ecp2s, - msesps, + sma_cps, + sma_coses, + body_engulfings, + ms_eses, } = value; - let macps = Self::resolve_latest_signal(macps.buy, macps.sell); - let macos_close_golden = macoses.latest_based_on_close(&GoldenCross); - let macos_close_dead = macoses.latest_based_on_close(&DeadCross); - let macos = Self::resolve_latest_signal(macos_close_golden, macos_close_dead); - let ecp2_buy = Self::latest_buy_sell_signal_date(ecp2s, &Buy); - let ecp2_sell = Self::latest_buy_sell_signal_date(ecp2s, &Sell); - let ecp2 = Self::resolve_latest_signal(ecp2_buy, ecp2_sell); - let msesp_buy = Self::latest_buy_sell_signal_date(msesps, &Buy); - let msesp_sell = Self::latest_buy_sell_signal_date(msesps, &Sell); - let msesp = Self::resolve_latest_signal(msesp_buy, msesp_sell); - // 終値のGoldenCross/ECP2 Buy/MSESP Buy/MACPS Buy が揃っていれば Buy - // 終値のDeadCross/ECP2 Sell/MSESP Sell/MACPS Sell が揃っていれば Sell + let sma_cps = Self::resolve_latest_signal(sma_cps.buy, sma_cps.sell); + let sma_cos_close_golden = sma_coses.latest_based_on_close(&GoldenCross); + let sma_cos_close_dead = sma_coses.latest_based_on_close(&DeadCross); + let sma_cos = Self::resolve_latest_signal(sma_cos_close_golden, sma_cos_close_dead); + let body_engulfing_buy = Self::latest_buy_sell_signal_date(body_engulfings, &Buy); + let body_engulfing_sell = Self::latest_buy_sell_signal_date(body_engulfings, &Sell); + let body_engulfing = Self::resolve_latest_signal(body_engulfing_buy, body_engulfing_sell); + let ms_es_buy = Self::latest_buy_sell_signal_date(ms_eses, &Buy); + let ms_es_sell = Self::latest_buy_sell_signal_date(ms_eses, &Sell); + let ms_es = Self::resolve_latest_signal(ms_es_buy, ms_es_sell); + // 終値のSmaCos GoldenCross/BodyEngulfing Buy/MsEs Buy/SmaCps Buy が揃っていれば Buy + // 終値のSmaCos DeadCross/BodyEngulfing Sell/MsEs Sell/SmaCps Sell が揃っていれば Sell // それ以外はStay - let r#type = match (macos, macps, ecp2, msesp) { - (Some(macos), Some(macps), Some(ecp2), Some(msesp)) - if macos.1.eq(&Buy) && macps.1.eq(&Buy) && ecp2.1.eq(&Buy) && msesp.1.eq(&Buy) => + let r#type = match (sma_cos, sma_cps, body_engulfing, ms_es) { + (Some(sma_cos), Some(sma_cps), Some(body_engulfing), Some(ms_es)) + if sma_cos.1.eq(&Buy) + && sma_cps.1.eq(&Buy) + && body_engulfing.1.eq(&Buy) + && ms_es.1.eq(&Buy) => { Buy } - (Some(macos), Some(macps), Some(ecp2), Some(msesp)) - if macos.1.eq(&Sell) - && macps.1.eq(&Sell) - && ecp2.1.eq(&Sell) - && msesp.1.eq(&Sell) => + (Some(sma_cos), Some(sma_cps), Some(body_engulfing), Some(ms_es)) + if sma_cos.1.eq(&Sell) + && sma_cps.1.eq(&Sell) + && body_engulfing.1.eq(&Sell) + && ms_es.1.eq(&Sell) => { Sell } @@ -96,10 +101,10 @@ impl<'a> From> for TrendReversalAnalysis { }; Self { r#type, - macps, - macos, - ecp2, - msesp, + sma_cps, + sma_cos, + body_engulfing, + ms_es, } } } @@ -111,12 +116,12 @@ mod tests { use chrono::NaiveDate; use pretty_assertions::assert_eq; + use crate::domain::models::body_engulfing::model::BodyEngulfings; use crate::domain::models::buy_sell_signal::model::BuySellSignalType::{Buy, Sell, Stay}; use crate::domain::models::candle_stick::model::CandleSticks; - use crate::domain::models::ecp2::model::ECP2s; - use crate::domain::models::macos::model::MACOSes; - use crate::domain::models::macps::model::MACPS; - use crate::domain::models::msesp::model::MSESPes; + use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; + use crate::domain::models::crossover_strategy::sma_cps::model::SmaCps; + use crate::domain::models::ms_es::model::MsEses; use crate::domain::models::sma::model::{SMAListPair, SMAListTrio, SMAs}; use crate::domain::models::trend_reversal_analysis::model::TrendReversalAnalysis; use crate::domain::models::trend_reversal_analysis::model::TrendReversalAnalysisSet; @@ -142,8 +147,8 @@ mod tests { MARUBOZU_WICK_MAX_RATIO, DOJI_MAX_BODY_RATIO, >::try_from(stocks.as_slice())?; - let ecp2s = ECP2s::from(candle_sticks.as_slice()); - let msespes = MSESPes::from(candle_sticks.as_slice()); + let body_engulfings = BodyEngulfings::from(candle_sticks.as_slice()); + let ms_eses = MsEses::from(candle_sticks.as_slice()); let smas_5 = SMAs::<5>::from(stocks.as_slice()); let smas_25 = SMAs::<25>::from(stocks.as_slice()); let smas_50 = SMAs::<50>::from(stocks.as_slice()); @@ -151,26 +156,26 @@ mod tests { smas_n: smas_5.as_slice(), smas_o: smas_25.as_slice(), }; - let macoses = MACOSes::from(sma_list_pair); + let sma_coses = SmaCoses::from(sma_list_pair); let sma_list_trio = SMAListTrio { smas_n: smas_5.as_slice(), smas_o: smas_25.as_slice(), smas_p: smas_50.as_slice(), }; - let macps = MACPS::from((stocks.as_slice(), sma_list_trio)); - let candle_stick_pattern_set = TrendReversalAnalysisSet { - ecp2s: &ecp2s, - msesps: &msespes, - macps: &macps, - macoses: &macoses, + let sma_cps = SmaCps::from((stocks.as_slice(), sma_list_trio)); + let trend_reversal_analysis_set = TrendReversalAnalysisSet { + body_engulfings: &body_engulfings, + ms_eses: &ms_eses, + sma_cps: &sma_cps, + sma_coses: &sma_coses, }; - let actual = TrendReversalAnalysis::from(candle_stick_pattern_set); + let actual = TrendReversalAnalysis::from(trend_reversal_analysis_set); let expected = TrendReversalAnalysis { r#type: Stay, - macos: NaiveDate::from_ymd_opt(2023, 8, 30).map(|date| (date, Buy)), - ecp2: NaiveDate::from_ymd_opt(2023, 8, 14).map(|date| (date, Sell)), - msesp: NaiveDate::from_ymd_opt(2023, 5, 24).map(|date| (date, Sell)), - macps: NaiveDate::from_ymd_opt(2023, 9, 8).map(|date| (date, Sell)), + sma_cos: NaiveDate::from_ymd_opt(2023, 8, 30).map(|date| (date, Buy)), + body_engulfing: NaiveDate::from_ymd_opt(2023, 8, 14).map(|date| (date, Sell)), + ms_es: NaiveDate::from_ymd_opt(2023, 5, 24).map(|date| (date, Sell)), + sma_cps: NaiveDate::from_ymd_opt(2023, 9, 8).map(|date| (date, Sell)), }; assert_eq!(actual, expected); Ok(()) diff --git a/src/domain/models/volume.rs b/src/domain/models/volume.rs new file mode 100644 index 0000000..65880be --- /dev/null +++ b/src/domain/models/volume.rs @@ -0,0 +1 @@ +pub mod model; diff --git a/src/domain/models/volume/model.rs b/src/domain/models/volume/model.rs new file mode 100644 index 0000000..8293be9 --- /dev/null +++ b/src/domain/models/volume/model.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct F64(pub f64); diff --git a/src/infrastructure/repositories/statement/jquants_api.rs b/src/infrastructure/repositories/statement/jquants_api.rs index eaa1c89..278efbe 100644 --- a/src/infrastructure/repositories/statement/jquants_api.rs +++ b/src/infrastructure/repositories/statement/jquants_api.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, bail}; +use anyhow::{bail, Context}; use async_trait::async_trait; use query_string_builder::QueryString; use rayon::prelude::*; @@ -90,15 +90,15 @@ mod tests { let actual = repository.get_row_statement(&query).await?; let expected = model::RowStatement { code: "8473".to_string(), - disclosed_date: NaiveDate::from_ymd_opt(2025, 5, 9), - eps: Some(536.09), - bps: Some(4162.73), - net_sales: Some(1443733000000.0), + disclosed_date: NaiveDate::from_ymd_opt(2026, 3, 13), + eps: None, + bps: None, + net_sales: None, opp: None, orp: None, - profit: Some(162120000000.0), - equity: Some(1763793000000.0), - total_assets: Some(32113430000000.0), + profit: None, + equity: None, + total_assets: None, }; assert_eq!(actual, expected); diff --git a/src/presenter/presenters/trend_analysis/output.rs b/src/presenter/presenters/trend_analysis/output.rs index 8ebc1cc..d81f0dd 100644 --- a/src/presenter/presenters/trend_analysis/output.rs +++ b/src/presenter/presenters/trend_analysis/output.rs @@ -1,11 +1,10 @@ use crate::domain::models::candle_stick::model::CandleSticks; use crate::domain::models::company::model::Company; -use crate::domain::models::ecp1::model::ECP1s; -use crate::domain::models::macos::model::MACOSes; -use crate::domain::models::macos_analysis::close::model::{ - LatestChance, MACOSAnalysisCloses, RateOfChance, -}; -use crate::domain::models::macos_analysis::volume::model::MACOSAnalysisVolumes; +use crate::domain::models::crossover_strategy::latest_chance::model::LatestChance; +use crate::domain::models::crossover_strategy::rate_of_chance::model::RateOfChance; +use crate::domain::models::crossover_strategy::sma_cos::analysis_result; +use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; +use crate::domain::models::high_low_direction_signal::model::HighLowDirectionSignals; use crate::domain::models::sma::model::SMAs; use crate::domain::models::stock::model::Stocks; use crate::domain::models::trend_reversal_analysis::model::TrendReversalAnalysis; @@ -17,12 +16,12 @@ pub struct TrendAnalysis, pub smas_25: SMAs<25>, pub smas_50: SMAs<50>, - pub macoses: MACOSes, - pub macos_analysis_closes: MACOSAnalysisCloses, + pub sma_coses: SmaCoses, + pub sma_cos_analysis_result_closes: analysis_result::close::model::AnalysisResults, pub rate_of_chance: RateOfChance, pub latest_chance: LatestChance, - pub macos_analysis_volumes: MACOSAnalysisVolumes, - pub ecp1s: ECP1s, + pub sma_cos_analysis_result_volumes: analysis_result::volume::model::AnalysisResults, + pub high_low_direction_signals: HighLowDirectionSignals, pub candle_sticks: CandleSticks, pub trend_reversal_analysis: TrendReversalAnalysis, pub crossover_pattern_filter: CrossoverPatternFilter, diff --git a/src/presenter/presenters/trend_analysis/response.rs b/src/presenter/presenters/trend_analysis/response.rs index 71abe99..8d269c7 100644 --- a/src/presenter/presenters/trend_analysis/response.rs +++ b/src/presenter/presenters/trend_analysis/response.rs @@ -1,10 +1,10 @@ -use deref_derive::{Deref, DerefMut}; - use crate::domain::models::company::model::Company; -use crate::domain::models::ecp1::model::ECP1s; -use crate::domain::models::macos_analysis::close::model::{LatestChance, RateOfChance}; +use crate::domain::models::crossover_strategy::latest_chance::model::LatestChance; +use crate::domain::models::crossover_strategy::rate_of_chance::model::RateOfChance; +use crate::domain::models::high_low_direction_signal::model::HighLowDirectionSignals; use crate::domain::models::trend_reversal_analysis::model::TrendReversalAnalysis; use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; +use deref_derive::{Deref, DerefMut}; pub mod chart; pub mod json; @@ -23,7 +23,7 @@ pub enum TrendAnalysis { crossover_pattern_filter: CrossoverPatternFilter, rate_of_chance: RateOfChance, latest_chance: LatestChance, - ecp1s: ECP1s, + high_low_direction_signals: HighLowDirectionSignals, trend_reversal_analysis: TrendReversalAnalysis, }, } diff --git a/src/presenter/presenters/trend_analysis/response/chart.rs b/src/presenter/presenters/trend_analysis/response/chart.rs index 61e51f1..862d426 100644 --- a/src/presenter/presenters/trend_analysis/response/chart.rs +++ b/src/presenter/presenters/trend_analysis/response/chart.rs @@ -6,16 +6,16 @@ use charts_rs::{ use rayon::prelude::*; use std::backtrace::Backtrace; -use crate::domain::models::macos::model::Pattern; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; use crate::presenter::presenters::trend_analysis::output; use crate::presenter::presenters::trend_analysis::presenter; use crate::presenter::presenters::trend_analysis::response; use crate::presenter::views::candle_stick::view::CandleSticks; -use crate::presenter::views::macos_analysis::close::view::MACOSAnalysisCloses; -use crate::presenter::views::macos_analysis::view::MACOSes; -use crate::presenter::views::macos_analysis::volume::view::MACOSTrendAnalysisVolumes; use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; use crate::presenter::views::sma::view::SMAs; +use crate::presenter::views::sma_cos_analysis::close::view::SmaCosAnalysis as SmaCosAnalysisClose; +use crate::presenter::views::sma_cos_analysis::view::SmaCoses; +use crate::presenter::views::sma_cos_analysis::volume::view::SmaCosAnalysis as SmaCosAnalysisVolume; use crate::presenter::views::stock::view::Stocks; use crate::shared::float; @@ -52,12 +52,12 @@ impl presenter::TrendAnalysis for Chart { charts.margin = 5.0.into(); let company = output.company; - let sma_5_averages = output.smas_5.sma_n_closes(); - let sma_25_averages = output.smas_25.sma_n_closes(); - let sma_50_averages = output.smas_50.sma_n_closes(); + let sma_5_closes = output.smas_5.sma_closes(); + let sma_25_closes = output.smas_25.sma_closes(); + let sma_50_closes = output.smas_50.sma_closes(); let ohlcs: Vec = output .stocks - .ohlces() + .ohlcs() .par_iter() .map(|value| *value as _) .collect(); @@ -68,34 +68,38 @@ impl presenter::TrendAnalysis for Chart { let series_list = match output.crossover_pattern_filter { CrossoverPatternFilter::Both => { - let dead_macoses = output.macoses.sma_25_closes(Pattern::DeadCross); - let golden_macoses = output.macoses.sma_25_closes(Pattern::GoldenCross); + let dead_crosses = output.sma_coses.sma_25_closes(CrossoverPattern::DeadCross); + let golden_crosses = output + .sma_coses + .sma_25_closes(CrossoverPattern::GoldenCross); vec![ - Series::from(("SMA5", sma_5_averages)), - Series::from(("SMA25", sma_25_averages)), - Series::from(("SMA50", sma_50_averages)), - Series::from(("Dead", dead_macoses)), - Series::from(("Golden", golden_macoses)), + Series::from(("SMA5", sma_5_closes)), + Series::from(("SMA25", sma_25_closes)), + Series::from(("SMA50", sma_50_closes)), + Series::from(("Dead", dead_crosses)), + Series::from(("Golden", golden_crosses)), Series::from(("OHLC", ohlcs)), ] } CrossoverPatternFilter::GoldenOnly => { - let golden_macoses = output.macoses.sma_25_closes(Pattern::GoldenCross); + let golden_crosses = output + .sma_coses + .sma_25_closes(CrossoverPattern::GoldenCross); vec![ - Series::from(("SMA5", sma_5_averages)), - Series::from(("SMA25", sma_25_averages)), - Series::from(("SMA50", sma_50_averages)), - Series::from(("Golden", golden_macoses)), + Series::from(("SMA5", sma_5_closes)), + Series::from(("SMA25", sma_25_closes)), + Series::from(("SMA50", sma_50_closes)), + Series::from(("Golden", golden_crosses)), Series::from(("OHLC", ohlcs)), ] } CrossoverPatternFilter::DeadOnly => { - let dead_macoses = output.macoses.sma_25_closes(Pattern::DeadCross); + let dead_crosses = output.sma_coses.sma_25_closes(CrossoverPattern::DeadCross); vec![ - Series::from(("SMA5", sma_5_averages)), - Series::from(("SMA25", sma_25_averages)), - Series::from(("SMA50", sma_50_averages)), - Series::from(("Dead", dead_macoses)), + Series::from(("SMA5", sma_5_closes)), + Series::from(("SMA25", sma_25_closes)), + Series::from(("SMA50", sma_50_closes)), + Series::from(("Dead", dead_crosses)), Series::from(("OHLC", ohlcs)), ] } @@ -143,8 +147,8 @@ impl presenter::TrendAnalysis for Chart { candlestick_chart.candlestick_down_border_color = Color::from((0, 40, 143)); charts.add(ChildChart::Candlestick(candlestick_chart, None)); - let sma_5_averages = output.smas_5.sma_n_volumes(); - let sma_25_averages = output.smas_25.sma_n_volumes(); + let sma_5_volumes = output.smas_5.sma_volumes(); + let sma_25_volumes = output.smas_25.sma_volumes(); let volumes: Vec = output .stocks .volumes() @@ -154,31 +158,35 @@ impl presenter::TrendAnalysis for Chart { let series_list = match output.crossover_pattern_filter { CrossoverPatternFilter::Both => { - let dead_macoses = output.macoses.sma_25_volumes(Pattern::DeadCross); - let golden_macoses = output.macoses.sma_25_volumes(Pattern::GoldenCross); + let dead_crosses = output.sma_coses.sma_25_volumes(CrossoverPattern::DeadCross); + let golden_crosses = output + .sma_coses + .sma_25_volumes(CrossoverPattern::GoldenCross); vec![ - Series::from(("SMA5", sma_5_averages)), - Series::from(("SMA25", sma_25_averages)), - Series::from(("Dead", dead_macoses)), - Series::from(("Golden", golden_macoses)), + Series::from(("SMA5", sma_5_volumes)), + Series::from(("SMA25", sma_25_volumes)), + Series::from(("Dead", dead_crosses)), + Series::from(("Golden", golden_crosses)), Series::from(("Volume", volumes)), ] } CrossoverPatternFilter::GoldenOnly => { - let golden_macoses = output.macoses.sma_25_volumes(Pattern::GoldenCross); + let golden_crosses = output + .sma_coses + .sma_25_volumes(CrossoverPattern::GoldenCross); vec![ - Series::from(("SMA5", sma_5_averages)), - Series::from(("SMA25", sma_25_averages)), - Series::from(("Golden", golden_macoses)), + Series::from(("SMA5", sma_5_volumes)), + Series::from(("SMA25", sma_25_volumes)), + Series::from(("Golden", golden_crosses)), Series::from(("Volume", volumes)), ] } CrossoverPatternFilter::DeadOnly => { - let dead_macoses = output.macoses.sma_25_volumes(Pattern::DeadCross); + let dead_crosses = output.sma_coses.sma_25_volumes(CrossoverPattern::DeadCross); vec![ - Series::from(("SMA5", sma_5_averages)), - Series::from(("SMA25", sma_25_averages)), - Series::from(("Dead", dead_macoses)), + Series::from(("SMA5", sma_5_volumes)), + Series::from(("SMA25", sma_25_volumes)), + Series::from(("Dead", dead_crosses)), Series::from(("Volume", volumes)), ] } @@ -210,12 +218,12 @@ impl presenter::TrendAnalysis for Chart { } charts.add(ChildChart::Bar(volume_chart, None)); - let mut rows = output.macos_analysis_closes.table_chart_header(); + let mut rows = output.sma_cos_analysis_result_closes.table_chart_header(); let mut body = output - .macos_analysis_closes + .sma_cos_analysis_result_closes .table_chart_rows(&output.crossover_pattern_filter); rows.append(&mut body); - let rate_of_chance = output.macos_analysis_closes.rate_of_chance(); + let rate_of_chance = output.sma_cos_analysis_result_closes.rate_of_chance(); let mut summary = rate_of_chance.table_chart_summary(&output.crossover_pattern_filter); rows.append(&mut summary); let mut table_chart = TableChart::new_with_theme(rows, self.theme.as_str()); @@ -223,9 +231,9 @@ impl presenter::TrendAnalysis for Chart { table_chart.width = self.width; charts.add(ChildChart::Table(table_chart, None)); - let mut rows = output.macos_analysis_volumes.table_chart_header(); + let mut rows = output.sma_cos_analysis_result_volumes.table_chart_header(); let mut body = output - .macos_analysis_volumes + .sma_cos_analysis_result_volumes .table_chart_rows(&output.crossover_pattern_filter); rows.append(&mut body); let mut table_chart = TableChart::new_with_theme(rows, self.theme.as_str()); diff --git a/src/presenter/presenters/trend_analysis/response/json.rs b/src/presenter/presenters/trend_analysis/response/json.rs index c39bd62..9f81ca6 100644 --- a/src/presenter/presenters/trend_analysis/response/json.rs +++ b/src/presenter/presenters/trend_analysis/response/json.rs @@ -16,7 +16,7 @@ impl presenter::TrendAnalysis for JSON { crossover_pattern_filter: output.crossover_pattern_filter, rate_of_chance: output.rate_of_chance, latest_chance: output.latest_chance, - ecp1s: output.ecp1s, + high_low_direction_signals: output.high_low_direction_signals, trend_reversal_analysis: output.trend_reversal_analysis, }) } diff --git a/src/presenter/presenters/trend_analysis_summary/response/chart.rs b/src/presenter/presenters/trend_analysis_summary/response/chart.rs index 5e5cabd..890d6f6 100644 --- a/src/presenter/presenters/trend_analysis_summary/response/chart.rs +++ b/src/presenter/presenters/trend_analysis_summary/response/chart.rs @@ -35,7 +35,7 @@ impl presenter::TrendAnalysisSummary for Chart { let mut rows = vec![vec![ "code".to_string(), "symbol".to_string(), - "macos type".to_string(), + "sma cos".to_string(), "latest".to_string(), chance_rate, ]]; diff --git a/src/presenter/views.rs b/src/presenter/views.rs index 34d93ed..766ed72 100644 --- a/src/presenter/views.rs +++ b/src/presenter/views.rs @@ -1,13 +1,13 @@ -pub mod buy_sell_signal_analysis; pub mod candle_stick; pub mod financial_indicator; pub mod financial_indicator_summary; +pub mod high_low_direction_signal_analysis; pub mod latest_chance; -pub mod macos_analysis; -pub mod macps_analysis; pub mod rate_of_chance; pub mod shared; pub mod sma; +pub mod sma_cos_analysis; +pub mod sma_cps_analysis; pub mod stock; pub mod trend_analysis_summary; pub mod trend_reversal_analysis; diff --git a/src/presenter/views/buy_sell_signal_analysis.rs b/src/presenter/views/high_low_direction_signal_analysis.rs similarity index 100% rename from src/presenter/views/buy_sell_signal_analysis.rs rename to src/presenter/views/high_low_direction_signal_analysis.rs diff --git a/src/presenter/views/buy_sell_signal_analysis/view.rs b/src/presenter/views/high_low_direction_signal_analysis/view.rs similarity index 70% rename from src/presenter/views/buy_sell_signal_analysis/view.rs rename to src/presenter/views/high_low_direction_signal_analysis/view.rs index c722066..4d90501 100644 --- a/src/presenter/views/buy_sell_signal_analysis/view.rs +++ b/src/presenter/views/high_low_direction_signal_analysis/view.rs @@ -1,31 +1,30 @@ +use crate::domain::models::buy_sell_signal::model; +use crate::domain::models::buy_sell_signal::model::BuySellSignalType; +use crate::shared::custom_serde::naive_date; use chrono::NaiveDate; use deref_derive::{Deref, DerefMut}; use rayon::prelude::*; use serde::{Deserialize, Serialize}; -use crate::domain::models::buy_sell_signal::model; -use crate::domain::models::buy_sell_signal::model::BuySellSignalType; -use crate::shared::custom_serde::naive_date; - #[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] -pub struct BuySellSignal { +pub struct HighLowDirectionSignal { pub r#type: BuySellSignalType, #[serde(with = "naive_date::primitive")] pub date: NaiveDate, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] -pub struct BuySellSignalAnalysis(Vec); +pub struct HighLowDirectionSignalAnalysis(Vec); -impl From<&[model::BuySellSignal]> for BuySellSignalAnalysis { +impl From<&[model::BuySellSignal]> for HighLowDirectionSignalAnalysis { fn from(value: &[model::BuySellSignal]) -> Self { - let vec_buy_sell_signal = value + let vec_high_low_direction_signal = value .par_iter() - .map(|element| BuySellSignal { + .map(|element| HighLowDirectionSignal { r#type: element.r#type, date: element.date, }) .collect(); - Self(vec_buy_sell_signal) + Self(vec_high_low_direction_signal) } } diff --git a/src/presenter/views/latest_chance/view.rs b/src/presenter/views/latest_chance/view.rs index f7a29ca..14e27c9 100644 --- a/src/presenter/views/latest_chance/view.rs +++ b/src/presenter/views/latest_chance/view.rs @@ -1,7 +1,7 @@ use chrono::NaiveDate; use std::fmt; -use crate::domain::models::macos_analysis::close::model::LatestChance; +use crate::domain::models::crossover_strategy::latest_chance::model::LatestChance; use crate::shared::custom_serde::naive_date::ISO8601_DATE_FORMAT; impl fmt::Display for LatestChance { diff --git a/src/presenter/views/macos_analysis/view.rs b/src/presenter/views/macos_analysis/view.rs deleted file mode 100644 index dd51121..0000000 --- a/src/presenter/views/macos_analysis/view.rs +++ /dev/null @@ -1,82 +0,0 @@ -use charts_rs::NIL_VALUE; -use chrono::NaiveDate; -use rayon::prelude::*; -use serde::{Deserialize, Serialize}; - -use crate::domain::models::macos::model; -use crate::domain::models::macos::model::MACOS; -use crate::domain::models::macos_analysis::close::model::{LatestChance, RateOfChance}; -use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; -use crate::shared::custom_serde::naive_date; - -#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct MACOSAnalysis { - pub pattern: model::Pattern, - #[serde(with = "naive_date::primitive")] - pub latest_chance: NaiveDate, - pub rate_of_chance: f64, -} - -impl From<(&CrossoverPatternFilter, &RateOfChance, &LatestChance)> for MACOSAnalysis { - fn from(value: (&CrossoverPatternFilter, &RateOfChance, &LatestChance)) -> Self { - let (crossover_pattern_filter, rate_of_chance, latest_chance) = value; - let latest_chance = crossover_pattern_filter.get_latest_chance(latest_chance); - let pattern = model::Pattern::from(latest_chance); - let latest_chance = NaiveDate::from(latest_chance); - let rate_of_chance = crossover_pattern_filter.get_rate_of_chance(rate_of_chance); - Self { - pattern, - latest_chance, - rate_of_chance, - } - } -} - -pub trait MACOSes { - fn sma_25_closes(&self, filter_pattern: model::Pattern) -> Vec; - fn sma_25_volumes(&self, filter_pattern: model::Pattern) -> Vec; -} - -impl MACOSes for model::MACOSes { - fn sma_25_closes(&self, filter_pattern: model::Pattern) -> Vec { - self.par_iter() - .map(|macos| { - let MACOS { - pattern_close_volume, - sma_set_25, - .. - } = macos; - pattern_close_volume.close.value_if_patterns_match( - filter_pattern, - sma_set_25.map(|sma_set| sma_set.close), - ) - }) - .collect() - } - - fn sma_25_volumes(&self, filter_pattern: model::Pattern) -> Vec { - self.par_iter() - .map(|macos| { - let MACOS { - pattern_close_volume, - sma_set_25, - .. - } = macos; - pattern_close_volume.volume.value_if_patterns_match( - filter_pattern, - sma_set_25.map(|sma_set| sma_set.volume), - ) - }) - .collect() - } -} - -impl model::Pattern { - fn value_if_patterns_match(&self, rhs: Self, value: Option) -> f32 { - if self.eq(&rhs) { - value.map_or(NIL_VALUE, |value| value as _) - } else { - NIL_VALUE - } - } -} diff --git a/src/presenter/views/rate_of_chance/view.rs b/src/presenter/views/rate_of_chance/view.rs index 7dd2a7a..cbba2a5 100644 --- a/src/presenter/views/rate_of_chance/view.rs +++ b/src/presenter/views/rate_of_chance/view.rs @@ -1,4 +1,4 @@ -use crate::domain::models::macos_analysis::close::model::RateOfChance; +use crate::domain::models::crossover_strategy::rate_of_chance::model::RateOfChance; use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; impl RateOfChance { @@ -17,19 +17,18 @@ impl RateOfChance { #[cfg(test)] mod tests { - use anyhow::Result; - use bytes::Bytes; - use pretty_assertions::assert_eq; - - use crate::domain::models::macos::model::MACOSes; - use crate::domain::models::macos_analysis::close::model::MACOSAnalysisCloses; + use crate::domain::models::crossover_strategy::sma_cos::analysis_result::close::model::AnalysisResults; + use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; use crate::domain::models::sma::model::{SMAListPair, SMAs}; - use crate::domain::models::stocks_macoses_pair::model::StocksMACOSESPair; + use crate::domain::models::stocks_sma_coses_pair::model::StocksSmaCosesPair; use crate::domain::repositories::stock::queries; use crate::domain::repositories::stock::repository::Stock; use crate::infrastructure::dsv::Dsv; use crate::infrastructure::repositories::stock::structures::internal::csv; use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; + use anyhow::Result; + use bytes::Bytes; + use pretty_assertions::assert_eq; const AFTER_DAYS: usize = 5; const CSV: &[u8] = include_bytes!("../../../../assets/8473.T.csv"); @@ -47,13 +46,13 @@ mod tests { smas_n: smas_5.as_slice(), smas_o: smas_25.as_slice(), }; - let macoses = MACOSes::from(sma_list_pair); - let stocks_macoses_pair = StocksMACOSESPair { + let sma_coses = SmaCoses::from(sma_list_pair); + let stocks_sma_coses_pair = StocksSmaCosesPair { stocks: stocks.as_slice(), - macoses: macoses.as_slice(), + sma_coses: sma_coses.as_slice(), }; - let macos_analysis_closes = MACOSAnalysisCloses::::from(&stocks_macoses_pair); - let rate_of_chance = macos_analysis_closes.rate_of_chance(); + let analysis_results = AnalysisResults::::from(&stocks_sma_coses_pair); + let rate_of_chance = analysis_results.rate_of_chance(); let summary = rate_of_chance.table_chart_summary(&CrossoverPatternFilter::Both); assert_eq!( summary, diff --git a/src/presenter/views/shared/crossover_pattern_filter.rs b/src/presenter/views/shared/crossover_pattern_filter.rs index e557d35..78fd8aa 100644 --- a/src/presenter/views/shared/crossover_pattern_filter.rs +++ b/src/presenter/views/shared/crossover_pattern_filter.rs @@ -1,5 +1,6 @@ -use crate::domain::models::macos::model; -use crate::domain::models::macos_analysis::close::model::{LatestChance, RateOfChance}; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; +use crate::domain::models::crossover_strategy::latest_chance::model::LatestChance; +use crate::domain::models::crossover_strategy::rate_of_chance::model::RateOfChance; use strum::Display; /// クロスオーバーのどのパターン(ゴールデンクロス、デッドクロス、または両方)を @@ -23,11 +24,13 @@ impl CrossoverPatternFilter { /// /// # 戻り値 /// フィルター条件に一致する場合は `true`、そうでない場合は `false`。 - pub fn matches_filter(&self, pattern: &model::Pattern) -> bool { + pub fn matches_filter(&self, crossover_pattern: &CrossoverPattern) -> bool { match self { CrossoverPatternFilter::Both => true, - CrossoverPatternFilter::GoldenOnly => pattern.eq(&model::Pattern::GoldenCross), - CrossoverPatternFilter::DeadOnly => pattern.eq(&model::Pattern::DeadCross), + CrossoverPatternFilter::GoldenOnly => { + crossover_pattern.eq(&CrossoverPattern::GoldenCross) + } + CrossoverPatternFilter::DeadOnly => crossover_pattern.eq(&CrossoverPattern::DeadCross), } } @@ -85,11 +88,11 @@ impl CrossoverPatternFilter { #[cfg(test)] mod tests { - use chrono::NaiveDate; - - use crate::domain::models::macos::model; - use crate::domain::models::macos_analysis::close::model::{LatestChance, RateOfChance}; + use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; + use crate::domain::models::crossover_strategy::latest_chance::model::LatestChance; + use crate::domain::models::crossover_strategy::rate_of_chance::model::RateOfChance; use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; + use chrono::NaiveDate; fn ymd(year: i32, month: u32, day: u32) -> NaiveDate { NaiveDate::from_ymd_opt(year, month, day).unwrap() @@ -97,17 +100,17 @@ mod tests { #[test] fn matches_filter_test() { - assert!(CrossoverPatternFilter::Both.matches_filter(&model::Pattern::GoldenCross)); - assert!(CrossoverPatternFilter::Both.matches_filter(&model::Pattern::DeadCross)); - assert!(CrossoverPatternFilter::Both.matches_filter(&model::Pattern::Neither)); // NeutralもBothではtrue + assert!(CrossoverPatternFilter::Both.matches_filter(&CrossoverPattern::GoldenCross)); + assert!(CrossoverPatternFilter::Both.matches_filter(&CrossoverPattern::DeadCross)); + assert!(CrossoverPatternFilter::Both.matches_filter(&CrossoverPattern::Neither)); // NeutralもBothではtrue - assert!(CrossoverPatternFilter::GoldenOnly.matches_filter(&model::Pattern::GoldenCross)); - assert!(!CrossoverPatternFilter::GoldenOnly.matches_filter(&model::Pattern::DeadCross)); - assert!(!CrossoverPatternFilter::GoldenOnly.matches_filter(&model::Pattern::Neither)); + assert!(CrossoverPatternFilter::GoldenOnly.matches_filter(&CrossoverPattern::GoldenCross)); + assert!(!CrossoverPatternFilter::GoldenOnly.matches_filter(&CrossoverPattern::DeadCross)); + assert!(!CrossoverPatternFilter::GoldenOnly.matches_filter(&CrossoverPattern::Neither)); - assert!(!CrossoverPatternFilter::DeadOnly.matches_filter(&model::Pattern::GoldenCross)); - assert!(CrossoverPatternFilter::DeadOnly.matches_filter(&model::Pattern::DeadCross)); - assert!(!CrossoverPatternFilter::DeadOnly.matches_filter(&model::Pattern::Neither)); + assert!(!CrossoverPatternFilter::DeadOnly.matches_filter(&CrossoverPattern::GoldenCross)); + assert!(CrossoverPatternFilter::DeadOnly.matches_filter(&CrossoverPattern::DeadCross)); + assert!(!CrossoverPatternFilter::DeadOnly.matches_filter(&CrossoverPattern::Neither)); } #[test] diff --git a/src/presenter/views/sma/view.rs b/src/presenter/views/sma/view.rs index 0e73517..efd2e8a 100644 --- a/src/presenter/views/sma/view.rs +++ b/src/presenter/views/sma/view.rs @@ -1,18 +1,17 @@ -use rayon::prelude::*; - use crate::domain::models::sma::model; +use rayon::prelude::*; pub trait SMAs { - fn sma_n_closes(&self) -> Vec; - fn sma_n_volumes(&self) -> Vec; + fn sma_closes(&self) -> Vec; + fn sma_volumes(&self) -> Vec; } impl SMAs for model::SMAs { - fn sma_n_closes(&self) -> Vec { - self.par_iter().map(|sma| sma.sma_n.close as _).collect() + fn sma_closes(&self) -> Vec { + self.par_iter().map(|sma| sma.close.0 as _).collect() } - fn sma_n_volumes(&self) -> Vec { - self.par_iter().map(|sma| sma.sma_n.volume as _).collect() + fn sma_volumes(&self) -> Vec { + self.par_iter().map(|sma| sma.volume.0 as _).collect() } } diff --git a/src/presenter/views/macos_analysis.rs b/src/presenter/views/sma_cos_analysis.rs similarity index 100% rename from src/presenter/views/macos_analysis.rs rename to src/presenter/views/sma_cos_analysis.rs diff --git a/src/presenter/views/macos_analysis/close.rs b/src/presenter/views/sma_cos_analysis/close.rs similarity index 100% rename from src/presenter/views/macos_analysis/close.rs rename to src/presenter/views/sma_cos_analysis/close.rs diff --git a/src/presenter/views/macos_analysis/close/view.rs b/src/presenter/views/sma_cos_analysis/close/view.rs similarity index 64% rename from src/presenter/views/macos_analysis/close/view.rs rename to src/presenter/views/sma_cos_analysis/close/view.rs index 7bda92c..d61c059 100644 --- a/src/presenter/views/macos_analysis/close/view.rs +++ b/src/presenter/views/sma_cos_analysis/close/view.rs @@ -1,16 +1,15 @@ -use rayon::prelude::*; - -use crate::domain::models::macos::model::AnalysisPattern; -use crate::domain::models::macos_analysis::close::model; +use crate::domain::models::crossover_strategy::analysis_pattern::model::AnalysisPattern; +use crate::domain::models::crossover_strategy::sma_cos::analysis_result::close::model; use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; use crate::shared::custom_serde::naive_date::SLASH_DELIMITED_DATE_FORMAT; +use rayon::prelude::*; -pub trait MACOSAnalysisCloses { +pub trait SmaCosAnalysis { fn table_chart_header(&self) -> Vec>; fn table_chart_rows(&self, pattern: &CrossoverPatternFilter) -> Vec>; } -impl MACOSAnalysisCloses for model::MACOSAnalysisCloses { +impl SmaCosAnalysis for model::AnalysisResults { fn table_chart_header(&self) -> Vec> { vec![vec![ "date".to_string(), @@ -24,23 +23,23 @@ impl MACOSAnalysisCloses for model::MACOSAnalysisCloses { fn table_chart_rows(&self, pattern: &CrossoverPatternFilter) -> Vec> { self.par_iter() - .filter(|macos_analysis_close| pattern.matches_filter(&macos_analysis_close.pattern)) - .map(|macos_analysis_close| { - let chance_loss = match macos_analysis_close.analysis_pattern { + .filter(|analysis_result| pattern.matches_filter(&analysis_result.pattern)) + .map(|analysis_result| { + let chance_loss = match analysis_result.analysis_pattern { AnalysisPattern::None => "❔".to_string(), AnalysisPattern::GoldenChance => "✅".to_string(), AnalysisPattern::DeadChance => "✅".to_string(), AnalysisPattern::GoldenLoss => "❌".to_string(), AnalysisPattern::DeadLoss => "❌".to_string(), }; - let date_of_event = macos_analysis_close + let date_of_event = analysis_result .date_of_event .format(SLASH_DELIMITED_DATE_FORMAT) .to_string(); - let pattern = macos_analysis_close.pattern.to_string(); - let rate_of_change = format!("{:+.3}%", macos_analysis_close.rate_of_change); - let close = macos_analysis_close.close.to_string(); - let close_after_n_days = macos_analysis_close.close_after_n_days.to_string(); + let pattern = analysis_result.pattern.to_string(); + let rate_of_change = format!("{:+.3}%", analysis_result.rate_of_change); + let close = analysis_result.close.to_string(); + let close_after_n_days = analysis_result.close_after_n_days.to_string(); vec![ date_of_event, chance_loss, diff --git a/src/presenter/views/sma_cos_analysis/view.rs b/src/presenter/views/sma_cos_analysis/view.rs new file mode 100644 index 0000000..c1c1ec5 --- /dev/null +++ b/src/presenter/views/sma_cos_analysis/view.rs @@ -0,0 +1,84 @@ +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; +use crate::domain::models::crossover_strategy::latest_chance::model::LatestChance; +use crate::domain::models::crossover_strategy::rate_of_chance::model::RateOfChance; +use crate::domain::models::crossover_strategy::sma_cos::model; +use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; +use crate::shared::custom_serde::naive_date; +use charts_rs::NIL_VALUE; +use chrono::NaiveDate; +use rayon::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, PartialOrd, Default)] +pub struct SmaCosAnalysis { + pub crossover_pattern: CrossoverPattern, + #[serde(with = "naive_date::primitive")] + pub latest_chance: NaiveDate, + pub rate_of_chance: f64, +} + +impl From<(&CrossoverPatternFilter, &RateOfChance, &LatestChance)> for SmaCosAnalysis { + fn from(value: (&CrossoverPatternFilter, &RateOfChance, &LatestChance)) -> Self { + let (crossover_pattern_filter, rate_of_chance, latest_chance) = value; + let latest_chance = crossover_pattern_filter.get_latest_chance(latest_chance); + let crossover_pattern = CrossoverPattern::from(latest_chance); + let latest_chance = NaiveDate::from(latest_chance); + let rate_of_chance = crossover_pattern_filter.get_rate_of_chance(rate_of_chance); + Self { + crossover_pattern, + latest_chance, + rate_of_chance, + } + } +} + +pub trait SmaCoses { + fn sma_25_closes(&self, filter_pattern: CrossoverPattern) -> Vec; + fn sma_25_volumes(&self, filter_pattern: CrossoverPattern) -> Vec; +} + +impl SmaCoses for model::SmaCoses { + fn sma_25_closes(&self, filter_pattern: CrossoverPattern) -> Vec { + collect_filtered_sma_values(self, filter_pattern, |sma_cos| { + ( + sma_cos.crossover_pattern_close.0, + sma_cos.close_25.map(|c| c.0), + ) + }) + } + + fn sma_25_volumes(&self, filter_pattern: CrossoverPattern) -> Vec { + collect_filtered_sma_values(self, filter_pattern, |sma_cos| { + ( + sma_cos.crossover_pattern_volume.0, + sma_cos.volume_25.map(|v| v.0), + ) + }) + } +} + +fn collect_filtered_sma_values( + sma_coses: &model::SmaCoses, + filter_pattern: CrossoverPattern, + extract: impl Fn(&model::SmaCos) -> (CrossoverPattern, Option) + Sync, +) -> Vec { + sma_coses + .par_iter() + .map(|sma_cos| { + let (crossover_pattern, value) = extract(sma_cos); + value_if_patterns_match(&crossover_pattern, &filter_pattern, value) + }) + .collect() +} + +fn value_if_patterns_match( + lhs: &CrossoverPattern, + rhs: &CrossoverPattern, + value: Option, +) -> f32 { + if lhs.eq(rhs) { + value.map_or(NIL_VALUE, |value| value as _) + } else { + NIL_VALUE + } +} diff --git a/src/presenter/views/macos_analysis/volume.rs b/src/presenter/views/sma_cos_analysis/volume.rs similarity index 100% rename from src/presenter/views/macos_analysis/volume.rs rename to src/presenter/views/sma_cos_analysis/volume.rs diff --git a/src/presenter/views/macos_analysis/volume/view.rs b/src/presenter/views/sma_cos_analysis/volume/view.rs similarity index 78% rename from src/presenter/views/macos_analysis/volume/view.rs rename to src/presenter/views/sma_cos_analysis/volume/view.rs index 3173b61..1868931 100644 --- a/src/presenter/views/macos_analysis/volume/view.rs +++ b/src/presenter/views/sma_cos_analysis/volume/view.rs @@ -1,15 +1,14 @@ -use rayon::prelude::*; - -use crate::domain::models::macos_analysis::volume::model; +use crate::domain::models::crossover_strategy::sma_cos::analysis_result::volume::model; use crate::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; use crate::shared::custom_serde::naive_date::SLASH_DELIMITED_DATE_FORMAT; +use rayon::prelude::*; -pub trait MACOSTrendAnalysisVolumes { +pub trait SmaCosAnalysis { fn table_chart_header(&self) -> Vec>; fn table_chart_rows(&self, pattern: &CrossoverPatternFilter) -> Vec>; } -impl MACOSTrendAnalysisVolumes for model::MACOSAnalysisVolumes { +impl SmaCosAnalysis for model::AnalysisResults { fn table_chart_header(&self) -> Vec> { vec![vec![ "date".to_string(), @@ -27,8 +26,8 @@ impl MACOSTrendAnalysisVolumes for model::MACOSAnalysisVolumes { .format(SLASH_DELIMITED_DATE_FORMAT) .to_string(); let pattern = trend_analysis.pattern.to_string(); - let volume_on_macos = trend_analysis.volume.to_string(); - vec![date, pattern, volume_on_macos] + let sma_cos_volume = trend_analysis.volume.to_string(); + vec![date, pattern, sma_cos_volume] }) .collect() } diff --git a/src/presenter/views/macps_analysis.rs b/src/presenter/views/sma_cps_analysis.rs similarity index 100% rename from src/presenter/views/macps_analysis.rs rename to src/presenter/views/sma_cps_analysis.rs diff --git a/src/presenter/views/macps_analysis/view.rs b/src/presenter/views/sma_cps_analysis/view.rs similarity index 92% rename from src/presenter/views/macps_analysis/view.rs rename to src/presenter/views/sma_cps_analysis/view.rs index 4c2eb4f..e005fb2 100644 --- a/src/presenter/views/macps_analysis/view.rs +++ b/src/presenter/views/sma_cps_analysis/view.rs @@ -5,7 +5,7 @@ use crate::domain::models::buy_sell_signal::model::BuySellSignalType; use crate::shared::custom_serde::naive_date; #[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, PartialOrd, Default)] -pub struct MACPSAnalysis { +pub struct SmaCpsAnalysis { pub r#type: BuySellSignalType, #[serde(with = "naive_date::primitive")] pub date: NaiveDate, diff --git a/src/presenter/views/stock/view.rs b/src/presenter/views/stock/view.rs index d81490a..6076108 100644 --- a/src/presenter/views/stock/view.rs +++ b/src/presenter/views/stock/view.rs @@ -4,7 +4,7 @@ use crate::domain::models::stock::model; pub trait Stocks { fn formatted_dates(&self, date_format: &str) -> Vec; - fn ohlces(&self) -> Vec; + fn ohlcs(&self) -> Vec; fn volumes(&self) -> Vec; } @@ -15,7 +15,7 @@ impl Stocks for model::Stocks { .collect() } - fn ohlces(&self) -> Vec { + fn ohlcs(&self) -> Vec { self.par_iter() .flat_map(|stock| vec![stock.open, stock.close, stock.low, stock.high]) .collect() diff --git a/src/presenter/views/trend_analysis_summary/chart/view.rs b/src/presenter/views/trend_analysis_summary/chart/view.rs index d22ed71..d911717 100644 --- a/src/presenter/views/trend_analysis_summary/chart/view.rs +++ b/src/presenter/views/trend_analysis_summary/chart/view.rs @@ -3,7 +3,7 @@ use deref_derive::Deref; use rayon::prelude::*; use crate::domain::models::company::model::Company; -use crate::domain::models::macos::model::Pattern; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; use crate::presenter::presenters::trend_analysis::response; pub struct ChartRow(pub Vec); @@ -22,14 +22,14 @@ impl TryFrom<&response::TrendAnalysis> for ChartRow { } => { let Company { code, symbol, .. } = company; let latest_chance = crossover_pattern_filter.get_latest_chance(latest_chance); - let macos = Pattern::from(latest_chance).to_string(); + let crossover_pattern = CrossoverPattern::from(latest_chance).to_string(); let latest_chance = latest_chance.to_string(); let rate_of_chance_percent = crossover_pattern_filter.format_rate_of_chance_percent(rate_of_chance); Ok(ChartRow(vec![ code.to_string(), symbol.to_string(), - macos, + crossover_pattern, latest_chance, rate_of_chance_percent, ])) diff --git a/src/presenter/views/trend_analysis_summary/json/view.rs b/src/presenter/views/trend_analysis_summary/json/view.rs index 5c98e76..da66c1d 100644 --- a/src/presenter/views/trend_analysis_summary/json/view.rs +++ b/src/presenter/views/trend_analysis_summary/json/view.rs @@ -4,16 +4,16 @@ use rayon::prelude::*; use serde::{Deserialize, Serialize}; use crate::presenter::presenters::trend_analysis::response; -use crate::presenter::views::buy_sell_signal_analysis::view::BuySellSignalAnalysis; -use crate::presenter::views::macos_analysis::view::MACOSAnalysis; +use crate::presenter::views::high_low_direction_signal_analysis::view::HighLowDirectionSignalAnalysis; +use crate::presenter::views::sma_cos_analysis::view::SmaCosAnalysis; use crate::presenter::views::trend_reversal_analysis::view::TrendReversalAnalysis; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, PartialOrd, Default)] pub struct JsonRow { pub code: String, pub symbol: String, - pub macos_analysis: MACOSAnalysis, - pub ecp1_analysis: BuySellSignalAnalysis, + pub sma_cos_analysis: SmaCosAnalysis, + pub high_low_direction_signal_analysis: HighLowDirectionSignalAnalysis, pub trend_reversal_analysis: TrendReversalAnalysis, } @@ -27,18 +27,19 @@ impl TryFrom<&response::TrendAnalysis> for JsonRow { crossover_pattern_filter, rate_of_chance, latest_chance, - ecp1s, + high_low_direction_signals, trend_reversal_analysis, } => { - let macos_analysis = - MACOSAnalysis::from((crossover_pattern_filter, rate_of_chance, latest_chance)); - let ecp1_analysis = BuySellSignalAnalysis::from(ecp1s.as_slice()); + let sma_cos_analysis = + SmaCosAnalysis::from((crossover_pattern_filter, rate_of_chance, latest_chance)); + let high_low_direction_signal_analysis = + HighLowDirectionSignalAnalysis::from(high_low_direction_signals.as_slice()); let trend_reversal_analysis = TrendReversalAnalysis::from(trend_reversal_analysis); Ok(JsonRow { code: company.code.to_string(), symbol: company.symbol.to_string(), - macos_analysis, - ecp1_analysis, + sma_cos_analysis, + high_low_direction_signal_analysis, trend_reversal_analysis, }) } @@ -68,16 +69,15 @@ impl From for JSON { #[cfg(test)] mod tests { - use chrono::NaiveDate; - use indoc::indoc; - use crate::domain::models::buy_sell_signal::model::BuySellSignal; use crate::domain::models::buy_sell_signal::model::BuySellSignalType; - use crate::domain::models::macos::model::Pattern; - use crate::presenter::views::buy_sell_signal_analysis::view::BuySellSignalAnalysis; - use crate::presenter::views::macos_analysis::view::MACOSAnalysis; + use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; + use crate::presenter::views::high_low_direction_signal_analysis::view::HighLowDirectionSignalAnalysis; + use crate::presenter::views::sma_cos_analysis::view::SmaCosAnalysis; use crate::presenter::views::trend_analysis_summary::json::view::JsonRow; use crate::presenter::views::trend_reversal_analysis::view::TrendReversalAnalysis; + use chrono::NaiveDate; + use indoc::indoc; #[test] fn serde_test() { @@ -85,12 +85,12 @@ mod tests { { "code": "8473", "symbol": "8473.T", - "macos_analysis": { - "pattern": "Neither", + "sma_cos_analysis": { + "crossover_pattern": "Neither", "latest_chance": "2017-02-16", "rate_of_chance": 32.7 }, - "ecp1_analysis": [ + "high_low_direction_signal_analysis": [ { "type": "Stay", "date": "2017-02-16" @@ -98,18 +98,18 @@ mod tests { ], "trend_reversal_analysis": { "type": "Buy", - "macos_date": "2023-08-15", - "ecp2_date": "2023-06-01", - "msesp_date": "2023-07-26", - "macps_date": "2023-07-04" + "sma_cos_date": "2023-08-15", + "sma_cps_date": "2023-07-04", + "body_engulfing_date": "2023-06-01", + "ms_es_date": "2023-07-26" } }"#}; - let macos_analysis = MACOSAnalysis { - pattern: Pattern::Neither, + let sma_cos_analysis = SmaCosAnalysis { + crossover_pattern: CrossoverPattern::Neither, latest_chance: NaiveDate::from_ymd_opt(2017, 2, 16).unwrap(), rate_of_chance: 32.7, }; - let ecp1_analysis = BuySellSignalAnalysis::from( + let high_low_direction_signal_analysis = HighLowDirectionSignalAnalysis::from( [BuySellSignal { r#type: BuySellSignalType::Stay, date: NaiveDate::from_ymd_opt(2017, 2, 16).unwrap(), @@ -118,16 +118,16 @@ mod tests { ); let trend_reversal_analysis = TrendReversalAnalysis { r#type: BuySellSignalType::Buy, - macos_date: NaiveDate::from_ymd_opt(2023, 8, 15).unwrap(), - ecp2_date: NaiveDate::from_ymd_opt(2023, 6, 1).unwrap(), - msesp_date: NaiveDate::from_ymd_opt(2023, 7, 26).unwrap(), - macps_date: NaiveDate::from_ymd_opt(2023, 7, 4).unwrap(), + sma_cos_date: NaiveDate::from_ymd_opt(2023, 8, 15).unwrap(), + sma_cps_date: NaiveDate::from_ymd_opt(2023, 7, 4).unwrap(), + body_engulfing_date: NaiveDate::from_ymd_opt(2023, 6, 1).unwrap(), + ms_es_date: NaiveDate::from_ymd_opt(2023, 7, 26).unwrap(), }; let json_row = JsonRow { code: "8473".to_string(), symbol: "8473.T".to_string(), - macos_analysis, - ecp1_analysis, + sma_cos_analysis, + high_low_direction_signal_analysis, trend_reversal_analysis, }; let actual = serde_json::to_string_pretty(&json_row).unwrap(); diff --git a/src/presenter/views/trend_reversal_analysis/view.rs b/src/presenter/views/trend_reversal_analysis/view.rs index 196d213..6779b5a 100644 --- a/src/presenter/views/trend_reversal_analysis/view.rs +++ b/src/presenter/views/trend_reversal_analysis/view.rs @@ -1,38 +1,43 @@ -use chrono::NaiveDate; -use serde::{Deserialize, Serialize}; - use crate::domain::models::buy_sell_signal::model::BuySellSignalType; use crate::domain::models::trend_reversal_analysis::model; use crate::shared::custom_serde::naive_date; +use chrono::NaiveDate; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, PartialOrd, Default)] pub struct TrendReversalAnalysis { pub r#type: BuySellSignalType, #[serde(with = "naive_date::primitive")] - pub macos_date: NaiveDate, + pub sma_cos_date: NaiveDate, #[serde(with = "naive_date::primitive")] - pub ecp2_date: NaiveDate, + pub sma_cps_date: NaiveDate, #[serde(with = "naive_date::primitive")] - pub msesp_date: NaiveDate, + pub body_engulfing_date: NaiveDate, #[serde(with = "naive_date::primitive")] - pub macps_date: NaiveDate, + pub ms_es_date: NaiveDate, } impl From<&model::TrendReversalAnalysis> for TrendReversalAnalysis { fn from(value: &model::TrendReversalAnalysis) -> Self { let model::TrendReversalAnalysis { r#type, - macos, - ecp2, - msesp, - macps, + sma_cos, + body_engulfing, + ms_es, + sma_cps, } = value; Self { r#type: *r#type, - macos_date: macos.map(|(date, _)| date).unwrap_or(NaiveDate::default()), - ecp2_date: ecp2.map(|(date, _)| date).unwrap_or(NaiveDate::default()), - msesp_date: msesp.map(|(date, _)| date).unwrap_or(NaiveDate::default()), - macps_date: macps.map(|(date, _)| date).unwrap_or(NaiveDate::default()), + sma_cos_date: sma_cos + .map(|(date, _)| date) + .unwrap_or(NaiveDate::default()), + sma_cps_date: sma_cps + .map(|(date, _)| date) + .unwrap_or(NaiveDate::default()), + body_engulfing_date: body_engulfing + .map(|(date, _)| date) + .unwrap_or(NaiveDate::default()), + ms_es_date: ms_es.map(|(date, _)| date).unwrap_or(NaiveDate::default()), } } } diff --git a/src/use_case/interactors/trend_analysis/interactor.rs b/src/use_case/interactors/trend_analysis/interactor.rs index 222bd30..703efd1 100644 --- a/src/use_case/interactors/trend_analysis/interactor.rs +++ b/src/use_case/interactors/trend_analysis/interactor.rs @@ -1,16 +1,12 @@ -use anyhow::Result; -use async_trait::async_trait; - +use crate::domain::models::body_engulfing::model::BodyEngulfings; use crate::domain::models::candle_stick::model::CandleSticks; -use crate::domain::models::ecp1::model::ECP1s; -use crate::domain::models::ecp2::model::ECP2s; -use crate::domain::models::macos::model::MACOSes; -use crate::domain::models::macos_analysis::close::model::MACOSAnalysisCloses; -use crate::domain::models::macos_analysis::volume::model::MACOSAnalysisVolumes; -use crate::domain::models::macps::model::MACPS; -use crate::domain::models::msesp::model::MSESPes; +use crate::domain::models::crossover_strategy::sma_cos::analysis_result; +use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; +use crate::domain::models::crossover_strategy::sma_cps::model::SmaCps; +use crate::domain::models::high_low_direction_signal::model::HighLowDirectionSignals; +use crate::domain::models::ms_es::model::MsEses; use crate::domain::models::sma::model::{SMAListPair, SMAListTrio, SMAs}; -use crate::domain::models::stocks_macoses_pair::model::StocksMACOSESPair; +use crate::domain::models::stocks_sma_coses_pair::model::StocksSmaCosesPair; use crate::domain::models::trend_reversal_analysis::model::TrendReversalAnalysis; use crate::domain::models::trend_reversal_analysis::model::TrendReversalAnalysisSet; use crate::domain::repositories; @@ -20,6 +16,8 @@ use crate::presenter::presenters::trend_analysis::output; use crate::shared::iterator::{FromEnd, SliceWrapper}; use crate::use_case::interfaces::trend_analysis::input; use crate::use_case::interfaces::trend_analysis::use_case; +use anyhow::Result; +use async_trait::async_trait; #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)] pub struct TrendAnalysis<'a, SR, CR> { @@ -79,7 +77,7 @@ where smas_n: smas_5.as_slice(), smas_o: smas_25.as_slice(), }; - let macoses = MACOSes::from(sma_list_pair); + let sma_coses = SmaCoses::from(sma_list_pair); let smas_50 = SMAs::<50>::from(stocks.as_slice()); let sma_list_trio = SMAListTrio { @@ -87,21 +85,25 @@ where smas_o: smas_25.as_slice(), smas_p: smas_50.as_slice(), }; - let macps = MACPS::from((stocks.as_slice(), sma_list_trio)); + let sma_cps = SmaCps::from((stocks.as_slice(), sma_list_trio)); let stocks_from_end_days = SliceWrapper::from(stocks.as_slice()).get_from_end(FROM_END_DAYS); - let ecp1s = ECP1s::from(stocks_from_end_days.as_slice()); + let high_low_direction_signals = + HighLowDirectionSignals::from(stocks_from_end_days.as_slice()); - let stocks_macoses_pair = StocksMACOSESPair { + let stocks_sma_coses_pair = StocksSmaCosesPair { stocks: stocks.as_slice(), - macoses: macoses.as_slice(), + sma_coses: sma_coses.as_slice(), }; - let macos_analysis_closes = MACOSAnalysisCloses::::from(&stocks_macoses_pair); - let rate_of_chance = macos_analysis_closes.rate_of_chance(); - let latest_chance = macos_analysis_closes.latest_chance(); + let sma_cos_analysis_result_closes = analysis_result::close::model::AnalysisResults::< + AFTER_DAYS, + >::from(&stocks_sma_coses_pair); + let rate_of_chance = sma_cos_analysis_result_closes.rate_of_chance(); + let latest_chance = sma_cos_analysis_result_closes.latest_chance(); - let macos_analysis_volumes = MACOSAnalysisVolumes::from(&stocks_macoses_pair); + let sma_cos_analysis_result_volumes = + analysis_result::volume::model::AnalysisResults::from(&stocks_sma_coses_pair); let candle_sticks = CandleSticks::< MARUBOZU_BODY_MIN_RATIO, @@ -110,14 +112,14 @@ where >::try_from(stocks.as_slice())?; let candle_sticks_from_end_days = SliceWrapper::from(candle_sticks.as_slice()).get_from_end(FROM_END_DAYS); - let ecp2s = ECP2s::from(candle_sticks_from_end_days.as_slice()); - let msespes = MSESPes::from(candle_sticks_from_end_days.as_slice()); + let body_engulfings = BodyEngulfings::from(candle_sticks_from_end_days.as_slice()); + let ms_eses = MsEses::from(candle_sticks_from_end_days.as_slice()); // 相場転換を分析 let trend_reversal_analysis_set = TrendReversalAnalysisSet { - ecp2s: &ecp2s, - msesps: &msespes, - macps: &macps, - macoses: &macoses, + body_engulfings: &body_engulfings, + ms_eses: &ms_eses, + sma_cps: &sma_cps, + sma_coses: &sma_coses, }; let trend_reversal_analysis = TrendReversalAnalysis::from(trend_reversal_analysis_set); @@ -127,12 +129,12 @@ where smas_5, smas_25, smas_50, - macoses, - macos_analysis_closes, + sma_coses, + sma_cos_analysis_result_closes, rate_of_chance, latest_chance, - macos_analysis_volumes, - ecp1s, + sma_cos_analysis_result_volumes, + high_low_direction_signals, candle_sticks, trend_reversal_analysis, crossover_pattern_filter: input.crossover_pattern_filter, diff --git a/tests/csv.rs b/tests/csv.rs index b5c91ca..443770b 100644 --- a/tests/csv.rs +++ b/tests/csv.rs @@ -2,7 +2,7 @@ use anyhow::Context; use csv::{ReaderBuilder, Writer}; use indoc::indoc; use quantitative_data_analysis_rs::infrastructure::repositories::stock::structures::internal::csv::Structure; -use quantitative_data_analysis_rs::presenter::views::macos_analysis::view::MACOSAnalysis; +use quantitative_data_analysis_rs::presenter::views::sma_cos_analysis::view::SmaCosAnalysis; const CSV_8473: &[u8] = include_bytes!("../assets/8473.T.csv"); @@ -37,16 +37,16 @@ fn csv_sandbox() { assert_eq!(actual, expected); let json = indoc! {r#"{ - "pattern":"GoldenCross", + "crossover_pattern":"GoldenCross", "latest_chance":"2023-08-30", "rate_of_chance":27.27272727272727 }"#}; - let macos_analysis: MACOSAnalysis = serde_json::from_str(json).unwrap(); + let sma_cos_analysis: SmaCosAnalysis = serde_json::from_str(json).unwrap(); let mut builder = Writer::from_writer(vec![]); - let _ = builder.serialize(macos_analysis); + let _ = builder.serialize(sma_cos_analysis); let data = String::from_utf8(builder.into_inner().unwrap()).unwrap(); assert_eq!( data, - "pattern,latest_chance,rate_of_chance\nGoldenCross,2023-08-30,27.27272727272727\n" + "crossover_pattern,latest_chance,rate_of_chance\nGoldenCross,2023-08-30,27.27272727272727\n" ); } diff --git a/tests/simple_moving_average.rs b/tests/simple_moving_average.rs deleted file mode 100644 index 9e1cf23..0000000 --- a/tests/simple_moving_average.rs +++ /dev/null @@ -1,15 +0,0 @@ -use anyhow::Result; -use simple_moving_average::{SMA, SumTreeSMA}; - -#[test] -fn simple_moving_average_sandbox() -> Result<()> { - let mut ma = SumTreeSMA::<_, f32, 5>::new(); // Sample window size = 2 - ma.add_sample(100.0); - ma.add_sample(200.0); - ma.add_sample(300.0); - ma.add_sample(400.0); - ma.add_sample(500.0); - let expected = 300.0; - assert_eq!(ma.get_average(), expected); - Ok(()) -} From 10f9b953340073c97bd86a04395a500bc0779488 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 12 Apr 2026 17:49:41 +0900 Subject: [PATCH 06/15] chore: remove formatting check from CI pipeline in rust.yml --- .github/workflows/rust.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ab43e46..0f3dc55 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -28,7 +28,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: 1.90.0 - components: clippy, rustfmt + components: clippy - name: Cache Rust artifacts uses: Swatinem/rust-cache@v2 @@ -41,9 +41,6 @@ jobs: test -n "$JQUANTS_MAIL_ADDRESS" test -n "$JQUANTS_PASSWORD" - - name: Check formatting - run: cargo fmt --all -- --check - - name: Run clippy run: cargo clippy --all-targets --all-features -- -D warnings From 73886f7e87f89f481adfa21f258f98066e2acce5 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 12 Apr 2026 17:55:43 +0900 Subject: [PATCH 07/15] chore: add .cargo/config.toml to .gitignore for improved configuration management --- .cargo/config.toml | 8 -------- .gitignore | 4 ++++ 2 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 6c36a91..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,8 +0,0 @@ -# https://medium.com/@anshusinghal703/rust-dev-speedup-secret-cutting-compile-time-from-22-minutes-to-under-a-minute-with-a-single-be8a0da4fc83 -[build] -rustflags = ["-C", "codegen-units=16"] -rustc-wrapper = "sccache" -incremental = true - -[profile.dev.build-override] -opt-level = 3 diff --git a/.gitignore b/.gitignore index 61ebaae..f05b50d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,12 @@ examples/**/*.svg examples/**/*.tsv /target + +.cargo/config.toml + # Cargo.lock is tracked in this repository to keep CI reproducible. !/Cargo.lock + ### Generated by gibo (https://github.com/simonwhitaker/gibo) ### https://raw.github.com/github/gitignore/4488915eec0b3a45b5c63ead28f286819c0917de/Global/macOS.gitignore From 63e2adf82bca9b047a6ccef96c817ddc005e32f9 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 12 Apr 2026 18:02:34 +0900 Subject: [PATCH 08/15] refactor: improve floating-point minimum value assertion for clarity --- src/shared/from_json_string_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/from_json_string_value.rs b/src/shared/from_json_string_value.rs index 821c20f..6ac52aa 100644 --- a/src/shared/from_json_string_value.rs +++ b/src/shared/from_json_string_value.rs @@ -540,7 +540,7 @@ mod tests { // f32 min let result: Result = f32::from_json_string_value("f32_min", &json_value); assert!(result.is_ok()); - assert_eq!(result.unwrap(), 1.17549435e-38); + assert_eq!(result.unwrap(), 1.175_494_4e-38); // f64 min let result: Result = f64::from_json_string_value("f64_min", &json_value); From f36e62279009a0ca95e210e10dd5c9b6e18c87fe Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Wed, 15 Apr 2026 19:10:55 +0900 Subject: [PATCH 09/15] refactor: update J-Quants API integration to use API key and adjust response handling --- .github/workflows/rust.yml | 9 +- README.md | 6 +- src/infrastructure/jquants_api.rs | 235 +----------------- .../repositories/company/jquants_api.rs | 12 +- .../company/structures/jquants_api.rs | 4 +- .../repositories/statement/jquants_api.rs | 99 ++++---- .../statement/structures/jquants_api.rs | 18 +- .../repositories/stock/jquants_api.rs | 12 +- .../stock/structures/jquants_api.rs | 12 +- src/shared/jquants_api/setup.rs | 71 +----- 10 files changed, 107 insertions(+), 371 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0f3dc55..842190e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -35,19 +35,16 @@ jobs: - name: Validate J-Quants secrets env: - JQUANTS_MAIL_ADDRESS: ${{ secrets.JQUANTS_MAIL_ADDRESS }} - JQUANTS_PASSWORD: ${{ secrets.JQUANTS_PASSWORD }} + JQUANTS_API_KEY: ${{ secrets.JQUANTS_API_KEY }} run: | - test -n "$JQUANTS_MAIL_ADDRESS" - test -n "$JQUANTS_PASSWORD" + test -n "$JQUANTS_API_KEY" - name: Run clippy run: cargo clippy --all-targets --all-features -- -D warnings - name: Run tests env: - JQUANTS_MAIL_ADDRESS: ${{ secrets.JQUANTS_MAIL_ADDRESS }} - JQUANTS_PASSWORD: ${{ secrets.JQUANTS_PASSWORD }} + JQUANTS_API_KEY: ${{ secrets.JQUANTS_API_KEY }} run: cargo test --all --locked - name: Build library diff --git a/README.md b/README.md index ffa39b1..c935bc9 100644 --- a/README.md +++ b/README.md @@ -53,12 +53,10 @@ regression safety. ## Configuration -- Place your cached token in `jquants_api_token.json` (created automatically on first run). -- Provide J-Quants credentials via environment variables before executing any example or binary: +- Provide J-Quants API key via environment variable before executing any example or binary: ```bash - export JQUANTS_MAIL_ADDRESS="your-email@example.com" - export JQUANTS_PASSWORD="your-jquants-password" + export JQUANTS_API_KEY="your-jquants-api-key" ``` - Optional inputs (dates, markets, crossover filters) are passed directly when calling controllers or editing the diff --git a/src/infrastructure/jquants_api.rs b/src/infrastructure/jquants_api.rs index 49910ac..b0e9215 100644 --- a/src/infrastructure/jquants_api.rs +++ b/src/infrastructure/jquants_api.rs @@ -1,241 +1,32 @@ -use anyhow::{ensure, Context, Result}; +use anyhow::{ensure, Result}; use bytestring::ByteString; -use chrono::{Days, NaiveDateTime, Utc}; -use chrono_tz::Asia::Tokyo; -use itertools::Either; -use query_string_builder::QueryString; -use reqwest::Client; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; - -const AUTH_USER_URL: &str = "https://api.jquants.com/v1/token/auth_user"; -const AUTH_REFRESH_URL: &str = "https://api.jquants.com/v1/token/auth_refresh"; - -#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct RefreshToken { - pub value: String, - pub expires_in: NaiveDateTime, -} - -#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct IdToken { - pub value: String, - pub expires_in: NaiveDateTime, -} - -#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct Token { - pub refresh_token: RefreshToken, - pub id_token: IdToken, -} - -impl Token { - pub async fn update_token( - token: Result>, - mailaddress: impl Into, - password: impl Into, - now: NaiveDateTime, - ) -> Result> { - let token = match token { - Err(_) => { - let refresh_token = JQuantsAPI::get_refresh_token(mailaddress, password).await?; - let id_token = JQuantsAPI::get_id_token(&refresh_token).await?; - let token = Token { - refresh_token, - id_token, - }; - Either::Right(token) - } - Ok(body) => { - let token: Token = serde_json::from_slice(&body)?; - let is_refresh_token_expired = token.is_refresh_token_expired(now); - let is_id_token_expired = token.is_id_token_expired(now); - match (is_refresh_token_expired, is_id_token_expired) { - (true, _) => { - let refresh_token = - JQuantsAPI::get_refresh_token(mailaddress, password).await?; - let id_token = JQuantsAPI::get_id_token(&refresh_token).await?; - let token = Token { - refresh_token, - id_token, - }; - Either::Right(token) - } - (_, true) => { - let id_token = JQuantsAPI::get_id_token(&token.refresh_token).await?; - let token = Token { id_token, ..token }; - Either::Right(token) - } - _ => Either::Left(token), - } - } - }; - Ok(token) - } - - fn is_refresh_token_expired(&self, now: NaiveDateTime) -> bool { - self.refresh_token.expires_in < now - } - - fn is_id_token_expired(&self, now: NaiveDateTime) -> bool { - self.id_token.expires_in < now - } -} - -#[derive(Deserialize)] -struct AuthUserResponse { - #[serde(rename = "refreshToken")] - refresh_token: String, -} - -#[derive(Deserialize)] -struct AuthRefreshResponse { - #[serde(rename = "idToken")] - id_token: String, -} - -/// Parses a `/token/auth_user` response body and returns the contained refresh token string. -/// The function validates the JSON structure and ensures the token is not empty. -pub fn parse_refresh_token_payload(body: &[u8]) -> Result { - let parsed: AuthUserResponse = - serde_json::from_slice(body).context("Failed to deserialize refresh token response")?; - let trim = parsed.refresh_token.trim(); - ensure!(!trim.is_empty(), "refreshToken field is empty"); - Ok(trim.to_string()) -} - -/// Parses a `/token/auth_refresh` response body and returns the contained ID token string. -/// The function validates the JSON structure and ensures the token is not empty. -pub fn parse_id_token_payload(body: &[u8]) -> Result { - let parsed: AuthRefreshResponse = - serde_json::from_slice(body).context("Failed to deserialize id token response")?; - let trim = parsed.id_token.trim(); - ensure!(!trim.is_empty(), "idToken field is empty"); - Ok(trim.to_string()) -} pub struct JQuantsAPI { - pub id_token: ByteString, + pub api_key: ByteString, } impl JQuantsAPI { - pub fn new(id_token: ByteString) -> Result { - Ok(Self { id_token }) - } - - pub async fn get_refresh_token( - mail_address: impl Into, - password: impl Into, - ) -> Result { - let mut params = HashMap::new(); - params.insert("mailaddress", mail_address.into()); - params.insert("password", password.into()); - let response = Client::new() - .post(AUTH_USER_URL) - .json(¶ms) - .send() - .await?; - let body = response.bytes().await?; - let refresh_token = parse_refresh_token_payload(&body)?; - let now = Utc::now().with_timezone(&Tokyo).naive_local(); - Ok(RefreshToken { - value: refresh_token, - expires_in: now.checked_add_days(Days::new(7)).unwrap(), - }) - } - - pub async fn get_id_token(refresh_token: &RefreshToken) -> Result { - let qs = QueryString::dynamic().with_value("refreshtoken", &refresh_token.value); - let auth_refresh_url = format!("{AUTH_REFRESH_URL}{qs}"); - let response = Client::new().post(auth_refresh_url).send().await?; - let body = response.bytes().await?; - let id_token = parse_id_token_payload(&body)?; - let now = Utc::now().with_timezone(&Tokyo).naive_local(); - Ok(IdToken { - value: id_token, - expires_in: now.checked_add_days(Days::new(1)).unwrap(), - }) + pub fn new(api_key: ByteString) -> Result { + ensure!(!api_key.trim().is_empty(), "J-Quants API key must not be empty"); + Ok(Self { api_key }) } } #[cfg(test)] mod tests { - use super::{parse_id_token_payload, parse_refresh_token_payload}; - use anyhow::Context; - use chrono::Utc; - use chrono_tz::Asia::Tokyo; - - use crate::infrastructure::jquants_api::{JQuantsAPI, Token}; - - #[tokio::test] - async fn jquants_api_test() -> anyhow::Result<()> { - let mailaddress = std::env::var("JQUANTS_MAIL_ADDRESS") - .with_context(|| "E-mail address must be set up for JQUANTS".to_string())?; - let password = std::env::var("JQUANTS_PASSWORD") - .with_context(|| "Password must be set up for JQUANTS".to_string())?; - let refresh_token = JQuantsAPI::get_refresh_token(mailaddress, password).await?; - assert!(!&refresh_token.value.is_empty()); - - let id_token = JQuantsAPI::get_id_token(&refresh_token).await?; - assert!(!&id_token.value.is_empty()); - - let token = Token { - refresh_token, - id_token, - }; - let now = Utc::now().with_timezone(&Tokyo).naive_local(); - assert!(!token.is_refresh_token_expired(now)); - assert!(!token.is_id_token_expired(now)); - Ok(()) - } - - #[test] - fn parse_refresh_token_payload_empty_fails() { - let body = br#"{"refreshToken": ""}"#; - assert!(parse_refresh_token_payload(body).is_err()); - } - - #[test] - fn parse_refresh_token_payload_missing_field_fails() { - let body = br#"{"unexpected": "value"}"#; - assert!(parse_refresh_token_payload(body).is_err()); - } - - #[test] - fn parse_id_token_payload_empty_fails() { - let body = br#"{"idToken": " "}"#; - assert!(parse_id_token_payload(body).is_err()); - } - - #[test] - fn parse_id_token_payload_missing_field_fails() { - let body = br#"{"error": "invalid"}"#; - assert!(parse_id_token_payload(body).is_err()); - } - - #[test] - fn parse_refresh_token_payload_handles_valid_body() { - let body = br#"{"refreshToken": "token123"}"#; - let parsed = parse_refresh_token_payload(body).expect("valid payload should parse"); - assert_eq!(parsed, "token123"); - } + use bytestring::ByteString; - #[test] - fn parse_refresh_token_payload_rejects_malformed_json() { - let body = br#"{"refresh": "token123"}"#; - assert!(parse_refresh_token_payload(body).is_err()); - } + use crate::infrastructure::jquants_api::JQuantsAPI; #[test] - fn parse_id_token_payload_handles_valid_body() { - let body = br#"{"idToken": "id-abc"}"#; - let parsed = parse_id_token_payload(body).expect("valid payload should parse"); - assert_eq!(parsed, "id-abc"); + fn new_rejects_empty_api_key() { + let result = JQuantsAPI::new(ByteString::from(" ")); + assert!(result.is_err()); } #[test] - fn parse_id_token_payload_rejects_empty_token() { - let body = br#"{"idToken": ""}"#; - assert!(parse_id_token_payload(body).is_err()); + fn new_accepts_non_empty_api_key() { + let result = JQuantsAPI::new(ByteString::from("api-key")); + assert!(result.is_ok()); } } diff --git a/src/infrastructure/repositories/company/jquants_api.rs b/src/infrastructure/repositories/company/jquants_api.rs index 2f06407..c11621a 100644 --- a/src/infrastructure/repositories/company/jquants_api.rs +++ b/src/infrastructure/repositories/company/jquants_api.rs @@ -10,7 +10,7 @@ use crate::domain::repositories::company::{queries, repository}; use crate::infrastructure::jquants_api::JQuantsAPI; use crate::infrastructure::repositories::company::structures::jquants_api::Response; -const COMPANY_URL: &str = "https://api.jquants.com/v1/listed/info"; +const COMPANY_URL: &str = "https://api.jquants.com/v2/equities/master"; #[async_trait] impl repository::Company for JQuantsAPI { @@ -22,11 +22,11 @@ impl repository::Company for JQuantsAPI { let url = format!("{COMPANY_URL}{qs}"); let response = Client::new() .get(url) - .bearer_auth(self.id_token.clone()) + .header("x-api-key", self.api_key.to_string()) .send() .await?; let response = &response.json::().await?; - let value = response["info"] + let value = response["data"] .get(0) .with_context(|| format!("Not found company. code = {}", query.code))?; Ok(From::from(Response(value))) @@ -35,12 +35,12 @@ impl repository::Company for JQuantsAPI { async fn get_vec_row_company(&self) -> Result> { let response = Client::new() .get(COMPANY_URL) - .bearer_auth(self.id_token.clone()) + .header("x-api-key", self.api_key.to_string()) .send() .await?; let response = &response.json::().await?; - let Some(companies) = response["info"].as_array() else { - bail!("[info] in response not found") + let Some(companies) = response["data"].as_array() else { + bail!("[data] in response not found") }; let vec_row_company = companies .par_iter() diff --git a/src/infrastructure/repositories/company/structures/jquants_api.rs b/src/infrastructure/repositories/company/structures/jquants_api.rs index e286214..82dd6a5 100644 --- a/src/infrastructure/repositories/company/structures/jquants_api.rs +++ b/src/infrastructure/repositories/company/structures/jquants_api.rs @@ -9,8 +9,8 @@ impl From> for model::RowCompany { fn from(value: Response<'_>) -> Self { let Response(value) = value; let code = String::from_json_string_value("Code", value).ok(); - let name = String::from_json_string_value("CompanyNameEnglish", value).ok(); - let market = String::from_json_string_value("MarketCode", value).ok(); + let name = String::from_json_string_value("CoNameEn", value).ok(); + let market = String::from_json_string_value("Mkt", value).ok(); Self { code, name, diff --git a/src/infrastructure/repositories/statement/jquants_api.rs b/src/infrastructure/repositories/statement/jquants_api.rs index 278efbe..a9055d3 100644 --- a/src/infrastructure/repositories/statement/jquants_api.rs +++ b/src/infrastructure/repositories/statement/jquants_api.rs @@ -1,15 +1,20 @@ +use crate::domain::models::statement::model; +use crate::domain::repositories::statement::{queries, repository}; +use crate::infrastructure::jquants_api::JQuantsAPI; +use crate::infrastructure::repositories::statement::structures::jquants_api::Response; use anyhow::{bail, Context}; use async_trait::async_trait; use query_string_builder::QueryString; use rayon::prelude::*; use reqwest::Client; +use serde_json::Value; -use crate::domain::models::statement::model; -use crate::domain::repositories::statement::{queries, repository}; -use crate::infrastructure::jquants_api::JQuantsAPI; -use crate::infrastructure::repositories::statement::structures::jquants_api::Response; +const STATEMENT_URL: &str = "https://api.jquants.com/v2/fins/summary"; -const STATEMENT_URL: &str = "https://api.jquants.com/v1/fins/statements"; +fn select_statement_record(rows: &[Value]) -> Option<&Value> { + rows.par_iter() + .find_last(|value| value["CurPerType"].as_str().is_some_and(|s| s == "FY")) +} #[async_trait] impl repository::Statement for JQuantsAPI { @@ -21,60 +26,70 @@ impl repository::Statement for JQuantsAPI { let url = format!("{STATEMENT_URL}{qs}"); let response = Client::new() .get(url) - .bearer_auth(self.id_token.clone()) + .header("x-api-key", self.api_key.to_string()) .send() .await?; - let response = &response.json::().await?; - let Some(response) = response["statements"].as_array() else { - bail!( - "response[statements] in response not found. code: {}", - query.code - ); + let response = &response.json::().await?; + let Some(response) = response["data"].as_array() else { + bail!("response[data] in response not found. code: {}", query.code); }; if response.is_empty() { bail!( - "response[statements] in response is empty array. code: {}", + "response[data] in response is empty array. code: {}", query.code ); } - response - .par_iter() - .filter_map(|value| { - // TypeOfCurrentPeriodはFY(Fiscal Year/事業年度)のみを対象とする - value["TypeOfCurrentPeriod"] - .as_str() - .filter(|&str| str.eq("FY"))?; - Some(From::from(Response { - code: query.code.to_string(), - value, - })) - }) - // API Docの以下の記述に従い、取得した配列データの最後尾を取得する。 - // 「DisclosureNumber: APIから出力されるjsonは開示番号で昇順に並んでいます。」 - .reduce_with(|_, b| b) - .with_context(|| { - let response = serde_json::to_string_pretty(response).unwrap(); - format!( - "struct model::Statement cannot be constructed. code: {}\n{}", - query.code, response - ) - }) + let selected = select_statement_record(response).with_context(|| { + let serialized = serde_json::to_string_pretty(response) + .unwrap_or_else(|_| "".to_string()); + format!( + "FY statement not found in response[data]. code: {}\n{}", + query.code, serialized + ) + })?; + + Ok(From::from(Response { + code: query.code.to_string(), + value: selected, + })) } } #[cfg(test)] mod tests { + use crate::domain::models::statement::model; + use crate::domain::repositories::statement::queries; + use crate::domain::repositories::statement::repository::Statement; + use crate::infrastructure::jquants_api::JQuantsAPI; + use crate::infrastructure::repositories::statement::jquants_api::select_statement_record; + use crate::shared::jquants_api::setup::Setup; use anyhow::Result; use bytestring::ByteString; use chrono::NaiveDate; use pretty_assertions::assert_eq; use rstest::*; + use serde_json::json; - use crate::domain::models::statement::model; - use crate::domain::repositories::statement::queries; - use crate::domain::repositories::statement::repository::Statement; - use crate::infrastructure::jquants_api::JQuantsAPI; - use crate::shared::jquants_api::setup::Setup; + #[test] + fn select_statement_record_prefers_latest_fy() { + let rows = vec![ + json!({"CurPerType": "Q1", "id": 1}), + json!({"CurPerType": "FY", "id": 2}), + json!({"CurPerType": "FY", "id": 3}), + ]; + let selected = select_statement_record(&rows).expect("record should be selected"); + assert_eq!(selected["id"], 3); + } + + #[test] + fn select_statement_record_returns_none_when_fy_missing() { + let rows = vec![ + json!({"CurPerType": "Q1", "id": 1}), + json!({"CurPerType": "Q2", "id": 2}), + ]; + let selected = select_statement_record(&rows); + assert!(selected.is_none()); + } #[fixture] async fn setup() -> Result { @@ -108,7 +123,7 @@ mod tests { .await .unwrap_err() .to_string(); - let expected = "response[statements] in response not found. code: ????"; + let expected = "response[data] in response not found. code: ????"; assert_eq!(actual, expected); let query = queries::get_statement::Query { code: "2995" }; @@ -117,7 +132,7 @@ mod tests { .await .unwrap_err() .to_string(); - let expected = "response[statements] in response is empty array. code: 2995"; + let expected = "response[data] in response is empty array. code: 2995"; assert_eq!(actual, expected); Ok(()) diff --git a/src/infrastructure/repositories/statement/structures/jquants_api.rs b/src/infrastructure/repositories/statement/structures/jquants_api.rs index 5ad05db..9a9c525 100644 --- a/src/infrastructure/repositories/statement/structures/jquants_api.rs +++ b/src/infrastructure/repositories/statement/structures/jquants_api.rs @@ -13,15 +13,15 @@ impl From> for model::RowStatement { fn from(value: Response<'_>) -> Self { let Response { code, value } = value; - let disclosed_date = NaiveDate::from_json_string_value("DisclosedDate", value).ok(); - let eps = f64::from_json_string_value("EarningsPerShare", value).ok(); - let bps = f64::from_json_string_value("BookValuePerShare", value).ok(); - let net_sales = f64::from_json_string_value("NetSales", value).ok(); - let opp = f64::from_json_string_value("OperatingProfit", value).ok(); - let orp = f64::from_json_string_value("OrdinaryProfit", value).ok(); - let profit = f64::from_json_string_value("Profit", value).ok(); - let equity = f64::from_json_string_value("Equity", value).ok(); - let total_assets = f64::from_json_string_value("TotalAssets", value).ok(); + let disclosed_date = NaiveDate::from_json_string_value("DiscDate", value).ok(); + let eps = f64::from_json_string_value("EPS", value).ok(); + let bps = f64::from_json_string_value("BPS", value).ok(); + let net_sales = f64::from_json_string_value("Sales", value).ok(); + let opp = f64::from_json_string_value("OP", value).ok(); + let orp = f64::from_json_string_value("OdP", value).ok(); + let profit = f64::from_json_string_value("NP", value).ok(); + let equity = f64::from_json_string_value("Eq", value).ok(); + let total_assets = f64::from_json_string_value("TA", value).ok(); Self { code, diff --git a/src/infrastructure/repositories/stock/jquants_api.rs b/src/infrastructure/repositories/stock/jquants_api.rs index e749dc7..d9bd1d0 100644 --- a/src/infrastructure/repositories/stock/jquants_api.rs +++ b/src/infrastructure/repositories/stock/jquants_api.rs @@ -9,7 +9,7 @@ use crate::domain::repositories::stock::{queries, repository}; use crate::infrastructure::jquants_api::JQuantsAPI; use crate::infrastructure::repositories::stock::structures::jquants_api::Response; -const DAILY_QUOTES_URL: &str = "https://api.jquants.com/v1/prices/daily_quotes"; +const DAILY_QUOTES_URL: &str = "https://api.jquants.com/v2/equities/bars/daily"; #[async_trait] impl repository::Stock for JQuantsAPI { @@ -24,11 +24,11 @@ impl repository::Stock for JQuantsAPI { let daily_quotes_url = format!("{DAILY_QUOTES_URL}{qs}"); let response = Client::new() .get(daily_quotes_url) - .bearer_auth(self.id_token.clone()) + .header("x-api-key", self.api_key.to_string()) .send() .await?; let response = response.json::().await?; - let value = response["daily_quotes"] + let value = response["data"] .get(0) .with_context(|| format!("Not found stock. code = {}", query.code.unwrap_or("")))?; Ok(From::from(Response(value))) @@ -45,13 +45,13 @@ impl repository::Stock for JQuantsAPI { let daily_quotes_url = format!("{DAILY_QUOTES_URL}{qs}"); let response = Client::new() .get(daily_quotes_url) - .bearer_auth(self.id_token.clone()) + .header("x-api-key", self.api_key.to_string()) .send() .await?; let response = &mut response.json::().await?; - let vec_row_stock: Vec = response["daily_quotes"] + let vec_row_stock: Vec = response["data"] .as_array() - .with_context(|| format!("daily_quotes is empty. code = {}", query.code.unwrap_or("")))? + .with_context(|| format!("data is empty. code = {}", query.code.unwrap_or("")))? .par_iter() .map(|value| From::from(Response(value))) .collect(); diff --git a/src/infrastructure/repositories/stock/structures/jquants_api.rs b/src/infrastructure/repositories/stock/structures/jquants_api.rs index c1189f5..3e96d01 100644 --- a/src/infrastructure/repositories/stock/structures/jquants_api.rs +++ b/src/infrastructure/repositories/stock/structures/jquants_api.rs @@ -11,12 +11,12 @@ impl From> for model::RowStock { fn from(value: Response<'_>) -> Self { let Response(value) = value; let date = NaiveDate::from_json_string_value("Date", value).ok(); - let open = value["Open"].as_f64(); - let high = value["High"].as_f64(); - let low = value["Low"].as_f64(); - let close = value["Close"].as_f64(); - let adj_close = value["AdjustmentClose"].as_f64(); - let volume = value["Volume"].as_f64().and_then(|volume| volume.to_u64()); + let open = value["O"].as_f64(); + let high = value["H"].as_f64(); + let low = value["L"].as_f64(); + let close = value["C"].as_f64(); + let adj_close = value["AdjC"].as_f64(); + let volume = value["Vo"].as_f64().and_then(|volume| volume.to_u64()); model::RowStock { date, open, diff --git a/src/shared/jquants_api/setup.rs b/src/shared/jquants_api/setup.rs index 931230f..d468555 100644 --- a/src/shared/jquants_api/setup.rs +++ b/src/shared/jquants_api/setup.rs @@ -1,77 +1,12 @@ use anyhow::{Context, Result}; use bytestring::ByteString; -use chrono::Utc; -use chrono_tz::Asia::Tokyo; -use dirs::config_dir; -use itertools::Either; -use std::fs; -use std::path::{Path, PathBuf}; -use tokio::fs::read; - -use crate::infrastructure::jquants_api::Token; - -const TOKEN_FILE_NAME: &str = "jquants_api_token.json"; -const APP_CONFIG_DIR: &str = "quantitative-data-analysis-rs"; pub struct Setup {} impl Setup { pub async fn run() -> Result { - let token_path = resolve_token_path()?; - let binary: Result> = read(&token_path) - .await - .with_context(|| format!("Token file not found: {}", token_path.display())); - let mailaddress = std::env::var("JQUANTS_MAIL_ADDRESS") - .with_context(|| "E-mail address MUST be set up for JQUANTS".to_string())?; - let password = std::env::var("JQUANTS_PASSWORD") - .with_context(|| "Password MUST be set up for JQUANTS".to_string())?; - let now = Utc::now().with_timezone(&Tokyo).naive_local(); - - let update_token = Token::update_token(binary, &mailaddress, &password, now).await?; - - let token = match update_token { - Either::Right(token) => { - let serialized = serde_json::to_vec(&token)?; - write_secure_token(&token_path, &serialized).await?; - token - } - Either::Left(token) => token, - }; - - let token = ByteString::from(token.id_token.value); - Ok(token) - } -} - -fn resolve_token_path() -> Result { - let mut config_root = - config_dir().ok_or_else(|| anyhow::anyhow!("Unable to determine config directory"))?; - config_root.push(APP_CONFIG_DIR); - ensure_private_dir(&config_root)?; - Ok(config_root.join(TOKEN_FILE_NAME)) -} - -fn ensure_private_dir(dir: &Path) -> Result<()> { - if !dir.exists() { - fs::create_dir_all(dir)?; - } - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt; - fs::set_permissions(dir, fs::Permissions::from_mode(0o700))?; - } - Ok(()) -} - -async fn write_secure_token(path: &Path, data: &[u8]) -> Result<()> { - tokio::fs::write(path, data) - .await - .with_context(|| format!("Failed to write token file: {}", path.display()))?; - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt; - let perms = fs::Permissions::from_mode(0o600); - tokio::fs::set_permissions(path, perms).await?; + let api_key = std::env::var("JQUANTS_API_KEY") + .with_context(|| "JQUANTS_API_KEY MUST be set up for JQUANTS".to_string())?; + Ok(ByteString::from(api_key)) } - Ok(()) } From c17b35bcfe3e24ac467af67bb2268acff60b1692 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Wed, 15 Apr 2026 21:47:11 +0900 Subject: [PATCH 10/15] chore: add code review instructions and checklist for PR reviews --- .../instructions/code-review.instructions.md | 62 +++++++++++++++++++ .github/prompts/code-review.prompt.md | 56 +++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 .github/instructions/code-review.instructions.md create mode 100644 .github/prompts/code-review.prompt.md diff --git a/.github/instructions/code-review.instructions.md b/.github/instructions/code-review.instructions.md new file mode 100644 index 0000000..2329b14 --- /dev/null +++ b/.github/instructions/code-review.instructions.md @@ -0,0 +1,62 @@ +--- +applyTo: "**/*" +excludeAgent: "coding-agent" +--- + +# code-review instructions + +## 目的 + +- 本リポジトリのコードレビューで、バグ・回帰・設計崩れを早期に検知する。 +- 指摘は再現性と修正方針が分かる形で提示し、手戻りを減らす。 + +## レビュー時の基本姿勢 + +- まず重大度順に指摘を列挙する(Critical/High/Medium/Low)。 +- 概要説明は最後に短くまとめる。指摘がない場合は明示する。 +- 推測で断定せず、根拠(コード位置、想定実行経路、テスト観点)を添える。 + +## 必須チェック項目 + +1. **正しさ/回帰** + - 境界値、null相当、空配列、0件データ、例外経路を扱えているか。 + - 既存の振る舞いを壊す変更がないか(互換性、入出力形式、公開API)。 +2. **アーキテクチャ整合** + - ヘキサゴナル境界を維持できているか。 + - ロジックが `domain`/`use_case`、外部適合が `infrastructure`/`presenter` に分離されているか。 +3. **Rust品質** + - `unwrap`/`expect` の乱用がないか(テスト・初期化を除く)。 + - `Result` とエラー型で失敗が明示され、エラー文脈が不足していないか。 + - 不要な `clone` や過剰アロケーションがないか。 +4. **テスト妥当性** + - 変更に対応するユニット/統合テストが追加・更新されているか。 + - 失敗ケース・境界ケースを検証しているか。 +5. **可読性/保守性** + - 命名が意図を表しているか。 + - 複雑な処理に最小限の補助コメントがあるか。 + +## レビューコメントの書き方 + +- 1指摘につき以下を含める: + - 重大度 + - 対象ファイルと行(例: `src/use_case/interactors/...:42`) + - 何が問題か + - なぜ問題か(実害/将来リスク) + - 修正案(短く具体的に) + +## 出力テンプレート + +- Findings + - `[Severity] path:line` 問題点、影響、修正案 +- Open Questions / Assumptions + - 仕様不明点や確認事項 +- Final Note + - 指摘なしの場合は「重大な指摘なし」。 + - 残留リスクや未実施テストがあれば明記。 + +## 参照ドキュメント + +- `.github/copilot-instructions.md` +- `.github/skills/coding-standards/SKILL.md` +- `.github/skills/testing-practices/SKILL.md` +- `~/.rust/rust-guidelines.txt` diff --git a/.github/prompts/code-review.prompt.md b/.github/prompts/code-review.prompt.md new file mode 100644 index 0000000..db1fa3c --- /dev/null +++ b/.github/prompts/code-review.prompt.md @@ -0,0 +1,56 @@ +--- +mode: agent +description: PRレビュー時に概要把握と内容確認の見逃しを防ぐための、チェックリスト連動プロンプト +--- + +# PR コードレビュー + +レビュー対象の差分(または変更ファイル一覧)を提示してください。 +以下の手順に沿ってレビューを実施し、所定テンプレートで結果を出力します。 + +## レビュー手順 + +### Step 1 — 変更概要の把握 + +- 変更の目的・背景をコミットメッセージや PR 説明から読み取る。 +- 変更規模(追加/削除行数、影響モジュール)を確認する。 +- ヘキサゴナル境界(`domain`/`use_case`/`infrastructure`/`presenter`)のどの層が触れられているかを特定する。 + +### Step 2 — チェックリストの実施 + +`.github/instructions/code-review.instructions.md` の「必須チェック項目」を順に確認する。 + +- [ ] **正しさ/回帰**: 境界値・null相当・空配列・0件データ・例外経路 +- [ ] **アーキテクチャ整合**: ヘキサゴナル境界、レイヤ分離 +- [ ] **Rust品質**: `unwrap`/`expect` の乱用、`Result` とエラー文脈、不要な `clone` +- [ ] **テスト妥当性**: 対応するユニット/統合テストの有無、失敗ケースの網羅 +- [ ] **可読性/保守性**: 命名の意図明確さ、複雑処理への補助コメント + +### Step 3 — 結果の出力 + +下記テンプレートに沿って出力する。 + +--- + +## Findings + + + + +## Open Questions / Assumptions + + + +## Final Note + + + +--- + +## 参照ドキュメント + +- `.github/instructions/code-review.instructions.md` +- `.github/skills/coding-standards/SKILL.md` +- `.github/skills/testing-practices/SKILL.md` +- `~/.rust/rust-guidelines.txt` + From 30f487e425fea6d5dc5ab924b04b7c176756777e Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sat, 18 Apr 2026 17:48:58 +0900 Subject: [PATCH 11/15] chore: update dependencies in Cargo.lock and remove obsolete packages --- Cargo.lock | 657 +++++++++++++++++++++++++---------------------------- 1 file changed, 311 insertions(+), 346 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e023470..efda453 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,6 +77,28 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "aws-lc-rs" +version = "1.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec6fb3fe69024a75fa7e1bfb48aa6cf59706a101658ea01bfd33b2b248a038f" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f50037ee5e1e41e7b8f9d161680a725bd1626cb6f8c7e901f91f942850852fe7" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", +] + [[package]] name = "base64" version = "0.22.1" @@ -117,9 +139,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.4" @@ -185,6 +215,25 @@ dependencies = [ "phf", ] +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "cookie" version = "0.18.1" @@ -353,6 +402,12 @@ dependencies = [ "litrs", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "either" version = "1.15.0" @@ -384,12 +439,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "fastrand" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" - [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -418,21 +467,6 @@ dependencies = [ "ttf-parser", ] -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.2" @@ -442,6 +476,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures-channel" version = "0.3.32" @@ -521,24 +561,11 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "r-efi 5.3.0", + "r-efi", "wasip2", "wasm-bindgen", ] -[[package]] -name = "getrandom" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" -dependencies = [ - "cfg-if", - "libc", - "r-efi 6.0.0", - "wasip2", - "wasip3", -] - [[package]] name = "glob" version = "0.3.3" @@ -672,22 +699,6 @@ dependencies = [ "webpki-roots", ] -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - [[package]] name = "hyper-util" version = "0.1.20" @@ -819,12 +830,6 @@ dependencies = [ "zerovec", ] -[[package]] -name = "id-arena" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - [[package]] name = "idna" version = "1.1.0" @@ -854,8 +859,6 @@ checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", "hashbrown 0.17.0", - "serde", - "serde_core", ] [[package]] @@ -898,6 +901,60 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys 0.3.1", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258" +dependencies = [ + "jni-sys 0.4.1", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.117", +] + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + [[package]] name = "js-sys" version = "0.3.95" @@ -910,12 +967,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "leb128fmt" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" - [[package]] name = "libc" version = "0.2.185" @@ -931,12 +982,6 @@ dependencies = [ "libc", ] -[[package]] -name = "linux-raw-sys" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" - [[package]] name = "litemap" version = "0.8.2" @@ -993,23 +1038,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "native-tls" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "num-conv" version = "0.2.1" @@ -1031,50 +1059,12 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" -[[package]] -name = "openssl" -version = "0.10.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfe4646e360ec77dff7dde40ed3d6c5fee52d156ef4a62f53973d38294dad87f" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.117", -] - [[package]] name = "openssl-probe" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" -[[package]] -name = "openssl-sys" -version = "0.9.113" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad2f2c0eba47118757e4c6d2bff2838f3e0523380021356e7875e858372ce644" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -1134,12 +1124,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" -[[package]] -name = "pkg-config" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" - [[package]] name = "potential_utf" version = "0.1.5" @@ -1174,16 +1158,6 @@ dependencies = [ "yansi", ] -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn 2.0.117", -] - [[package]] name = "proc-macro-crate" version = "3.5.0" @@ -1238,12 +1212,12 @@ dependencies = [ "pretty_assertions", "query-string-builder", "rayon", - "reqwest", + "reqwest 0.13.2", "rstest", "serde", "serde_json", - "simple_moving_average", "strum", + "ta", "thiserror 2.0.18", "tokio", "tokio-test", @@ -1286,6 +1260,7 @@ version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" dependencies = [ + "aws-lc-rs", "bytes", "getrandom 0.3.4", "lru-slab", @@ -1330,12 +1305,6 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" -[[package]] -name = "r-efi" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" - [[package]] name = "rand" version = "0.9.4" @@ -1450,6 +1419,44 @@ dependencies = [ "bytes", "cookie", "cookie_store", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "reqwest" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" +dependencies = [ + "base64", + "bytes", "encoding_rs", "futures-core", "h2", @@ -1458,23 +1465,20 @@ dependencies = [ "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "js-sys", "log", "mime", - "native-tls", "percent-encoding", "pin-project-lite", "quinn", "rustls", "rustls-pki-types", + "rustls-platform-verifier", "serde", "serde_json", - "serde_urlencoded", "sync_wrapper", "tokio", - "tokio-native-tls", "tokio-rustls", "tower", "tower-http", @@ -1483,7 +1487,6 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", ] [[package]] @@ -1544,25 +1547,13 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.61.2", -] - [[package]] name = "rustls" version = "0.23.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f9466fb2c14ea04357e91413efb882e2a6d4a406e625449bc0a5d360d53a21" dependencies = [ + "aws-lc-rs", "once_cell", "ring", "rustls-pki-types", @@ -1571,6 +1562,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pki-types" version = "1.14.0" @@ -1581,12 +1584,40 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + [[package]] name = "rustls-webpki" version = "0.103.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8279bb85272c9f10811ae6a6c547ff594d6a7f3c6c6b02ee9726d1d0dcfcdd06" dependencies = [ + "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -1604,6 +1635,15 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.29" @@ -1719,15 +1759,6 @@ dependencies = [ "libc", ] -[[package]] -name = "simple_moving_average" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a4b144ad185430cd033299e2c93e465d5a7e65fbb858593dc57181fa13cd310" -dependencies = [ - "num-traits", -] - [[package]] name = "siphasher" version = "1.0.2" @@ -1785,18 +1816,18 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "strum" -version = "0.27.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.27.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" dependencies = [ "heck", "proc-macro2", @@ -1883,17 +1914,10 @@ dependencies = [ ] [[package]] -name = "tempfile" -version = "3.27.0" +name = "ta" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" -dependencies = [ - "fastrand", - "getrandom 0.4.2", - "once_cell", - "rustix", - "windows-sys 0.61.2", -] +checksum = "609409d472a0a7d8d4dd9e19891bbdef546b9dce670c3057d0e02192dc541226" [[package]] name = "thiserror" @@ -2019,16 +2043,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.4" @@ -2196,12 +2210,6 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "untrusted" version = "0.9.0" @@ -2232,18 +2240,22 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -2265,16 +2277,7 @@ version = "1.0.3+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" dependencies = [ - "wit-bindgen 0.57.1", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen 0.51.0", + "wit-bindgen", ] [[package]] @@ -2332,40 +2335,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" -dependencies = [ - "leb128fmt", - "wasmparser", -] - -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags", - "hashbrown 0.15.5", - "indexmap", - "semver", -] - [[package]] name = "web-sys" version = "0.3.95" @@ -2386,6 +2355,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-root-certs" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31141ce3fc3e300ae89b78c0dd67f9708061d1d2eda54b8209346fd6be9a92c" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "webpki-roots" version = "1.0.7" @@ -2395,6 +2373,15 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "windows-core" version = "0.62.2" @@ -2465,6 +2452,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -2492,6 +2488,21 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -2525,6 +2536,12 @@ dependencies = [ "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" @@ -2537,6 +2554,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" @@ -2549,6 +2572,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -2573,6 +2602,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.52.6" @@ -2585,6 +2620,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" @@ -2597,6 +2638,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" @@ -2609,6 +2656,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -2630,100 +2683,12 @@ dependencies = [ "memchr", ] -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - [[package]] name = "wit-bindgen" version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn 2.0.117", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn 2.0.117", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - [[package]] name = "writeable" version = "0.6.3" @@ -2736,7 +2701,7 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc75c0aef2fb5095c7fb103dc2aaec2d0bdeed8c4a34b2cd504f083e29f6f128" dependencies = [ - "reqwest", + "reqwest 0.12.28", "serde", "serde_json", "thiserror 1.0.69", From 494503326470209c1d48ebf075db12884813cb2e Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 19 Apr 2026 14:37:12 +0900 Subject: [PATCH 12/15] chore: update file paths in documentation for Rust guidelines --- .github/copilot-instructions.md | 5 ++--- .github/skills/coding-standards/SKILL.md | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 5e5ceb1..88aee0c 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -11,8 +11,7 @@ ### Quick Reference -- Complete guidelines: `~/.rust/rust-guidelines.txt` -- `~/rust-toolchain` for Rust toolchain management +- Complete guidelines: `~/rust-guidelines.txt` - Focus areas: Error handling, API design, performance, interoperability - Tools: rustfmt, clippy, cargo-audit @@ -26,7 +25,7 @@ ### AI Assistant Integration When using AI coding assistants, reference the guidelines file: -"Please follow the Microsoft Rust guidelines in `~/.rust/rust-guidelines.txt`" +"Please follow the Microsoft Rust guidelines in `~/rust-guidelines.txt`" ## コミュニケーション diff --git a/.github/skills/coding-standards/SKILL.md b/.github/skills/coding-standards/SKILL.md index e9a9cf9..f6d9cd5 100644 --- a/.github/skills/coding-standards/SKILL.md +++ b/.github/skills/coding-standards/SKILL.md @@ -25,7 +25,7 @@ description: Rust の設計原則と品質ゲートを一貫適用し、ヘキ ## 作業手順 -1. 変更前に `~/.rust/rust-guidelines.txt` を参照し、該当セクション(エラー処理・API 設計・性能)を確認。 +1. 変更前に `~/rust-guidelines.txt` を参照し、該当セクション(エラー処理・API 設計・性能)を確認。 2. 実装ではレイヤリングと依存方向を常に意識し、必要ならユースケース→インフラの順で改修する。 3. フォーマットと静的解析をローカルで実行: ```bash @@ -47,5 +47,5 @@ description: Rust の設計原則と品質ゲートを一貫適用し、ヘキ ## 参考資料 -- Microsoft Pragmatic Rust Guidelines: `~/.rust/rust-guidelines.txt` +- Microsoft Pragmatic Rust Guidelines: `~/rust-guidelines.txt` - リポジトリ共通方針: `.github/copilot-instructions.md` From f54cda1ec254a3cffc2c718039320be5cbed3db4 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Thu, 7 May 2026 10:23:04 +0900 Subject: [PATCH 13/15] chore: update financial indicators and trend analysis to include MACD calculations --- Cargo.lock | 123 ------------- Cargo.toml | 1 - .../8473.T.financial_indicator_summary.json | 14 +- assets/8473.T.trend_reversal_analysis.json | 3 +- assets/9223.T.trend_reversal_analysis.json | 3 +- examples/financial_indicator.rs | 3 +- examples/make_companies.rs | 5 +- examples/trend_analysis.rs | 41 ++++- src/controller/trend_analysis/controller.rs | 14 +- src/domain/models/buy_sell_signal/model.rs | 11 ++ .../crossover_strategy/macd_cos/model.rs | 34 +++- .../crossover_strategy/sma_cos/model.rs | 36 ---- src/domain/models/macd/model.rs | 23 ++- .../models/trend_reversal_analysis/model.rs | 166 +++++++++++------- .../repositories/company/jquants_api.rs | 28 +-- .../repositories/statement/jquants_api.rs | 26 +-- .../repositories/stock/jquants_api.rs | 33 ++-- .../views/trend_analysis_summary/json/view.rs | 4 +- .../views/trend_reversal_analysis/view.rs | 6 + src/shared/jquants_api/setup.rs | 2 +- .../interactors/trend_analysis/interactor.rs | 10 ++ .../interfaces/trend_analysis/use_case.rs | 3 + 22 files changed, 276 insertions(+), 313 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efda453..167a925 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -497,17 +497,6 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" -[[package]] -name = "futures-macro" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.117", -] - [[package]] name = "futures-sink" version = "0.3.32" @@ -520,12 +509,6 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" -[[package]] -name = "futures-timer" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" - [[package]] name = "futures-util" version = "0.3.32" @@ -533,7 +516,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" dependencies = [ "futures-core", - "futures-macro", "futures-task", "pin-project-lite", "slab", @@ -566,12 +548,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "glob" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" - [[package]] name = "h2" version = "0.4.13" @@ -1158,15 +1134,6 @@ dependencies = [ "yansi", ] -[[package]] -name = "proc-macro-crate" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" -dependencies = [ - "toml_edit", -] - [[package]] name = "proc-macro2" version = "1.0.106" @@ -1213,7 +1180,6 @@ dependencies = [ "query-string-builder", "rayon", "reqwest 0.13.2", - "rstest", "serde", "serde_json", "strum", @@ -1403,12 +1369,6 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" -[[package]] -name = "relative-path" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" - [[package]] name = "reqwest" version = "0.12.28" @@ -1503,50 +1463,12 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rstest" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5a3193c063baaa2a95a33f03035c8a72b83d97a54916055ba22d35ed3839d49" -dependencies = [ - "futures-timer", - "futures-util", - "rstest_macros", -] - -[[package]] -name = "rstest_macros" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c845311f0ff7951c5506121a9ad75aec44d083c31583b2ea5a30bcb0b0abba0" -dependencies = [ - "cfg-if", - "glob", - "proc-macro-crate", - "proc-macro2", - "quote", - "regex", - "relative-path", - "rustc_version", - "syn 2.0.117", - "unicode-ident", -] - [[package]] name = "rustc-hash" version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - [[package]] name = "rustls" version = "0.23.38" @@ -1682,12 +1604,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" - [[package]] name = "serde" version = "1.0.228" @@ -2088,36 +2004,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml_datetime" -version = "1.1.1+spec-1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" -dependencies = [ - "serde_core", -] - -[[package]] -name = "toml_edit" -version = "0.25.11+spec-1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b59c4d22ed448339746c59b905d24568fcbb3ab65a500494f7b8c3e97739f2b" -dependencies = [ - "indexmap", - "toml_datetime", - "toml_parser", - "winnow", -] - -[[package]] -name = "toml_parser" -version = "1.1.2+spec-1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" -dependencies = [ - "winnow", -] - [[package]] name = "tower" version = "0.5.3" @@ -2674,15 +2560,6 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" -[[package]] -name = "winnow" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09dac053f1cd375980747450bfc7250c264eaae0583872e845c0c7cd578872b5" -dependencies = [ - "memchr", -] - [[package]] name = "wit-bindgen" version = "0.57.1" diff --git a/Cargo.toml b/Cargo.toml index 9b3f365..430bb15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,5 @@ ta = "=0.5.0" [dev-dependencies] indoc = "2.0.7" -rstest = "0.26.1" tokio-test = "0.4.4" pretty_assertions = "1.4.1" diff --git a/assets/8473.T.financial_indicator_summary.json b/assets/8473.T.financial_indicator_summary.json index 6ad0db5..c2d6acd 100644 --- a/assets/8473.T.financial_indicator_summary.json +++ b/assets/8473.T.financial_indicator_summary.json @@ -1,14 +1,14 @@ [ { "close_date": "2025-08-27", - "disclosed_date": "2026-03-13", - "pbr": null, - "per": null, + "disclosed_date": "2026-05-01", + "pbr": 2.4314095477477413, + "per": 10.125671095648, "oppr": null, "orpr": null, - "pr": null, - "mix": null, - "roe": null, - "roa": null + "pr": 22.544312026687656, + "mix": 24.61965337931188, + "roe": 17.717061212921553, + "roa": 1.116657352418128 } ] \ No newline at end of file diff --git a/assets/8473.T.trend_reversal_analysis.json b/assets/8473.T.trend_reversal_analysis.json index 78dbadf..074c20d 100644 --- a/assets/8473.T.trend_reversal_analysis.json +++ b/assets/8473.T.trend_reversal_analysis.json @@ -4,6 +4,7 @@ "sma_cos_date": "2023-08-30", "sma_cps_date": "2023-09-08", "body_engulfing_date": "1970-01-01", - "ms_es_date": "1970-01-01" + "ms_es_date": "1970-01-01", + "macd_cos_date": "2023-08-30" } ] \ No newline at end of file diff --git a/assets/9223.T.trend_reversal_analysis.json b/assets/9223.T.trend_reversal_analysis.json index c406555..2db0d29 100644 --- a/assets/9223.T.trend_reversal_analysis.json +++ b/assets/9223.T.trend_reversal_analysis.json @@ -4,6 +4,7 @@ "sma_cos_date": "2024-02-07", "sma_cps_date": "1970-01-01", "body_engulfing_date": "1970-01-01", - "ms_es_date": "2024-02-13" + "ms_es_date": "2024-02-13", + "macd_cos_date": "2024-02-05" } ] \ No newline at end of file diff --git a/examples/financial_indicator.rs b/examples/financial_indicator.rs index 71a9a87..ff10c82 100644 --- a/examples/financial_indicator.rs +++ b/examples/financial_indicator.rs @@ -1,14 +1,13 @@ use anyhow::Result; use chrono::NaiveDate; use pretty_assertions::assert_eq; - use quantitative_data_analysis_rs::shared::jquants_api::setup::Setup; use quantitative_data_analysis_rs::{controller, infrastructure, presenter, use_case}; #[tokio::main] async fn main() -> Result<()> { // JQUANTS APIのためのトークン準備 - let token = Setup::run().await?; + let token = Setup::run()?; // JQUANTS APIを用いたレポジトリの準備 let jquants_api = infrastructure::jquants_api::JQuantsAPI::new(token)?; diff --git a/examples/make_companies.rs b/examples/make_companies.rs index 671b9b4..9ff53cf 100644 --- a/examples/make_companies.rs +++ b/examples/make_companies.rs @@ -1,15 +1,14 @@ use csv::WriterBuilder; -use tokio::fs::write; - use quantitative_data_analysis_rs::domain::repositories::company::repository::Company; use quantitative_data_analysis_rs::infrastructure::jquants_api::JQuantsAPI; use quantitative_data_analysis_rs::infrastructure::repositories::company::structures::internal::tsv; use quantitative_data_analysis_rs::shared::jquants_api::setup::Setup; +use tokio::fs::write; #[tokio::main] async fn main() -> anyhow::Result<()> { // JQUANTS APIのためのトークン準備 - let token = Setup::run().await?; + let token = Setup::run()?; let jquants_api = JQuantsAPI::new(token)?; let companies = jquants_api.get_companies().await?; diff --git a/examples/trend_analysis.rs b/examples/trend_analysis.rs index 209dbfd..e72d1ca 100644 --- a/examples/trend_analysis.rs +++ b/examples/trend_analysis.rs @@ -2,8 +2,6 @@ use anyhow::Result; use bytes::Bytes; use chrono::NaiveDate; use itertools::{multiunzip, Itertools}; -use tokio::fs::write; - use quantitative_data_analysis_rs::infrastructure::repositories::company::structures::internal::tsv; use quantitative_data_analysis_rs::presenter::views::high_low_direction_signal_analysis::view::HighLowDirectionSignalAnalysis; use quantitative_data_analysis_rs::presenter::views::shared::crossover_pattern_filter::CrossoverPatternFilter; @@ -12,12 +10,16 @@ use quantitative_data_analysis_rs::presenter::views::trend_analysis_summary::jso use quantitative_data_analysis_rs::presenter::views::trend_reversal_analysis::view::TrendReversalAnalysis; use quantitative_data_analysis_rs::shared::jquants_api::setup::Setup; use quantitative_data_analysis_rs::{controller, infrastructure, presenter, use_case}; +use tokio::fs::write; const AFTER_DAYS_5: usize = 5; const FROM_END_DAYS_7: isize = 7; const MARUBOZU_BODY_MIN_RATIO: usize = 90; const MARUBOZU_WICK_MAX_RATIO: usize = 2; const DOJI_MAX_BODY_RATIO: usize = 5; +const FAST_PERIOD_12: usize = 12; +const SLOW_PERIOD_26: usize = 26; +const SIGNAL_PERIOD_9: usize = 9; const DATE_FORMAT: &str = "%Y/%m/%d"; const COMPANIES_TSV: &[u8] = include_bytes!("../assets/companies.tsv"); @@ -25,7 +27,7 @@ const COMPANIES_TSV: &[u8] = include_bytes!("../assets/companies.tsv"); #[tokio::main] async fn main() -> Result<()> { // JQUANTS APIのためのトークン準備 - let token = Setup::run().await?; + let token = Setup::run()?; // DSVを用いたレポジトリの準備 let dsv = infrastructure::dsv::Dsv::::new(false, Bytes::from(COMPANIES_TSV)); @@ -45,7 +47,16 @@ async fn main() -> Result<()> { let controller = controller::trend_analysis::controller::TrendAnalysis::new(&interactor, &presenter); let trend_analysis = controller - .analyze::( + .analyze::< + AFTER_DAYS_5, + FROM_END_DAYS_7, + MARUBOZU_BODY_MIN_RATIO, + MARUBOZU_WICK_MAX_RATIO, + DOJI_MAX_BODY_RATIO, + FAST_PERIOD_12, + SLOW_PERIOD_26, + SIGNAL_PERIOD_9, + >( "84730", "T", NaiveDate::from_ymd_opt(2022, 9, 9).unwrap(), @@ -70,7 +81,16 @@ async fn main() -> Result<()> { let controller = controller::trend_analysis::controller::TrendAnalysis::new(&interactor, &presenter); let trend_analysis = controller - .analyze::( + .analyze::< + AFTER_DAYS_5, + FROM_END_DAYS_7, + MARUBOZU_BODY_MIN_RATIO, + MARUBOZU_WICK_MAX_RATIO, + DOJI_MAX_BODY_RATIO, + FAST_PERIOD_12, + SLOW_PERIOD_26, + SIGNAL_PERIOD_9, + >( "84730", "T", NaiveDate::from_ymd_opt(2022, 9, 9).unwrap(), @@ -144,7 +164,16 @@ async fn main() -> Result<()> { let controller = controller::trend_analysis::controller::TrendAnalysis::new(&interactor, &presenter); let trend_analysis = controller - .analyze::( + .analyze::< + AFTER_DAYS_5, + FROM_END_DAYS_7, + MARUBOZU_BODY_MIN_RATIO, + MARUBOZU_WICK_MAX_RATIO, + DOJI_MAX_BODY_RATIO, + FAST_PERIOD_12, + SLOW_PERIOD_26, + SIGNAL_PERIOD_9, + >( "92230", "T", NaiveDate::from_ymd_opt(2023, 12, 25).unwrap(), diff --git a/src/controller/trend_analysis/controller.rs b/src/controller/trend_analysis/controller.rs index 9aa35eb..59a90d4 100644 --- a/src/controller/trend_analysis/controller.rs +++ b/src/controller/trend_analysis/controller.rs @@ -31,6 +31,9 @@ where const MARUBOZU_BODY_MIN_RATIO: usize, const MARUBOZU_WICK_MAX_RATIO: usize, const DOJI_MAX_BODY_RATIO: usize, + const FAST_PERIOD: usize, + const SLOW_PERIOD: usize, + const SIGNAL_PERIOD: usize, >( &self, code: impl Into, @@ -43,7 +46,16 @@ where input::TrendAnalysis::new(code, market, start_date, end_date, crossover_pattern_filter); let output = self .interactor - .handle::( + .handle::< + AFTER_DAYS, + FROM_END_DAYS, + MARUBOZU_BODY_MIN_RATIO, + MARUBOZU_WICK_MAX_RATIO, + DOJI_MAX_BODY_RATIO, + FAST_PERIOD, + SLOW_PERIOD, + SIGNAL_PERIOD, + >( input, ) .await?; diff --git a/src/domain/models/buy_sell_signal/model.rs b/src/domain/models/buy_sell_signal/model.rs index ed2a009..e2d7bcf 100644 --- a/src/domain/models/buy_sell_signal/model.rs +++ b/src/domain/models/buy_sell_signal/model.rs @@ -1,3 +1,4 @@ +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; use chrono::NaiveDate; use serde::{Deserialize, Serialize}; use strum::Display; @@ -13,6 +14,16 @@ pub enum BuySellSignalType { Sell, } +impl From for BuySellSignalType { + fn from(crossover_pattern: CrossoverPattern) -> Self { + match crossover_pattern { + CrossoverPattern::Neither => Self::Stay, + CrossoverPattern::GoldenCross => Self::Buy, + CrossoverPattern::DeadCross => Self::Sell, + } + } +} + /// 売買シグナル #[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] pub struct BuySellSignal { diff --git a/src/domain/models/crossover_strategy/macd_cos/model.rs b/src/domain/models/crossover_strategy/macd_cos/model.rs index a74fc51..8174491 100644 --- a/src/domain/models/crossover_strategy/macd_cos/model.rs +++ b/src/domain/models/crossover_strategy/macd_cos/model.rs @@ -1,5 +1,5 @@ use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; -use crate::domain::models::macd::model::{MACDs, MACD}; +use crate::domain::models::macd::model::{MACD, MACDs}; use chrono::NaiveDate; use deref_derive::{Deref, DerefMut}; use rayon::prelude::*; @@ -18,6 +18,38 @@ pub struct MacdCos { pub struct MacdCoses(Vec); impl From> for MacdCoses { + /// + /// # Examples + /// ``` + /// use bytes::Bytes; + /// use chrono::NaiveDate; + /// use rayon::prelude::*; + /// + /// use quantitative_data_analysis_rs::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; + /// use quantitative_data_analysis_rs::domain::models::crossover_strategy::macd_cos::model::{ MacdCos, MacdCoses }; + /// use quantitative_data_analysis_rs::domain::models::macd::model::MACDs; + /// use quantitative_data_analysis_rs::domain::models::stock::model; + /// use quantitative_data_analysis_rs::domain::repositories::stock::queries; + /// use quantitative_data_analysis_rs::domain::repositories::stock::repository::Stock; + /// use quantitative_data_analysis_rs::infrastructure::dsv::Dsv; + /// use quantitative_data_analysis_rs::infrastructure::repositories::stock::structures::internal::csv; + /// + /// const FAST_PERIOD: usize = 12; + /// const SLOW_PERIOD: usize = 26; + /// const SIGNAL_PERIOD: usize = 9; + /// const CSV: &[u8] = include_bytes!("../../../../../assets/8473.T.csv"); + /// + /// tokio_test::block_on(async { + /// let dsv = Dsv::::new(true, Bytes::from(CSV)); + /// let query = queries::get_stocks::Query { + /// ..Default::default() + /// }; + /// let stocks = dsv.get_stocks(&query).await.unwrap(); + /// let macds = MACDs::::from(stocks.as_slice()); + /// let macd_coses = MacdCoses::from(macds); + /// assert_eq!(macd_coses.len(), 245); + /// }); + /// ``` fn from(value: MACDs) -> Self { let vec_macd_cos = value .as_slice() diff --git a/src/domain/models/crossover_strategy/sma_cos/model.rs b/src/domain/models/crossover_strategy/sma_cos/model.rs index 84e611d..7140ded 100644 --- a/src/domain/models/crossover_strategy/sma_cos/model.rs +++ b/src/domain/models/crossover_strategy/sma_cos/model.rs @@ -20,42 +20,6 @@ pub struct SmaCos { #[derive(Debug, Clone, PartialEq, PartialOrd, Default, Deref, DerefMut)] pub struct SmaCoses(Vec); -impl SmaCoses { - /// Retrieves the latest date based on the closing value that matches a specified pattern. - /// - /// # Parameters - /// - `crossover_pattern: &CrossoverPattern` - /// A reference to the `CrossoverPattern` object used to match against the `close` value - /// in the `pattern_close_volume` of each `SmaCos` item. - /// - /// # Returns - /// - `Option`: - /// - Returns `Some(date)` if one or more `SmaCos` objects match the given pattern, where `date` is the latest matching date. - /// - Returns `None` if no matches are found. - /// - /// # Process - /// - The method uses parallel iteration (`par_iter`) for efficiency when traversing the `MACOSES` collection. - /// - It filters `SmaCos` objects where the `close` field of `pattern_close_volume` equals the given `CrossoverPattern`. - /// - The filtered results are then sorted by the `date` field in ascending order. - /// - Finally, the latest date (if any) is extracted and returned. - /// - /// # Notes - /// - This method leverages the `rayon` library for parallel processing, ideal for handling large datasets. - /// - Sorting is done using `itertools`'s `sorted_by` for a clear and concise sorting step. - pub fn latest_based_on_close(&self, crossover_pattern: &CrossoverPattern) -> Option { - self.par_iter() - .filter_map(|sma_cos| { - if sma_cos.crossover_pattern_close.0.eq(crossover_pattern) { - Some(sma_cos) - } else { - None - } - }) - .max_by(|a, b| Ord::cmp(&a.date, &b.date)) - .map(|x| x.date) - } -} - impl<'a> From> for SmaCoses { /// /// # Examples diff --git a/src/domain/models/macd/model.rs b/src/domain/models/macd/model.rs index 8ac5886..39c8f4e 100644 --- a/src/domain/models/macd/model.rs +++ b/src/domain/models/macd/model.rs @@ -1,8 +1,8 @@ use crate::domain::models::stock::model::Stock; use chrono::NaiveDate; use deref_derive::{Deref, DerefMut}; -use ta::indicators::MovingAverageConvergenceDivergence; use ta::Next; +use ta::indicators::MovingAverageConvergenceDivergence; #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default)] pub struct MACD { @@ -36,15 +36,22 @@ pub struct MACDs(Vec); /// ..Default::default() /// }; /// let stocks = dsv.get_stocks(&query).await.unwrap(); -/// let macds = MACDs::::try_from(stocks.as_slice()).unwrap(); +/// let macds = MACDs::::from(stocks.as_slice()); /// assert_eq!(macds.len(), 35); /// }); /// ``` -impl TryFrom<&[Stock]> for MACDs { - type Error = anyhow::Error; - - fn try_from(value: &[Stock]) -> Result { - let mut macd = MovingAverageConvergenceDivergence::new(F, S, SG)?; +impl From<&[Stock]> for MACDs { + fn from(value: &[Stock]) -> Self { + const { + assert!(F > 0, "F(fast period) is greater than 0"); + } + const { + assert!(S > 0, "S(slow period) is greater than 0"); + } + const { + assert!(SG > 0, "SG(signal period) is greater than 0"); + } + let mut macd = MovingAverageConvergenceDivergence::new(F, S, SG).unwrap(); let macds = value .iter() .map(|stock| { @@ -57,6 +64,6 @@ impl TryFrom<&[Stock]> for MACD } }) .collect::>(); - Ok(MACDs(macds)) + MACDs(macds) } } diff --git a/src/domain/models/trend_reversal_analysis/model.rs b/src/domain/models/trend_reversal_analysis/model.rs index 90f0421..7054eb8 100644 --- a/src/domain/models/trend_reversal_analysis/model.rs +++ b/src/domain/models/trend_reversal_analysis/model.rs @@ -2,15 +2,18 @@ use rayon::prelude::*; use crate::domain::models::buy_sell_signal::model::BuySellSignalType::{Buy, Sell, Stay}; use crate::domain::models::buy_sell_signal::model::{BuySellSignal, BuySellSignalType}; +use crate::domain::models::crossover_strategy::crossover_pattern; +use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern; use crate::domain::models::crossover_strategy::crossover_pattern::model::CrossoverPattern::{ DeadCross, GoldenCross, }; -use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; +use crate::domain::models::crossover_strategy::macd_cos::model::{MacdCos, MacdCoses}; +use crate::domain::models::crossover_strategy::sma_cos::model::{SmaCos, SmaCoses}; use crate::domain::models::crossover_strategy::sma_cps::model::SmaCps; use chrono::NaiveDate; use serde::{Deserialize, Serialize}; -/// SmaCos/SmaCps/BodyEngulfing/MsEsの売買シグナルから相場転換を分析する +/// SmaCos/SmaCps/BodyEngulfing/MsEs/MacdCosの売買シグナルから相場転換を分析する #[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] pub struct TrendReversalAnalysis { pub r#type: BuySellSignalType, @@ -18,44 +21,68 @@ pub struct TrendReversalAnalysis { pub sma_cps: Option<(NaiveDate, BuySellSignalType)>, pub body_engulfing: Option<(NaiveDate, BuySellSignalType)>, pub ms_es: Option<(NaiveDate, BuySellSignalType)>, + pub macd_cos: Option<(NaiveDate, BuySellSignalType)>, } -impl TrendReversalAnalysis { - fn latest_buy_sell_signal_date( - buy_sell_signal: &[BuySellSignal], - r#type: &BuySellSignalType, - ) -> Option { - buy_sell_signal - .par_iter() - .filter(|signal| signal.r#type.eq(r#type)) - .max_by(|a, b| Ord::cmp(&a.date, &b.date)) - .map(|signal| signal.date) - } +fn all_signals_match( + signal0: Option<(NaiveDate, BuySellSignalType)>, + signal1: Option<(NaiveDate, BuySellSignalType)>, + signal2: Option<(NaiveDate, BuySellSignalType)>, + signal3: Option<(NaiveDate, BuySellSignalType)>, + signal4: Option<(NaiveDate, BuySellSignalType)>, + target: BuySellSignalType, +) -> bool { + signal0.is_some_and(|s| s.1 == target) + && signal1.is_some_and(|s| s.1 == target) + && signal2.is_some_and(|s| s.1 == target) + && signal3.is_some_and(|s| s.1 == target) + && signal4.is_some_and(|s| s.1 == target) +} + +fn latest_buy_or_sell_signal_type( + buy_sell_signal: &[BuySellSignal], +) -> Option<(NaiveDate, BuySellSignalType)> { + buy_sell_signal + .par_iter() + .filter_map(|signal| { + matches!(signal.r#type, Buy | Sell).then_some((signal.date, signal.r#type)) + }) + .max_by(|(a, _), (b, _)| Ord::cmp(a, b)) +} - fn resolve_latest_signal( - buy_date: Option, - sell_date: Option, - ) -> Option<(NaiveDate, BuySellSignalType)> { - match (buy_date, sell_date) { - (Some(buy_date), Some(sell_date)) => { - if buy_date >= sell_date { - Some((buy_date, Buy)) - } else { - Some((sell_date, Sell)) - } +fn latest_signal_from_buy_sell_dates( + buy_date: Option, + sell_date: Option, +) -> Option<(NaiveDate, BuySellSignalType)> { + match (buy_date, sell_date) { + (Some(buy_date), Some(sell_date)) => { + if buy_date >= sell_date { + Some((buy_date, Buy)) + } else { + Some((sell_date, Sell)) } - (Some(buy_date), None) => Some((buy_date, Buy)), - (None, Some(sell_date)) => Some((sell_date, Sell)), - _ => None, } + (Some(buy_date), None) => Some((buy_date, Buy)), + (None, Some(sell_date)) => Some((sell_date, Sell)), + _ => None, } } +fn crossover_pattern_to_buy_sell_signal( + date: NaiveDate, + crossover_pattern: CrossoverPattern, +) -> Option<(NaiveDate, BuySellSignalType)> { + matches!(crossover_pattern, GoldenCross | DeadCross) + .then_some((date, crossover_pattern)) + .map(|(date, crossover_pattern)| (date, BuySellSignalType::from(crossover_pattern))) +} + pub struct TrendReversalAnalysisSet<'a> { pub body_engulfings: &'a [BuySellSignal], pub ms_eses: &'a [BuySellSignal], pub sma_cps: &'a SmaCps, pub sma_coses: &'a SmaCoses, + pub macd_coses: &'a MacdCoses, } impl<'a> From> for TrendReversalAnalysis { @@ -65,39 +92,45 @@ impl<'a> From> for TrendReversalAnalysis { sma_coses, body_engulfings, ms_eses, + macd_coses, } = value; - let sma_cps = Self::resolve_latest_signal(sma_cps.buy, sma_cps.sell); - let sma_cos_close_golden = sma_coses.latest_based_on_close(&GoldenCross); - let sma_cos_close_dead = sma_coses.latest_based_on_close(&DeadCross); - let sma_cos = Self::resolve_latest_signal(sma_cos_close_golden, sma_cos_close_dead); - let body_engulfing_buy = Self::latest_buy_sell_signal_date(body_engulfings, &Buy); - let body_engulfing_sell = Self::latest_buy_sell_signal_date(body_engulfings, &Sell); - let body_engulfing = Self::resolve_latest_signal(body_engulfing_buy, body_engulfing_sell); - let ms_es_buy = Self::latest_buy_sell_signal_date(ms_eses, &Buy); - let ms_es_sell = Self::latest_buy_sell_signal_date(ms_eses, &Sell); - let ms_es = Self::resolve_latest_signal(ms_es_buy, ms_es_sell); - // 終値のSmaCos GoldenCross/BodyEngulfing Buy/MsEs Buy/SmaCps Buy が揃っていれば Buy - // 終値のSmaCos DeadCross/BodyEngulfing Sell/MsEs Sell/SmaCps Sell が揃っていれば Sell + let sma_cos = sma_coses + .par_iter() + .filter_map( + |&SmaCos { + date, + crossover_pattern_close, + .. + }| { + let crossover_pattern::close::model::CrossoverPattern(crossover_pattern) = + crossover_pattern_close; + crossover_pattern_to_buy_sell_signal(date, crossover_pattern) + }, + ) + .max_by(|(a, _), (b, _)| Ord::cmp(a, b)); + let macd_cos = macd_coses + .par_iter() + .filter_map( + |&MacdCos { + date, + crossover_pattern, + .. + }| crossover_pattern_to_buy_sell_signal(date, crossover_pattern), + ) + .max_by(|(a, _), (b, _)| Ord::cmp(a, b)); + let sma_cps = latest_signal_from_buy_sell_dates(sma_cps.buy, sma_cps.sell); + let body_engulfing = latest_buy_or_sell_signal_type(body_engulfings); + let ms_es = latest_buy_or_sell_signal_type(ms_eses); + // 終値のSmaCos GoldenCross/MacdCos GoldenCross/BodyEngulfing Buy/MsEs Buy/SmaCps Buy が揃っていれば Buy + // 終値のSmaCos DeadCross/MacdCos DeadCross/BodyEngulfing Sell/MsEs Sell/SmaCps Sell が揃っていれば Sell // それ以外はStay - let r#type = match (sma_cos, sma_cps, body_engulfing, ms_es) { - (Some(sma_cos), Some(sma_cps), Some(body_engulfing), Some(ms_es)) - if sma_cos.1.eq(&Buy) - && sma_cps.1.eq(&Buy) - && body_engulfing.1.eq(&Buy) - && ms_es.1.eq(&Buy) => - { - Buy - } - (Some(sma_cos), Some(sma_cps), Some(body_engulfing), Some(ms_es)) - if sma_cos.1.eq(&Sell) - && sma_cps.1.eq(&Sell) - && body_engulfing.1.eq(&Sell) - && ms_es.1.eq(&Sell) => - { - Sell - } - _ => Stay, + let r#type = if all_signals_match(sma_cos, macd_cos, sma_cps, body_engulfing, ms_es, Buy) { + Buy + } else if all_signals_match(sma_cos, macd_cos, sma_cps, body_engulfing, ms_es, Sell) { + Sell + } else { + Stay }; Self { r#type, @@ -105,22 +138,20 @@ impl<'a> From> for TrendReversalAnalysis { sma_cos, body_engulfing, ms_es, + macd_cos, } } } #[cfg(test)] mod tests { - use anyhow::Result; - use bytes::Bytes; - use chrono::NaiveDate; - use pretty_assertions::assert_eq; - use crate::domain::models::body_engulfing::model::BodyEngulfings; use crate::domain::models::buy_sell_signal::model::BuySellSignalType::{Buy, Sell, Stay}; use crate::domain::models::candle_stick::model::CandleSticks; + use crate::domain::models::crossover_strategy::macd_cos::model::MacdCoses; use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; use crate::domain::models::crossover_strategy::sma_cps::model::SmaCps; + use crate::domain::models::macd::model::MACDs; use crate::domain::models::ms_es::model::MsEses; use crate::domain::models::sma::model::{SMAListPair, SMAListTrio, SMAs}; use crate::domain::models::trend_reversal_analysis::model::TrendReversalAnalysis; @@ -129,10 +160,17 @@ mod tests { use crate::domain::repositories::stock::repository::Stock; use crate::infrastructure::dsv::Dsv; use crate::infrastructure::repositories::stock::structures::internal::csv; + use anyhow::Result; + use bytes::Bytes; + use chrono::NaiveDate; + use pretty_assertions::assert_eq; const MARUBOZU_BODY_MIN_RATIO: usize = 90; const MARUBOZU_WICK_MAX_RATIO: usize = 2; const DOJI_MAX_BODY_RATIO: usize = 5; + const FAST_PERIOD: usize = 12; + const SLOW_PERIOD: usize = 26; + const SIGNAL_PERIOD: usize = 9; const CSV: &[u8] = include_bytes!("../../../../assets/8473.T.csv"); #[tokio::test] @@ -163,11 +201,14 @@ mod tests { smas_p: smas_50.as_slice(), }; let sma_cps = SmaCps::from((stocks.as_slice(), sma_list_trio)); + let macds = MACDs::::from(stocks.as_slice()); + let macd_coses = MacdCoses::from(macds); let trend_reversal_analysis_set = TrendReversalAnalysisSet { body_engulfings: &body_engulfings, ms_eses: &ms_eses, sma_cps: &sma_cps, sma_coses: &sma_coses, + macd_coses: &macd_coses, }; let actual = TrendReversalAnalysis::from(trend_reversal_analysis_set); let expected = TrendReversalAnalysis { @@ -176,6 +217,7 @@ mod tests { body_engulfing: NaiveDate::from_ymd_opt(2023, 8, 14).map(|date| (date, Sell)), ms_es: NaiveDate::from_ymd_opt(2023, 5, 24).map(|date| (date, Sell)), sma_cps: NaiveDate::from_ymd_opt(2023, 9, 8).map(|date| (date, Sell)), + macd_cos: NaiveDate::from_ymd_opt(2023, 8, 30).map(|date| (date, Buy)), }; assert_eq!(actual, expected); Ok(()) diff --git a/src/infrastructure/repositories/company/jquants_api.rs b/src/infrastructure/repositories/company/jquants_api.rs index c11621a..900cd38 100644 --- a/src/infrastructure/repositories/company/jquants_api.rs +++ b/src/infrastructure/repositories/company/jquants_api.rs @@ -1,15 +1,14 @@ -use anyhow::{Context, Result, bail}; +use crate::domain::models::company::model; +use crate::domain::repositories::company::{queries, repository}; +use crate::infrastructure::jquants_api::JQuantsAPI; +use crate::infrastructure::repositories::company::structures::jquants_api::Response; +use anyhow::{bail, Context, Result}; use async_trait::async_trait; use query_string_builder::QueryString; use rayon::prelude::*; use reqwest::Client; use serde_json::Value; -use crate::domain::models::company::model; -use crate::domain::repositories::company::{queries, repository}; -use crate::infrastructure::jquants_api::JQuantsAPI; -use crate::infrastructure::repositories::company::structures::jquants_api::Response; - const COMPANY_URL: &str = "https://api.jquants.com/v2/equities/master"; #[async_trait] @@ -53,9 +52,7 @@ impl repository::Company for JQuantsAPI { #[cfg(test)] mod tests { use anyhow::Result; - use bytestring::ByteString; use pretty_assertions::assert_eq; - use rstest::*; use crate::domain::models::company::model; use crate::domain::repositories::company::queries; @@ -63,15 +60,9 @@ mod tests { use crate::infrastructure::jquants_api::JQuantsAPI; use crate::shared::jquants_api::setup::Setup; - #[fixture] - async fn setup() -> Result { - Setup::run().await - } - - #[rstest] #[tokio::test] - async fn get_row_company_test(#[future] setup: Result) -> Result<()> { - let token = setup.await?; + async fn get_row_company_test() -> Result<()> { + let token = Setup::run()?; let repository = JQuantsAPI::new(token)?; let query = queries::get_company::Query { code: "8473", @@ -88,10 +79,9 @@ mod tests { Ok(()) } - #[rstest] #[tokio::test] - async fn get_vec_row_company_test(#[future] setup: Result) -> Result<()> { - let token = setup.await?; + async fn get_vec_row_company_test() -> Result<()> { + let token = Setup::run()?; let repository = JQuantsAPI::new(token)?; let vec_row_company = repository.get_vec_row_company().await?; assert!(vec_row_company.len() > 4400); diff --git a/src/infrastructure/repositories/statement/jquants_api.rs b/src/infrastructure/repositories/statement/jquants_api.rs index a9055d3..2ec3505 100644 --- a/src/infrastructure/repositories/statement/jquants_api.rs +++ b/src/infrastructure/repositories/statement/jquants_api.rs @@ -64,10 +64,8 @@ mod tests { use crate::infrastructure::repositories::statement::jquants_api::select_statement_record; use crate::shared::jquants_api::setup::Setup; use anyhow::Result; - use bytestring::ByteString; use chrono::NaiveDate; use pretty_assertions::assert_eq; - use rstest::*; use serde_json::json; #[test] @@ -91,29 +89,23 @@ mod tests { assert!(selected.is_none()); } - #[fixture] - async fn setup() -> Result { - Setup::run().await - } - - #[rstest] #[tokio::test] - async fn get_row_statement_test(#[future] setup: Result) -> Result<()> { - let token = setup.await?; + async fn get_row_statement_test() -> Result<()> { + let token = Setup::run()?; let repository = JQuantsAPI::new(token)?; let query = queries::get_statement::Query { code: "8473" }; let actual = repository.get_row_statement(&query).await?; let expected = model::RowStatement { code: "8473".to_string(), - disclosed_date: NaiveDate::from_ymd_opt(2026, 3, 13), - eps: None, - bps: None, - net_sales: None, + disclosed_date: NaiveDate::from_ymd_opt(2026, 5, 1), + eps: Some(666.82), + bps: Some(2776.99), + net_sales: Some(1_896_607_000_000.0), opp: None, orp: None, - profit: None, - equity: None, - total_assets: None, + profit: Some(427_577_000_000.0), + equity: Some(2_413_363_000_000.0), + total_assets: Some(38_290_797_000_000.0), }; assert_eq!(actual, expected); diff --git a/src/infrastructure/repositories/stock/jquants_api.rs b/src/infrastructure/repositories/stock/jquants_api.rs index d9bd1d0..52ccedd 100644 --- a/src/infrastructure/repositories/stock/jquants_api.rs +++ b/src/infrastructure/repositories/stock/jquants_api.rs @@ -1,14 +1,13 @@ +use crate::domain::models::stock::model; +use crate::domain::repositories::stock::{queries, repository}; +use crate::infrastructure::jquants_api::JQuantsAPI; +use crate::infrastructure::repositories::stock::structures::jquants_api::Response; use anyhow::Context; use async_trait::async_trait; use query_string_builder::QueryString; use rayon::prelude::*; use reqwest::Client; -use crate::domain::models::stock::model; -use crate::domain::repositories::stock::{queries, repository}; -use crate::infrastructure::jquants_api::JQuantsAPI; -use crate::infrastructure::repositories::stock::structures::jquants_api::Response; - const DAILY_QUOTES_URL: &str = "https://api.jquants.com/v2/equities/bars/daily"; #[async_trait] @@ -60,26 +59,17 @@ impl repository::Stock for JQuantsAPI { } #[cfg(test)] mod tests { - use bytestring::ByteString; - use chrono::NaiveDate; - use pretty_assertions::assert_eq; - use rstest::*; - use crate::domain::models::stock::model; use crate::domain::repositories::stock::queries; use crate::domain::repositories::stock::repository::Stock; use crate::infrastructure::jquants_api::JQuantsAPI; use crate::shared::jquants_api::setup::Setup; + use chrono::NaiveDate; + use pretty_assertions::assert_eq; - #[fixture] - async fn setup() -> anyhow::Result { - Setup::run().await - } - - #[rstest] #[tokio::test] - async fn get_row_stock_test(#[future] setup: anyhow::Result) -> anyhow::Result<()> { - let token = setup.await?; + async fn get_row_stock_test() -> anyhow::Result<()> { + let token = Setup::run()?; let repository = JQuantsAPI::new(token)?; let query = queries::get_stock::Query { code: Some("84730"), @@ -100,12 +90,9 @@ mod tests { Ok(()) } - #[rstest] #[tokio::test] - async fn get_vec_row_stock_test( - #[future] setup: anyhow::Result, - ) -> anyhow::Result<()> { - let token = setup.await?; + async fn get_vec_row_stock_test() -> anyhow::Result<()> { + let token = Setup::run()?; let repository = JQuantsAPI::new(token)?; let query = queries::get_stocks::Query { code: Some("84730"), diff --git a/src/presenter/views/trend_analysis_summary/json/view.rs b/src/presenter/views/trend_analysis_summary/json/view.rs index da66c1d..c9b5960 100644 --- a/src/presenter/views/trend_analysis_summary/json/view.rs +++ b/src/presenter/views/trend_analysis_summary/json/view.rs @@ -101,7 +101,8 @@ mod tests { "sma_cos_date": "2023-08-15", "sma_cps_date": "2023-07-04", "body_engulfing_date": "2023-06-01", - "ms_es_date": "2023-07-26" + "ms_es_date": "2023-07-26", + "macd_cos_date": "2023-08-15" } }"#}; let sma_cos_analysis = SmaCosAnalysis { @@ -122,6 +123,7 @@ mod tests { sma_cps_date: NaiveDate::from_ymd_opt(2023, 7, 4).unwrap(), body_engulfing_date: NaiveDate::from_ymd_opt(2023, 6, 1).unwrap(), ms_es_date: NaiveDate::from_ymd_opt(2023, 7, 26).unwrap(), + macd_cos_date: NaiveDate::from_ymd_opt(2023, 8, 15).unwrap(), }; let json_row = JsonRow { code: "8473".to_string(), diff --git a/src/presenter/views/trend_reversal_analysis/view.rs b/src/presenter/views/trend_reversal_analysis/view.rs index 6779b5a..c6de49f 100644 --- a/src/presenter/views/trend_reversal_analysis/view.rs +++ b/src/presenter/views/trend_reversal_analysis/view.rs @@ -15,6 +15,8 @@ pub struct TrendReversalAnalysis { pub body_engulfing_date: NaiveDate, #[serde(with = "naive_date::primitive")] pub ms_es_date: NaiveDate, + #[serde(with = "naive_date::primitive")] + pub macd_cos_date: NaiveDate, } impl From<&model::TrendReversalAnalysis> for TrendReversalAnalysis { @@ -25,6 +27,7 @@ impl From<&model::TrendReversalAnalysis> for TrendReversalAnalysis { body_engulfing, ms_es, sma_cps, + macd_cos, } = value; Self { r#type: *r#type, @@ -38,6 +41,9 @@ impl From<&model::TrendReversalAnalysis> for TrendReversalAnalysis { .map(|(date, _)| date) .unwrap_or(NaiveDate::default()), ms_es_date: ms_es.map(|(date, _)| date).unwrap_or(NaiveDate::default()), + macd_cos_date: macd_cos + .map(|(date, _)| date) + .unwrap_or(NaiveDate::default()), } } } diff --git a/src/shared/jquants_api/setup.rs b/src/shared/jquants_api/setup.rs index d468555..3da5578 100644 --- a/src/shared/jquants_api/setup.rs +++ b/src/shared/jquants_api/setup.rs @@ -4,7 +4,7 @@ use bytestring::ByteString; pub struct Setup {} impl Setup { - pub async fn run() -> Result { + pub fn run() -> Result { let api_key = std::env::var("JQUANTS_API_KEY") .with_context(|| "JQUANTS_API_KEY MUST be set up for JQUANTS".to_string())?; Ok(ByteString::from(api_key)) diff --git a/src/use_case/interactors/trend_analysis/interactor.rs b/src/use_case/interactors/trend_analysis/interactor.rs index 703efd1..7b0ebc8 100644 --- a/src/use_case/interactors/trend_analysis/interactor.rs +++ b/src/use_case/interactors/trend_analysis/interactor.rs @@ -1,9 +1,11 @@ use crate::domain::models::body_engulfing::model::BodyEngulfings; use crate::domain::models::candle_stick::model::CandleSticks; +use crate::domain::models::crossover_strategy::macd_cos::model::MacdCoses; use crate::domain::models::crossover_strategy::sma_cos::analysis_result; use crate::domain::models::crossover_strategy::sma_cos::model::SmaCoses; use crate::domain::models::crossover_strategy::sma_cps::model::SmaCps; use crate::domain::models::high_low_direction_signal::model::HighLowDirectionSignals; +use crate::domain::models::macd::model::MACDs; use crate::domain::models::ms_es::model::MsEses; use crate::domain::models::sma::model::{SMAListPair, SMAListTrio, SMAs}; use crate::domain::models::stocks_sma_coses_pair::model::StocksSmaCosesPair; @@ -46,6 +48,9 @@ where const MARUBOZU_BODY_MIN_RATIO: usize, const MARUBOZU_WICK_MAX_RATIO: usize, const DOJI_MAX_BODY_RATIO: usize, + const FAST_PERIOD: usize, + const SLOW_PERIOD: usize, + const SIGNAL_PERIOD: usize, >( &self, input: input::TrendAnalysis, @@ -105,6 +110,9 @@ where let sma_cos_analysis_result_volumes = analysis_result::volume::model::AnalysisResults::from(&stocks_sma_coses_pair); + let macds = MACDs::::from(stocks.as_slice()); + let macd_coses = MacdCoses::from(macds); + let candle_sticks = CandleSticks::< MARUBOZU_BODY_MIN_RATIO, MARUBOZU_WICK_MAX_RATIO, @@ -120,9 +128,11 @@ where ms_eses: &ms_eses, sma_cps: &sma_cps, sma_coses: &sma_coses, + macd_coses: &macd_coses, }; let trend_reversal_analysis = TrendReversalAnalysis::from(trend_reversal_analysis_set); + // TODO: MacdCosesを追加 let output = output::TrendAnalysis { company, stocks, diff --git a/src/use_case/interfaces/trend_analysis/use_case.rs b/src/use_case/interfaces/trend_analysis/use_case.rs index bd96561..ced6847 100644 --- a/src/use_case/interfaces/trend_analysis/use_case.rs +++ b/src/use_case/interfaces/trend_analysis/use_case.rs @@ -12,6 +12,9 @@ pub trait TrendAnalysis { const MARUBOZU_BODY_MIN_RATIO: usize, const MARUBOZU_WICK_MAX_RATIO: usize, const DOJI_MAX_BODY_RATIO: usize, + const FAST_PERIOD: usize, + const SLOW_PERIOD: usize, + const SIGNAL_PERIOD: usize, >( &self, input: input::TrendAnalysis, From 0060e8c691c7dd1f43caf6f21edd1d96e991e449 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 14 Jun 2026 15:46:28 +0900 Subject: [PATCH 14/15] chore: add developer tools configuration for text format converter --- .idea/developer-tools.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .idea/developer-tools.xml diff --git a/.idea/developer-tools.xml b/.idea/developer-tools.xml new file mode 100644 index 0000000..897cddc --- /dev/null +++ b/.idea/developer-tools.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file From c26ac0bd9353c36fe81a5fd70d1e606757b77457 Mon Sep 17 00:00:00 2001 From: t4ai6i Date: Sun, 14 Jun 2026 15:47:31 +0900 Subject: [PATCH 15/15] chore: update quantitative-data-analysis-rs version to 0.35.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 167a925..f14702c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1161,7 +1161,7 @@ dependencies = [ [[package]] name = "quantitative-data-analysis-rs" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 430bb15..60b3813 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quantitative-data-analysis-rs" -version = "0.34.0" +version = "0.35.0" edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html