-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added technicals and optimizations (#29)
* added technicals and optimizations * formatting * bbands normalize * updated git ignore
- Loading branch information
Showing
17 changed files
with
87 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
_trial_temp/ | ||
.idea | ||
.DS_Store | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -515,7 +515,8 @@ | |
} | ||
}, | ||
"processor": { | ||
"returnsCount": 5 | ||
"returnsCount": 5, | ||
"fieldPrefix": "ctc" | ||
}, | ||
"terminator": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
import random | ||
from datetime import datetime | ||
from datetime import datetime, timedelta | ||
from unittest import TestCase | ||
|
||
from algotrader.entities.candle import Candle | ||
from algotrader.entities.timespan import TimeSpan | ||
from fakes.pipeline_validators import ValidationProcessor | ||
from fakes.source import FakeSource | ||
from algotrader.pipeline.pipeline import Pipeline | ||
from algotrader.pipeline.processors.candle_cache import CandleCache | ||
from algotrader.pipeline.processors.returns import ReturnsCalculatorProcessor, RETURNS_ATTACHMENT_KEY, Returns | ||
from algotrader.pipeline.processors.returns import ReturnsCalculatorProcessor, RETURNS_ATTACHMENT_KEY | ||
from algotrader.pipeline.reverse_source import ReverseSource | ||
from algotrader.pipeline.runner import PipelineRunner | ||
from algotrader.pipeline.shared_context import SharedContext | ||
from unit import generate_candle_with_price | ||
from fakes.pipeline_validators import TerminatorValidator | ||
from fakes.source import FakeSource | ||
from unit import generate_candle_with_price, TEST_SYMBOL | ||
|
||
|
||
class TestReturnsCalculatorProcessor(TestCase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
self.source = FakeSource( | ||
[generate_candle_with_price(TimeSpan.Day, datetime.now(), random.randint(1, c)) for c in range(1, 50)]) | ||
[generate_candle_with_price(TimeSpan.Day, datetime.now() + timedelta(minutes=c), c) for c in range(1, 50)]) | ||
|
||
def test(self): | ||
def _check(context: SharedContext, candle: Candle): | ||
def _check_returns(context: SharedContext): | ||
self.assertIsNotNone(context) | ||
context.put_kv_data('check_count', context.get_kv_data('check_count', 0) + 1) | ||
check_count = context.get_kv_data('check_count', 0) | ||
cache_reader = CandleCache.context_reader(context) | ||
candles = cache_reader.get_symbol_candles(TEST_SYMBOL) | ||
|
||
self.assertFalse(candles[0].attachments.get_attachment(RETURNS_ATTACHMENT_KEY).has('ctc-1')) | ||
self.assertFalse(candles[1].attachments.get_attachment(RETURNS_ATTACHMENT_KEY).has('ctc-1')) | ||
self.assertFalse(candles[2].attachments.get_attachment(RETURNS_ATTACHMENT_KEY).has('ctc-1')) | ||
|
||
ctc1 = candles[3].attachments.get_attachment(RETURNS_ATTACHMENT_KEY)['ctc-1'] | ||
ctc2 = candles[3].attachments.get_attachment(RETURNS_ATTACHMENT_KEY)['ctc-2'] | ||
ctc3 = candles[3].attachments.get_attachment(RETURNS_ATTACHMENT_KEY)['ctc-3'] | ||
self.assertTrue(ctc1 < ctc2 < ctc3) | ||
|
||
cache_processor = CandleCache() | ||
processor = ReturnsCalculatorProcessor('ctc', 3, cache_processor) | ||
|
||
if check_count > 6: | ||
candle_returns: Returns = candle.attachments.get_attachment(RETURNS_ATTACHMENT_KEY) | ||
self.assertTrue(candle_returns.has('ctc1')) | ||
terminator = TerminatorValidator(_check_returns) | ||
|
||
validator = ValidationProcessor(_check) | ||
cache_processor = CandleCache(validator) | ||
processor = ReturnsCalculatorProcessor(5, cache_processor) | ||
PipelineRunner(Pipeline(self.source, processor)).run() | ||
self.source = ReverseSource(self.source) | ||
PipelineRunner(Pipeline(self.source, processor, terminator)).run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters